Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import time
|
4 |
-
import streamlit_analytics
|
5 |
from dotenv import load_dotenv
|
6 |
import pickle
|
7 |
from huggingface_hub import Repository
|
@@ -93,7 +92,6 @@ def display_chat_history(chat_history):
|
|
93 |
|
94 |
|
95 |
|
96 |
-
|
97 |
def page1():
|
98 |
try:
|
99 |
hide_streamlit_style = """
|
@@ -104,102 +102,73 @@ def page1():
|
|
104 |
"""
|
105 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
106 |
|
107 |
-
|
108 |
-
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
109 |
|
110 |
with col1:
|
111 |
st.title("Welcome to BinDocs ChatBot!")
|
112 |
|
113 |
with col2:
|
114 |
-
# Load and display the image in the right column, which will be the top-right corner of the page
|
115 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
116 |
st.image(image, use_column_width='always')
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
if not os.path.exists(pdf_path):
|
122 |
-
st.error("File not found. Please check the file path.")
|
123 |
-
return
|
124 |
-
|
125 |
-
VectorStore = load_vector_store(pdf_path, "vector_store_page1", force_reload=False)
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
130 |
-
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
131 |
-
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
add_vertical_space(2) # Adjust as per the desired spacing
|
138 |
-
|
139 |
-
# Create two columns for the buttons
|
140 |
-
col1, col2 = st.columns(2)
|
141 |
-
|
142 |
-
with col1:
|
143 |
-
if st.button("Was kann ich mit dem Prognose-Analyse-Tool machen?"):
|
144 |
-
query = "Was kann ich mit dem Prognose-Analyse-Tool machen?"
|
145 |
-
if st.button("Was sagt mir die Farbe der Balken der Bevölkerungsentwicklung?"):
|
146 |
-
query = "Was sagt mir die Farbe der Balken der Bevölkerungsentwicklung?"
|
147 |
-
if st.button("Ich habe mein Meta-Password vergessen, wie kann ich es zurücksetzen?"):
|
148 |
-
query = "Ich habe mein Meta-Password vergessen, wie kann ich es zurücksetzen?"
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
if st.button("Dies ist eine reine Test Frage, welche aber eine ausreichende Länge hat."):
|
153 |
-
query = "Dies ist eine reine Test Frage, welche aber eine ausreichende Länge hat."
|
154 |
-
if st.button("Was sagt mir denn generell die wundervolle Bevölkerungsentwicklung?"):
|
155 |
-
query = "Was sagt mir denn generell die wundervolle Bevölkerungsentwicklung?"
|
156 |
-
if st.button("Ob ich hier wohl viel schreibe, dass die Fragen vom Layout her passen?"):
|
157 |
-
query = "Ob ich hier wohl viel schreibe, dass die Fragen vom Layout her passen?"
|
158 |
|
|
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
|
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 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
197 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
198 |
|
199 |
except Exception as e:
|
200 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
201 |
-
# Optionally log the exception details to a file or error tracking service
|
202 |
-
|
203 |
|
204 |
|
205 |
|
@@ -212,108 +181,74 @@ def page2():
|
|
212 |
</style>
|
213 |
"""
|
214 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
215 |
-
|
216 |
-
|
217 |
-
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
218 |
|
219 |
with col1:
|
220 |
st.title("Kodieren statt Frustrieren!")
|
221 |
|
222 |
with col2:
|
223 |
-
# Load and display the image in the right column, which will be the top-right corner of the page
|
224 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
225 |
st.image(image, use_column_width='always')
|
226 |
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
if not os.path.exists(pdf_path2):
|
232 |
-
st.error("File not found. Please check the file path.")
|
233 |
-
return
|
234 |
-
|
235 |
-
VectorStore = load_vector_store(pdf_path2, "vector_store_page2", force_reload=False)
|
236 |
-
|
237 |
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
242 |
-
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
243 |
-
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
244 |
-
|
245 |
-
new_messages_placeholder = st.empty()
|
246 |
-
|
247 |
-
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
248 |
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
col1, col2 = st.columns(2)
|
253 |
-
|
254 |
-
with col1:
|
255 |
-
if st.button("Wann kodiere ich etwas als Hauptdiagnose und wann als Nebendiagnose?"):
|
256 |
-
query = "Wann kodiere ich etwas als Hauptdiagnose und wann als Nebendiagnose?"
|
257 |
-
if st.button("Ein Patient wird mit Aszites bei bekannter Leberzirrhose stationär aufgenommen. Es wird nur der Aszites durch eine Punktion behandelt.Wie kodiere ich das?"):
|
258 |
-
query = ("Ein Patient wird mit Aszites bei bekannter Leberzirrhose stationär aufgenommen. Es wird nur der Aszites durch eine Punktion behandelt.Wie kodiere ich das?")
|
259 |
-
if st.button("Hauptdiagnose: Hirntumor wie kodiere ich das?"):
|
260 |
-
query = "Hauptdiagnose: Hirntumor wie kodiere ich das?"
|
261 |
|
262 |
-
|
263 |
-
|
264 |
-
if st.button("Welche Prozeduren werden normalerweise nicht verschlüsselt?"):
|
265 |
-
query = "Welche Prozeduren werden normalerweise nicht verschlüsselt?"
|
266 |
-
if st.button("Was muss ich bei der Kodierung der Folgezusänden von Krankheiten beachten?"):
|
267 |
-
query = "Was muss ich bei der Kodierung der Folgezusänden von Krankheiten beachten?"
|
268 |
-
if st.button("Was mache ich bei einer Verdachtsdiagnose, wenn mein Patien nach Hause entlassen wird?"):
|
269 |
-
query = "Was mache ich bei einer Verdachtsdiagnose, wenn mein Patien nach Hause entlassen wird?"
|
270 |
|
271 |
-
|
272 |
-
if query:
|
273 |
-
st.session_state['chat_history_page2'].append(("User", query, "new"))
|
274 |
-
|
275 |
-
# Start timing
|
276 |
-
start_time = time.time()
|
277 |
-
|
278 |
-
with st.spinner('Bot is thinking...'):
|
279 |
-
# Use the VectorStore loaded at the start from the session state
|
280 |
-
chain = load_chatbot()
|
281 |
-
docs = VectorStore.similarity_search(query=query, k=3)
|
282 |
-
with get_openai_callback() as cb:
|
283 |
-
response = chain.run(input_documents=docs, question=query)
|
284 |
-
|
285 |
-
|
286 |
-
# Stop timing
|
287 |
-
end_time = time.time()
|
288 |
-
|
289 |
-
# Calculate duration
|
290 |
-
duration = end_time - start_time
|
291 |
-
|
292 |
-
# You can use Streamlit's text function to display the timing
|
293 |
-
st.text(f"Response time: {duration:.2f} seconds")
|
294 |
-
|
295 |
-
st.session_state['chat_history_page2'].append(("Bot", response, "new"))
|
296 |
-
|
297 |
-
|
298 |
-
# Display new messages at the bottom
|
299 |
-
new_messages = st.session_state['chat_history_page2'][-2:]
|
300 |
-
for chat in new_messages:
|
301 |
-
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
302 |
-
new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
|
303 |
-
|
304 |
-
|
305 |
-
# Clear the input field after the query is made
|
306 |
-
query = ""
|
307 |
-
|
308 |
-
# Mark all messages as old after displaying
|
309 |
-
st.session_state['chat_history_page2'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page2']]
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
|
|
|
|
|
|
|
|
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
|
|
316 |
|
|
|
|
|
317 |
|
318 |
|
319 |
def main():
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import time
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
import pickle
|
6 |
from huggingface_hub import Repository
|
|
|
92 |
|
93 |
|
94 |
|
|
|
95 |
def page1():
|
96 |
try:
|
97 |
hide_streamlit_style = """
|
|
|
102 |
"""
|
103 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
104 |
|
105 |
+
col1, col2 = st.columns([3, 1])
|
|
|
106 |
|
107 |
with col1:
|
108 |
st.title("Welcome to BinDocs ChatBot!")
|
109 |
|
110 |
with col2:
|
|
|
111 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
112 |
st.image(image, use_column_width='always')
|
113 |
|
114 |
+
if not os.path.exists(pdf_path):
|
115 |
+
st.error("File not found. Please check the file path.")
|
116 |
+
return
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
+
VectorStore = load_vector_store(pdf_path, "vector_store_page1", force_reload=False)
|
119 |
+
display_chat_history(st.session_state['chat_history_page1'])
|
|
|
|
|
|
|
120 |
|
121 |
+
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
122 |
+
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
123 |
+
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
126 |
+
add_vertical_space(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
+
col1, col2 = st.columns(2)
|
129 |
|
130 |
+
with col1:
|
131 |
+
if st.button("Was kann ich mit dem Prognose-Analyse-Tool machen?"):
|
132 |
+
query = "Was kann ich mit dem Prognose-Analyse-Tool machen?"
|
133 |
+
if st.button("Was sagt mir die Farbe der Balken der Bevölkerungsentwicklung?"):
|
134 |
+
query = "Was sagt mir die Farbe der Balken der Bevölkerungsentwicklung?"
|
135 |
+
if st.button("Ich habe mein Meta-Password vergessen, wie kann ich es zurücksetzen?"):
|
136 |
+
query = "Ich habe mein Meta-Password vergessen, wie kann ich es zurücksetzen?"
|
137 |
+
|
138 |
+
with col2:
|
139 |
+
if st.button("Dies ist eine reine Test Frage, welche aber eine ausreichende Länge hat."):
|
140 |
+
query = "Dies ist eine reine Test Frage, welche aber eine ausreichende Länge hat."
|
141 |
+
if st.button("Was sagt mir denn generell die wundervolle Bevölkerungsentwicklung?"):
|
142 |
+
query = "Was sagt mir denn generell die wundervolle Bevölkerungsentwicklung?"
|
143 |
+
if st.button("Ob ich hier wohl viel schreibe, dass die Fragen vom Layout her passen?"):
|
144 |
+
query = "Ob ich hier wohl viel schreibe, dass die Fragen vom Layout her passen?"
|
145 |
+
|
146 |
+
if query:
|
147 |
+
st.session_state['chat_history_page1'].append(("User", query, "new"))
|
148 |
+
start_time = time.time()
|
149 |
+
with st.spinner('Bot is thinking...'):
|
150 |
+
chain = load_chatbot()
|
151 |
+
docs = VectorStore.similarity_search(query=query, k=3)
|
152 |
+
with get_openai_callback() as cb:
|
153 |
+
response = chain.run(input_documents=docs, question=query)
|
154 |
+
|
155 |
+
end_time = time.time()
|
156 |
+
duration = end_time - start_time
|
157 |
+
st.text(f"Response time: {duration:.2f} seconds")
|
158 |
+
|
159 |
+
st.session_state['chat_history_page1'].append(("Bot", response, "new"))
|
160 |
+
|
161 |
+
new_messages = st.session_state['chat_history_page1'][-2:]
|
162 |
+
for chat in new_messages:
|
163 |
+
background_color = "#ffeecf"
|
164 |
+
st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
|
165 |
+
|
166 |
+
query = ""
|
167 |
+
|
168 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
169 |
|
170 |
except Exception as e:
|
171 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
|
|
172 |
|
173 |
|
174 |
|
|
|
181 |
</style>
|
182 |
"""
|
183 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
184 |
+
|
185 |
+
col1, col2 = st.columns([3, 1])
|
|
|
186 |
|
187 |
with col1:
|
188 |
st.title("Kodieren statt Frustrieren!")
|
189 |
|
190 |
with col2:
|
|
|
191 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
192 |
st.image(image, use_column_width='always')
|
193 |
|
194 |
+
if not os.path.exists(pdf_path2):
|
195 |
+
st.error("File not found. Please check the file path.")
|
196 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
+
VectorStore = load_vector_store(pdf_path2, "vector_store_page2", force_reload=False)
|
199 |
+
display_chat_history(st.session_state['chat_history_page2'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
+
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
202 |
+
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
203 |
+
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
206 |
+
add_vertical_space(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
+
with col1:
|
211 |
+
if st.button("Wann kodiere ich etwas als Hauptdiagnose und wann als Nebendiagnose?"):
|
212 |
+
query = "Wann kodiere ich etwas als Hauptdiagnose und wann als Nebendiagnose?"
|
213 |
+
if st.button("Ein Patient wird mit Aszites bei bekannter Leberzirrhose stationär aufgenommen. Es wird nur der Aszites durch eine Punktion behandelt. Wie kodiere ich das?"):
|
214 |
+
query = "Ein Patient wird mit Aszites bei bekannter Leberzirrhose stationär aufgenommen. Es wird nur der Aszites durch eine Punktion behandelt. Wie kodiere ich das?"
|
215 |
+
if st.button("Hauptdiagnose: Hirntumor wie kodiere ich das?"):
|
216 |
+
query = "Hauptdiagnose: Hirntumor wie kodiere ich das?"
|
217 |
|
218 |
+
with col2:
|
219 |
+
if st.button("Welche Prozeduren werden normalerweise nicht verschlüsselt?"):
|
220 |
+
query = "Welche Prozeduren werden normalerweise nicht verschlüsselt?"
|
221 |
+
if st.button("Was muss ich bei der Kodierung der Folgezustände von Krankheiten beachten?"):
|
222 |
+
query = "Was muss ich bei der Kodierung der Folgezustände von Krankheiten beachten?"
|
223 |
+
if st.button("Was mache ich bei einer Verdachtsdiagnose, wenn mein Patient nach Hause entlassen wird?"):
|
224 |
+
query = "Was mache ich bei einer Verdachtsdiagnose, wenn mein Patient nach Hause entlassen wird?"
|
225 |
+
|
226 |
+
if query:
|
227 |
+
st.session_state['chat_history_page2'].append(("User", query, "new"))
|
228 |
+
start_time = time.time()
|
229 |
+
with st.spinner('Bot is thinking...'):
|
230 |
+
chain = load_chatbot()
|
231 |
+
docs = VectorStore.similarity_search(query=query, k=3)
|
232 |
+
with get_openai_callback() as cb:
|
233 |
+
response = chain.run(input_documents=docs, question=query)
|
234 |
+
|
235 |
+
end_time = time.time()
|
236 |
+
duration = end_time - start_time
|
237 |
+
st.text(f"Response time: {duration:.2f} seconds")
|
238 |
+
|
239 |
+
st.session_state['chat_history_page2'].append(("Bot", response, "new"))
|
240 |
+
|
241 |
+
new_messages = st.session_state['chat_history_page2'][-2:]
|
242 |
+
for chat in new_messages:
|
243 |
+
background_color = "#ffeecf"
|
244 |
+
st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
|
245 |
+
|
246 |
+
query = ""
|
247 |
|
248 |
+
st.session_state['chat_history_page2'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page2']]
|
249 |
|
250 |
+
except Exception as e:
|
251 |
+
st.error(f"Upsi, an unexpected error occurred: {e}")
|
252 |
|
253 |
|
254 |
def main():
|