Spaces:
Runtime error
Runtime error
Experimenting with user interface
Browse files- Dockerfile +10 -16
- app.py +85 -29
- control.py +53 -0
- defaults.py +1 -1
- entrypoint.sh +0 -28
- queries.py +2 -0
Dockerfile
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# Trying to put qdrant into same container as chainlit application
|
2 |
-
|
3 |
# Start with qdrant image
|
4 |
FROM qdrant/qdrant:latest
|
5 |
|
@@ -8,31 +6,27 @@ RUN apt-get update && apt-get install -y \
|
|
8 |
--no-install-recommends curl ca-certificates\
|
9 |
&& rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
# Install uv
|
14 |
ADD https://astral.sh/uv/install.sh /uv-installer.sh
|
15 |
RUN sh /uv-installer.sh && rm /uv-installer.sh
|
16 |
|
17 |
|
18 |
-
# Set
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
ENV PATH="/root/.local/bin:$PATH"
|
24 |
|
25 |
# # NEEDED FOR CHAINLIT IN HUGGING FACE SPACES
|
26 |
ENV UVICORN_WS_PROTOCOL=websockets
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
|
32 |
# # Copy the app to the container
|
33 |
-
|
34 |
-
|
35 |
RUN chmod 777 entrypoint.sh
|
|
|
36 |
# # Install the dependencies
|
37 |
RUN uv sync --frozen
|
38 |
|
|
|
|
|
|
|
1 |
# Start with qdrant image
|
2 |
FROM qdrant/qdrant:latest
|
3 |
|
|
|
6 |
--no-install-recommends curl ca-certificates\
|
7 |
&& rm -rf /var/lib/apt/lists/*
|
8 |
|
9 |
+
# Install uv - it installs in /root/.local/bin
|
|
|
|
|
10 |
ADD https://astral.sh/uv/install.sh /uv-installer.sh
|
11 |
RUN sh /uv-installer.sh && rm /uv-installer.sh
|
12 |
|
13 |
|
14 |
+
# Set the home directory and path, need access to uv
|
15 |
+
ENV HOME=/home/user \
|
16 |
+
PATH="/home/user/.local/bin:/root/.local/bin/:$PATH"
|
|
|
|
|
|
|
17 |
|
18 |
# # NEEDED FOR CHAINLIT IN HUGGING FACE SPACES
|
19 |
ENV UVICORN_WS_PROTOCOL=websockets
|
20 |
|
21 |
+
# Set the working directory
|
22 |
+
WORKDIR $HOME/app
|
23 |
+
|
24 |
|
25 |
# # Copy the app to the container
|
26 |
+
COPY --chown=user . $HOME/app
|
27 |
+
|
28 |
RUN chmod 777 entrypoint.sh
|
29 |
+
|
30 |
# # Install the dependencies
|
31 |
RUN uv sync --frozen
|
32 |
|
app.py
CHANGED
@@ -89,7 +89,7 @@ async def on_chat_start():
|
|
89 |
)
|
90 |
await msg.send()
|
91 |
|
92 |
-
chunk_size =
|
93 |
chunk_overlap = 200
|
94 |
|
95 |
text_splitter = RecursiveCharacterTextSplitter(
|
@@ -161,32 +161,88 @@ async def on_chat_start():
|
|
161 |
|
162 |
await msg.send()
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
-
await msg.send()
|
|
|
89 |
)
|
90 |
await msg.send()
|
91 |
|
92 |
+
chunk_size = 3000
|
93 |
chunk_overlap = 200
|
94 |
|
95 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
161 |
|
162 |
await msg.send()
|
163 |
|
164 |
+
# Sending an action button within a chatbot message
|
165 |
+
actions = [
|
166 |
+
cl.Action(
|
167 |
+
name="summary_button",
|
168 |
+
icon="mouse-pointer-click",
|
169 |
+
payload={"value": "summary"},
|
170 |
+
label="Write summary"
|
171 |
+
),
|
172 |
+
cl.Action(
|
173 |
+
name="risk_button",
|
174 |
+
icon="mouse-pointer-click",
|
175 |
+
payload={"value": "risks"},
|
176 |
+
label="Write risk section"
|
177 |
+
),
|
178 |
+
cl.Action(
|
179 |
+
name="benefits_button",
|
180 |
+
icon="mouse-pointer-click",
|
181 |
+
payload={"value": "benefits"},
|
182 |
+
label="Write benefits section"
|
183 |
+
),
|
184 |
+
cl.Action(
|
185 |
+
name="file_button",
|
186 |
+
icon="mouse-pointer-click",
|
187 |
+
payload={"value": "markdown"},
|
188 |
+
label="Create final file"
|
189 |
+
)
|
190 |
+
]
|
191 |
+
await cl.Message(content="Select consent form sections:", actions=actions).send()
|
192 |
+
|
193 |
+
@cl.action_callback("summary_button")
|
194 |
+
async def on_action(action: cl.Action):
|
195 |
+
summary = rag_chain.invoke({"question":summary_query()})
|
196 |
+
await cl.Message(content=summary).send()
|
197 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
198 |
+
# await action.remove()
|
199 |
+
|
200 |
+
@cl.action_callback("risk_button")
|
201 |
+
async def on_action(action: cl.Action):
|
202 |
+
risks = rag_chain.invoke({"question":risks_query()})
|
203 |
+
await cl.Message(content=risks).send()
|
204 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
205 |
+
# await action.remove()
|
206 |
+
|
207 |
+
@cl.action_callback("benefits_button")
|
208 |
+
async def on_action(action: cl.Action):
|
209 |
+
benefits = rag_chain.invoke({"question":benefits_query()})
|
210 |
+
await cl.Message(content=benefits).send()
|
211 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
212 |
+
# await action.remove()
|
213 |
+
|
214 |
+
# @cl.action_callback("file_button")
|
215 |
+
# async def on_action(action: cl.Action):
|
216 |
+
# await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
217 |
+
# await action.remove()
|
218 |
+
|
219 |
+
|
220 |
+
# # Now let's test the application to make a consent document
|
221 |
+
# start_time = time.time()
|
222 |
+
# # Brute force method that just saves each generated section as string
|
223 |
+
# summary = rag_chain.invoke({"question":summary_query()})
|
224 |
+
# background = rag_chain.invoke({"question":background_query()})
|
225 |
+
# number_of_participants = rag_chain.invoke({"question":number_of_participants_query()})
|
226 |
+
# study_procedures = rag_chain.invoke({"question":study_procedures_query()})
|
227 |
+
# alt_procedures = rag_chain.invoke({"question":alt_procedures_query()})
|
228 |
+
# risks = rag_chain.invoke({"question":risks_query()})
|
229 |
+
# benefits = rag_chain.invoke({"question":benefits_query()})
|
230 |
+
|
231 |
+
# end_time = time.time()
|
232 |
+
# execution_time = end_time - start_time
|
233 |
+
|
234 |
+
# msg = cl.Message(
|
235 |
+
# content=f"""
|
236 |
+
# Brute force (sequential) execution time: {execution_time:.2f} seconds.
|
237 |
+
# {summary}
|
238 |
+
# {background}
|
239 |
+
# {number_of_participants}
|
240 |
+
# {study_procedures}
|
241 |
+
# {alt_procedures}
|
242 |
+
# {risks}
|
243 |
+
# {benefits}
|
244 |
+
# """
|
245 |
+
|
246 |
+
# )
|
247 |
|
248 |
+
# await msg.send()
|
control.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chainlit as cl
|
2 |
+
|
3 |
+
@cl.on_chat_start
|
4 |
+
async def start():
|
5 |
+
# Sending an action button within a chatbot message
|
6 |
+
actions = [
|
7 |
+
cl.Action(
|
8 |
+
name="summary_button",
|
9 |
+
icon="mouse-pointer-click",
|
10 |
+
payload={"value": "summary"},
|
11 |
+
label="Write summary"
|
12 |
+
),
|
13 |
+
cl.Action(
|
14 |
+
name="risk_button",
|
15 |
+
icon="mouse-pointer-click",
|
16 |
+
payload={"value": "risks"},
|
17 |
+
label="Write risk section"
|
18 |
+
),
|
19 |
+
cl.Action(
|
20 |
+
name="benefits_button",
|
21 |
+
icon="mouse-pointer-click",
|
22 |
+
payload={"value": "benefits"},
|
23 |
+
label="Write benefits section"
|
24 |
+
),
|
25 |
+
cl.Action(
|
26 |
+
name="file_button",
|
27 |
+
icon="mouse-pointer-click",
|
28 |
+
payload={"value": "markdown"},
|
29 |
+
label="Create final file"
|
30 |
+
)
|
31 |
+
]
|
32 |
+
|
33 |
+
await cl.Message(content="Select consent form sections:", actions=actions).send()
|
34 |
+
|
35 |
+
@cl.action_callback("summary_button")
|
36 |
+
async def on_action(action: cl.Action):
|
37 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
38 |
+
await action.remove()
|
39 |
+
|
40 |
+
@cl.action_callback("risk_button")
|
41 |
+
async def on_action(action: cl.Action):
|
42 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
43 |
+
await action.remove()
|
44 |
+
|
45 |
+
@cl.action_callback("benefits_button")
|
46 |
+
async def on_action(action: cl.Action):
|
47 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
48 |
+
await action.remove()
|
49 |
+
|
50 |
+
@cl.action_callback("file_button")
|
51 |
+
async def on_action(action: cl.Action):
|
52 |
+
await cl.Message(content=f"Executed {action.payload["value"]}").send()
|
53 |
+
await action.remove()
|
defaults.py
CHANGED
@@ -6,4 +6,4 @@ OPENAI_API_KEY = os.getenv("NEWKEY")
|
|
6 |
default_embedding_model = OpenAIEmbeddings(model="text-embedding-3-small", api_key=OPENAI_API_KEY)
|
7 |
default_location = ":memory:"
|
8 |
default_url = "http://localhost:6333"
|
9 |
-
default_llm = ChatOpenAI(model="gpt-4o", api_key=OPENAI_API_KEY, streaming=True, temperature=0)
|
|
|
6 |
default_embedding_model = OpenAIEmbeddings(model="text-embedding-3-small", api_key=OPENAI_API_KEY)
|
7 |
default_location = ":memory:"
|
8 |
default_url = "http://localhost:6333"
|
9 |
+
default_llm = ChatOpenAI(model="gpt-4o", api_key=OPENAI_API_KEY, streaming=True, temperature=0.2)
|
entrypoint.sh
CHANGED
@@ -1,33 +1,5 @@
|
|
1 |
#!/bin/bash
|
2 |
-
echo "Current directory: $(pwd)"
|
3 |
-
echo "Current path: $PATH"
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
# Specify the starting directory (e.g., root or home)
|
8 |
-
start_directory="/"
|
9 |
-
|
10 |
-
# Use find to locate 'uv'
|
11 |
-
found=$(find "$start_directory" -name "uv" 2>/dev/null)
|
12 |
-
|
13 |
-
if [ -n "$found" ]; then
|
14 |
-
echo "'uv' found at:"
|
15 |
-
echo "$found"
|
16 |
-
else
|
17 |
-
echo "'uv' not found in $start_directory or its subdirectories"
|
18 |
-
fi
|
19 |
-
|
20 |
-
|
21 |
-
directory="/"
|
22 |
-
# directory="../root/.local/bin"
|
23 |
-
if [ -d "$directory" ];
|
24 |
-
then
|
25 |
-
echo "Directory exists: $directory"
|
26 |
-
echo "Files in $directory:"
|
27 |
-
find "$directory" -type f
|
28 |
-
else
|
29 |
-
echo "Directory does not exist: $directory"
|
30 |
-
fi
|
31 |
# Start Qdrant in the background
|
32 |
echo "Starting Qdrant server..."
|
33 |
/qdrant/qdrant &
|
|
|
1 |
#!/bin/bash
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
# Start Qdrant in the background
|
4 |
echo "Starting Qdrant server..."
|
5 |
/qdrant/qdrant &
|
queries.py
CHANGED
@@ -126,6 +126,8 @@ def risks_query():
|
|
126 |
|
127 |
All the details of study risks should be specific to this protocol.
|
128 |
|
|
|
|
|
129 |
"""
|
130 |
return risks_query
|
131 |
|
|
|
126 |
|
127 |
All the details of study risks should be specific to this protocol.
|
128 |
|
129 |
+
You must complete this task as it is a required part of the document.
|
130 |
+
|
131 |
"""
|
132 |
return risks_query
|
133 |
|