Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -254,99 +254,97 @@ def page1():
|
|
| 254 |
st.image(image, use_column_width='always')
|
| 255 |
|
| 256 |
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
-
display_chat_history(st.session_state['chat_history_page1'])
|
| 266 |
-
|
| 267 |
-
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
| 268 |
-
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
| 269 |
-
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
| 270 |
-
|
| 271 |
-
new_messages_placeholder = st.empty()
|
| 272 |
|
| 273 |
-
|
|
|
|
|
|
|
| 274 |
|
| 275 |
-
|
|
|
|
| 276 |
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
query = ("Wie viele Leistungsgruppen gibt es?")
|
| 285 |
-
if st.button("Was sind die hauptsächlichen Änderungsvorhaben der Krankenhausreform?"):
|
| 286 |
-
query = "Was sind die hauptsächlichen Änderungsvorhaben der Krankenhausreform?"
|
| 287 |
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
query = "Welche und wieviele Fachärzte benötige ich für die Leistungsgruppe Pädiatrie"
|
| 292 |
-
if st.button("Was soll die Reform der Notfallversorgung beinhalten?"):
|
| 293 |
-
query = "Was soll die Reform der Notfallversorgung beinhalten?"
|
| 294 |
-
if st.button("Was bedeutet die Vorhaltefinanzierung?"):
|
| 295 |
-
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 296 |
|
|
|
|
|
|
|
| 297 |
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
st.session_state['chat_history_page1'].append(("User", query, "new"))
|
| 302 |
|
| 303 |
-
|
| 304 |
-
start_time = time.time()
|
| 305 |
-
|
| 306 |
-
with st.spinner('Bot is thinking...'):
|
| 307 |
-
chain = load_chatbot()
|
| 308 |
-
docs = VectorStore.similarity_search(query=query, k=5)
|
| 309 |
-
with get_openai_callback() as cb:
|
| 310 |
-
response = chain.run(input_documents=docs, question=full_query)
|
| 311 |
-
response = handle_no_answer(response) # Process the response through the new function
|
| 312 |
|
| 313 |
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
duration = end_time - start_time
|
| 320 |
|
| 321 |
-
|
| 322 |
-
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
# Display new messages at the bottom
|
| 332 |
-
new_messages = st.session_state['chat_history_page1'][-2:]
|
| 333 |
-
for chat in new_messages:
|
| 334 |
-
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
| 335 |
-
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)
|
| 336 |
-
|
| 337 |
-
# Save conversation after chat interaction
|
| 338 |
-
save_conversation(st.session_state['chat_history_page1'], st.session_state['session_id'], 1)
|
| 339 |
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
current_dir = os.getcwd()
|
| 343 |
-
st.text(f"Current working directory after save_conversation: {current_dir}")
|
| 344 |
-
|
| 345 |
-
# Clear the input field after the query is made
|
| 346 |
-
query = ""
|
| 347 |
-
|
| 348 |
-
# Mark all messages as old after displaying
|
| 349 |
-
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
| 350 |
|
| 351 |
except Exception as e:
|
| 352 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
|
| 254 |
st.image(image, use_column_width='always')
|
| 255 |
|
| 256 |
|
| 257 |
+
if not os.path.exists(pdf_path):
|
| 258 |
+
st.error("File not found. Please check the file path.")
|
| 259 |
+
return
|
| 260 |
+
|
| 261 |
+
VectorStore = load_vector_store(pdf_path, "KH_Reform_2301", force_reload=False)
|
| 262 |
+
|
| 263 |
+
display_chat_history(st.session_state['chat_history_page1'])
|
| 264 |
+
|
| 265 |
+
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
| 266 |
+
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
| 267 |
+
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
| 268 |
+
|
| 269 |
+
new_messages_placeholder = st.empty()
|
| 270 |
+
|
| 271 |
+
query = st.text_input("Geben Sie hier Ihre Frage ein / Enter your question here:")
|
| 272 |
+
|
| 273 |
+
add_vertical_space(2) # Adjust as per the desired spacing
|
| 274 |
+
|
| 275 |
+
# Create two columns for the buttons
|
| 276 |
+
col1, col2 = st.columns(2)
|
| 277 |
+
|
| 278 |
+
with col1:
|
| 279 |
+
if st.button("Wie viele Ärzte benötigt eine Klinik in der Leistungsgruppe Stammzell-transplantation?"):
|
| 280 |
+
query = "Wie viele Ärzte benötigt eine Klinik in der Leistungsgruppe Stammzell-transplantation?"
|
| 281 |
+
if st.button("Wie viele Leistungsgruppen gibt es?"):
|
| 282 |
+
query = ("Wie viele Leistungsgruppen gibt es?")
|
| 283 |
+
if st.button("Was sind die hauptsächlichen Änderungsvorhaben der Krankenhausreform?"):
|
| 284 |
+
query = "Was sind die hauptsächlichen Änderungsvorhaben der Krankenhausreform?"
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
with col2:
|
| 288 |
+
if st.button("Welche und wieviele Fachärzte benötige ich für die Leistungsgruppe Pädiatrie? "):
|
| 289 |
+
query = "Welche und wieviele Fachärzte benötige ich für die Leistungsgruppe Pädiatrie"
|
| 290 |
+
if st.button("Was soll die Reform der Notfallversorgung beinhalten?"):
|
| 291 |
+
query = "Was soll die Reform der Notfallversorgung beinhalten?"
|
| 292 |
+
if st.button("Was bedeutet die Vorhaltefinanzierung?"):
|
| 293 |
+
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 294 |
+
|
| 295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
+
if query:
|
| 298 |
+
full_query = ask_bot(query)
|
| 299 |
+
st.session_state['chat_history_page1'].append(("User", query, "new"))
|
| 300 |
|
| 301 |
+
# Start timing
|
| 302 |
+
start_time = time.time()
|
| 303 |
|
| 304 |
+
with st.spinner('Bot is thinking...'):
|
| 305 |
+
chain = load_chatbot()
|
| 306 |
+
docs = VectorStore.similarity_search(query=query, k=5)
|
| 307 |
+
with get_openai_callback() as cb:
|
| 308 |
+
response = chain.run(input_documents=docs, question=full_query)
|
| 309 |
+
response = handle_no_answer(response) # Process the response through the new function
|
| 310 |
+
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
+
|
| 313 |
+
# Stop timing
|
| 314 |
+
end_time = time.time()
|
| 315 |
|
| 316 |
+
# Calculate duration
|
| 317 |
+
duration = end_time - start_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
+
# You can use Streamlit's text function to display the timing
|
| 320 |
+
st.text(f"Response time: {duration:.2f} seconds")
|
| 321 |
|
| 322 |
+
# Display the current working directory after save_conversation
|
| 323 |
+
current_dir = os.getcwd()
|
| 324 |
+
st.text(f"Current working directory before save_conversation: {current_dir}")
|
|
|
|
| 325 |
|
| 326 |
+
st.session_state['chat_history_page1'].append(("Bot", response, "new"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
|
| 329 |
+
# Display new messages at the bottom
|
| 330 |
+
new_messages = st.session_state['chat_history_page1'][-2:]
|
| 331 |
+
for chat in new_messages:
|
| 332 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
| 333 |
+
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)
|
|
|
|
| 334 |
|
| 335 |
+
# Save conversation after chat interaction
|
| 336 |
+
save_conversation(st.session_state['chat_history_page1'], st.session_state['session_id'], 1)
|
| 337 |
|
| 338 |
+
|
| 339 |
+
# Display the current working directory after save_conversation
|
| 340 |
+
current_dir = os.getcwd()
|
| 341 |
+
st.text(f"Current working directory after save_conversation: {current_dir}")
|
| 342 |
+
|
| 343 |
+
# Clear the input field after the query is made
|
| 344 |
+
query = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
+
# Mark all messages as old after displaying
|
| 347 |
+
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
|
| 349 |
except Exception as e:
|
| 350 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|