Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
|
|
2 |
from PIL import Image
|
3 |
import random
|
4 |
import time
|
5 |
-
import streamlit_analytics
|
6 |
from dotenv import load_dotenv
|
7 |
import pickle
|
8 |
from huggingface_hub import Repository
|
@@ -107,7 +106,6 @@ def load_vector_store(file_path, store_name, force_reload=False):
|
|
107 |
repo.git_add(f"{store_name}.pkl") # Use just the file name
|
108 |
repo.git_commit(f"Update vector store: {store_name}")
|
109 |
repo.git_push()
|
110 |
-
#st.text("Committed and pushed vector store to repository.")
|
111 |
except Exception as e:
|
112 |
st.error(f"Error during Git operations: {e}")
|
113 |
finally:
|
@@ -319,10 +317,6 @@ def page1():
|
|
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 |
|
@@ -337,8 +331,8 @@ def page1():
|
|
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 = ""
|
@@ -373,90 +367,88 @@ def page2():
|
|
373 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
374 |
st.image(image, use_column_width='always')
|
375 |
|
376 |
-
|
377 |
-
# Start tracking user interactions
|
378 |
-
with streamlit_analytics.track():
|
379 |
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
|
387 |
|
388 |
-
display_chat_history(st.session_state['chat_history_page2'])
|
389 |
-
|
390 |
-
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
391 |
-
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
392 |
-
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
393 |
-
|
394 |
-
new_messages_placeholder = st.empty()
|
395 |
-
|
396 |
-
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
397 |
|
398 |
-
|
|
|
|
|
|
|
|
|
|
|
399 |
|
400 |
-
|
401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
|
403 |
-
|
404 |
-
|
405 |
-
query = "Nenne mir 5 wichtige Personalkennzahlen im Krankenhaus."
|
406 |
-
if st.button("Wie ist die durchschnittliche Bettenauslastung eines Krankenhauses?"):
|
407 |
-
query = ("Wie ist die durchschnittliche Bettenauslastung eines Krankenhauses?")
|
408 |
-
if st.button("Welches sind die häufigsten DRGs, die von den Krankenhäusern abgerechnet werden?"):
|
409 |
-
query = "Welches sind die häufigsten DRGs, die von den Krankenhäusern abgerechnet werden? "
|
410 |
|
411 |
-
|
412 |
-
|
413 |
-
if st.button("Wie viel Casemixpunkte werden im Median von einer ärztlichen Vollkraft erbracht?"):
|
414 |
-
query = "Wie viel Casemixpunkte werden im Median von einer ärztlichen Vollkraft erbracht?"
|
415 |
-
if st.button("Bitte erstelle mir einer Übersicht der wichtiger Strukturkennzahlen eines Krankenhauses der Grund- und Regelversorgung."):
|
416 |
-
query = "Bitte erstelle mir einer Übersicht der wichtiger Strukturkennzahlen eines Krankenhauses der Grund- und Regelversorgung."
|
417 |
-
if st.button("Wie viele Patienten eines Grund- und Regelversorgers kommen aus welcher Fahrzeitzone?"):
|
418 |
-
query = "Wie viele Patienten eines Grund- und Regelversorgers kommen aus welcher Fahrzeitzone?"
|
419 |
|
420 |
-
|
421 |
|
422 |
-
|
423 |
-
full_query = ask_bot(query)
|
424 |
-
st.session_state['chat_history_page2'].append(("User", query, "new"))
|
425 |
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
docs = VectorStore.similarity_search(query=query, k=5)
|
432 |
-
with get_openai_callback() as cb:
|
433 |
-
response = chain.run(input_documents=docs, question=full_query)
|
434 |
-
response = handle_no_answer(response) # Process the response through the new function
|
435 |
-
|
436 |
-
# Stop timing
|
437 |
-
end_time = time.time()
|
438 |
-
|
439 |
-
# Calculate duration
|
440 |
-
duration = end_time - start_time
|
441 |
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
# Display new messages at the bottom
|
449 |
-
new_messages = st.session_state['chat_history_page2'][-2:]
|
450 |
-
for chat in new_messages:
|
451 |
-
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
452 |
-
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)
|
453 |
-
|
454 |
-
|
455 |
-
# Clear the input field after the query is made
|
456 |
-
query = ""
|
457 |
-
|
458 |
-
# Mark all messages as old after displaying
|
459 |
-
st.session_state['chat_history_page2'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page2']]
|
460 |
|
461 |
except Exception as e:
|
462 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
@@ -485,90 +477,88 @@ def page3():
|
|
485 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
486 |
st.image(image, use_column_width='always')
|
487 |
|
488 |
-
|
489 |
-
# Start tracking user interactions
|
490 |
-
with streamlit_analytics.track():
|
491 |
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
|
499 |
|
500 |
-
display_chat_history(st.session_state['chat_history_page3'])
|
501 |
-
|
502 |
-
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
503 |
-
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
504 |
-
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
505 |
-
|
506 |
-
new_messages_placeholder = st.empty()
|
507 |
-
|
508 |
-
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
509 |
|
510 |
-
|
|
|
|
|
|
|
|
|
|
|
511 |
|
512 |
-
|
513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
|
515 |
-
|
516 |
-
|
517 |
-
query = "Wie hat sich die Bettenanzahl in den letzten 10 Jahren entwickelt?"
|
518 |
-
if st.button("Wie viele Patienten werden pro Jahr vollstationär behandelt?"):
|
519 |
-
query = ("Wie viele Patienten werden pro Jahr vollstationär behandelt?")
|
520 |
-
if st.button("Wie viele Vollkräfte arbeiten in Summe in deutschen Krankenhäusern?"):
|
521 |
-
query = "Wie viele Vollkräfte arbeiten in Summe in deutschen Krankenhäusern? "
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
if st.button("Welche unterschiedlichen Personalkosten gibt es im Krankenhaus?"):
|
526 |
-
query = "Welche unterschiedlichen Personalkosten gibt es im Krankenhaus?"
|
527 |
-
if st.button("Welche Sachkosten werden in Krankenhäusern unterschieden?"):
|
528 |
-
query = "Welche Sachkosten werden in Krankenhäusern unterschieden? "
|
529 |
-
if st.button("Wie hoch sind die Gesamtkosten der Krankenhäuser pro Jahr?"):
|
530 |
-
query = "Wie hoch sind die Gesamtkosten der Krankenhäuser pro Jahr?"
|
531 |
|
532 |
-
|
533 |
|
534 |
-
if query:
|
535 |
-
full_query = ask_bot(query)
|
536 |
-
st.session_state['chat_history_page3'].append(("User", query, "new"))
|
537 |
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
docs = VectorStore.similarity_search(query=query, k=5)
|
544 |
-
with get_openai_callback() as cb:
|
545 |
-
response = chain.run(input_documents=docs, question=full_query)
|
546 |
-
response = handle_no_answer(response) # Process the response through the new function
|
547 |
-
|
548 |
-
# Stop timing
|
549 |
-
end_time = time.time()
|
550 |
|
551 |
-
|
552 |
-
duration = end_time - start_time
|
553 |
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
# Display new messages at the bottom
|
561 |
-
new_messages = st.session_state['chat_history_page3'][-2:]
|
562 |
-
for chat in new_messages:
|
563 |
-
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
564 |
-
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)
|
565 |
-
|
566 |
-
|
567 |
-
# Clear the input field after the query is made
|
568 |
-
query = ""
|
569 |
-
|
570 |
-
# Mark all messages as old after displaying
|
571 |
-
st.session_state['chat_history_page3'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page3']]
|
572 |
|
573 |
except Exception as e:
|
574 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
2 |
from PIL import Image
|
3 |
import random
|
4 |
import time
|
|
|
5 |
from dotenv import load_dotenv
|
6 |
import pickle
|
7 |
from huggingface_hub import Repository
|
|
|
106 |
repo.git_add(f"{store_name}.pkl") # Use just the file name
|
107 |
repo.git_commit(f"Update vector store: {store_name}")
|
108 |
repo.git_push()
|
|
|
109 |
except Exception as e:
|
110 |
st.error(f"Error during Git operations: {e}")
|
111 |
finally:
|
|
|
317 |
# You can use Streamlit's text function to display the timing
|
318 |
st.text(f"Response time: {duration:.2f} seconds")
|
319 |
|
|
|
|
|
|
|
|
|
320 |
st.session_state['chat_history_page1'].append(("Bot", response, "new"))
|
321 |
|
322 |
|
|
|
331 |
|
332 |
|
333 |
# Display the current working directory after save_conversation
|
334 |
+
#current_dir = os.getcwd()
|
335 |
+
#st.text(f"Current working directory after save_conversation: {current_dir}")
|
336 |
|
337 |
# Clear the input field after the query is made
|
338 |
query = ""
|
|
|
367 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
368 |
st.image(image, use_column_width='always')
|
369 |
|
|
|
|
|
|
|
370 |
|
371 |
+
if not os.path.exists(pdf_path2):
|
372 |
+
st.error("File not found. Please check the file path.")
|
373 |
+
return
|
374 |
+
|
375 |
+
VectorStore = load_vector_store(pdf_path2, "Buch_2301", force_reload=False)
|
376 |
+
|
377 |
+
|
378 |
+
|
379 |
+
display_chat_history(st.session_state['chat_history_page2'])
|
380 |
+
|
381 |
+
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
382 |
+
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
383 |
+
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
384 |
+
|
385 |
+
new_messages_placeholder = st.empty()
|
386 |
+
|
387 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
388 |
+
|
389 |
+
add_vertical_space(2) # Adjust as per the desired spacing
|
390 |
+
|
391 |
+
# Create two columns for the buttons
|
392 |
+
col1, col2 = st.columns(2)
|
393 |
+
|
394 |
+
with col1:
|
395 |
+
if st.button("Nenne mir 5 wichtige Personalkennzahlen im Krankenhaus."):
|
396 |
+
query = "Nenne mir 5 wichtige Personalkennzahlen im Krankenhaus."
|
397 |
+
if st.button("Wie ist die durchschnittliche Bettenauslastung eines Krankenhauses?"):
|
398 |
+
query = ("Wie ist die durchschnittliche Bettenauslastung eines Krankenhauses?")
|
399 |
+
if st.button("Welches sind die häufigsten DRGs, die von den Krankenhäusern abgerechnet werden?"):
|
400 |
+
query = "Welches sind die häufigsten DRGs, die von den Krankenhäusern abgerechnet werden? "
|
401 |
+
|
402 |
+
|
403 |
+
with col2:
|
404 |
+
if st.button("Wie viel Casemixpunkte werden im Median von einer ärztlichen Vollkraft erbracht?"):
|
405 |
+
query = "Wie viel Casemixpunkte werden im Median von einer ärztlichen Vollkraft erbracht?"
|
406 |
+
if st.button("Bitte erstelle mir einer Übersicht der wichtiger Strukturkennzahlen eines Krankenhauses der Grund- und Regelversorgung."):
|
407 |
+
query = "Bitte erstelle mir einer Übersicht der wichtiger Strukturkennzahlen eines Krankenhauses der Grund- und Regelversorgung."
|
408 |
+
if st.button("Wie viele Patienten eines Grund- und Regelversorgers kommen aus welcher Fahrzeitzone?"):
|
409 |
+
query = "Wie viele Patienten eines Grund- und Regelversorgers kommen aus welcher Fahrzeitzone?"
|
410 |
|
411 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
|
413 |
+
if query:
|
414 |
+
full_query = ask_bot(query)
|
415 |
+
st.session_state['chat_history_page2'].append(("User", query, "new"))
|
416 |
+
|
417 |
+
# Start timing
|
418 |
+
start_time = time.time()
|
419 |
|
420 |
+
with st.spinner('Bot is thinking...'):
|
421 |
+
chain = load_chatbot()
|
422 |
+
docs = VectorStore.similarity_search(query=query, k=5)
|
423 |
+
with get_openai_callback() as cb:
|
424 |
+
response = chain.run(input_documents=docs, question=full_query)
|
425 |
+
response = handle_no_answer(response) # Process the response through the new function
|
426 |
+
|
427 |
+
# Stop timing
|
428 |
+
end_time = time.time()
|
429 |
|
430 |
+
# Calculate duration
|
431 |
+
duration = end_time - start_time
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
+
# You can use Streamlit's text function to display the timing
|
434 |
+
st.text(f"Response time: {duration:.2f} seconds")
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
|
436 |
+
st.session_state['chat_history_page2'].append(("Bot", response, "new"))
|
437 |
|
438 |
+
save_conversation(st.session_state['chat_history_page2'], st.session_state['session_id'], 2)
|
|
|
|
|
439 |
|
440 |
+
# Display new messages at the bottom
|
441 |
+
new_messages = st.session_state['chat_history_page2'][-2:]
|
442 |
+
for chat in new_messages:
|
443 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
444 |
+
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
|
446 |
+
|
447 |
+
# Clear the input field after the query is made
|
448 |
+
query = ""
|
449 |
+
|
450 |
+
# Mark all messages as old after displaying
|
451 |
+
st.session_state['chat_history_page2'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page2']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
|
453 |
except Exception as e:
|
454 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
477 |
image = Image.open('BinDoc Logo (Quadratisch).png')
|
478 |
st.image(image, use_column_width='always')
|
479 |
|
|
|
|
|
|
|
480 |
|
481 |
+
if not os.path.exists(pdf_path2):
|
482 |
+
st.error("File not found. Please check the file path.")
|
483 |
+
return
|
484 |
+
|
485 |
+
VectorStore = load_vector_store(pdf_path3, "Kosten_Str_2301", force_reload=False)
|
486 |
+
|
487 |
+
|
488 |
+
|
489 |
+
display_chat_history(st.session_state['chat_history_page3'])
|
490 |
+
|
491 |
+
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
492 |
+
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
493 |
+
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
494 |
+
|
495 |
+
new_messages_placeholder = st.empty()
|
496 |
+
|
497 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
498 |
+
|
499 |
+
add_vertical_space(2) # Adjust as per the desired spacing
|
500 |
+
|
501 |
+
# Create two columns for the buttons
|
502 |
+
col1, col2 = st.columns(2)
|
503 |
+
|
504 |
+
with col1:
|
505 |
+
if st.button("Wie hat sich die Bettenanzahl in den letzten 10 Jahren entwickelt?"):
|
506 |
+
query = "Wie hat sich die Bettenanzahl in den letzten 10 Jahren entwickelt?"
|
507 |
+
if st.button("Wie viele Patienten werden pro Jahr vollstationär behandelt?"):
|
508 |
+
query = ("Wie viele Patienten werden pro Jahr vollstationär behandelt?")
|
509 |
+
if st.button("Wie viele Vollkräfte arbeiten in Summe in deutschen Krankenhäusern?"):
|
510 |
+
query = "Wie viele Vollkräfte arbeiten in Summe in deutschen Krankenhäusern? "
|
511 |
+
|
512 |
+
|
513 |
+
with col2:
|
514 |
+
if st.button("Welche unterschiedlichen Personalkosten gibt es im Krankenhaus?"):
|
515 |
+
query = "Welche unterschiedlichen Personalkosten gibt es im Krankenhaus?"
|
516 |
+
if st.button("Welche Sachkosten werden in Krankenhäusern unterschieden?"):
|
517 |
+
query = "Welche Sachkosten werden in Krankenhäusern unterschieden? "
|
518 |
+
if st.button("Wie hoch sind die Gesamtkosten der Krankenhäuser pro Jahr?"):
|
519 |
+
query = "Wie hoch sind die Gesamtkosten der Krankenhäuser pro Jahr?"
|
520 |
|
521 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
|
523 |
+
if query:
|
524 |
+
full_query = ask_bot(query)
|
525 |
+
st.session_state['chat_history_page3'].append(("User", query, "new"))
|
526 |
+
|
527 |
+
# Start timing
|
528 |
+
start_time = time.time()
|
529 |
|
530 |
+
with st.spinner('Bot is thinking...'):
|
531 |
+
chain = load_chatbot()
|
532 |
+
docs = VectorStore.similarity_search(query=query, k=5)
|
533 |
+
with get_openai_callback() as cb:
|
534 |
+
response = chain.run(input_documents=docs, question=full_query)
|
535 |
+
response = handle_no_answer(response) # Process the response through the new function
|
536 |
+
|
537 |
+
# Stop timing
|
538 |
+
end_time = time.time()
|
539 |
|
540 |
+
# Calculate duration
|
541 |
+
duration = end_time - start_time
|
|
|
|
|
|
|
|
|
|
|
542 |
|
543 |
+
# You can use Streamlit's text function to display the timing
|
544 |
+
st.text(f"Response time: {duration:.2f} seconds")
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
|
546 |
+
st.session_state['chat_history_page3'].append(("Bot", response, "new"))
|
547 |
|
|
|
|
|
|
|
548 |
|
549 |
+
# Display new messages at the bottom
|
550 |
+
new_messages = st.session_state['chat_history_page3'][-2:]
|
551 |
+
for chat in new_messages:
|
552 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
553 |
+
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
|
555 |
+
save_conversation(st.session_state['chat_history_page3'], st.session_state['session_id'], 3)
|
|
|
556 |
|
557 |
+
# Clear the input field after the query is made
|
558 |
+
query = ""
|
559 |
+
|
560 |
+
# Mark all messages as old after displaying
|
561 |
+
st.session_state['chat_history_page3'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page3']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
|
563 |
except Exception as e:
|
564 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|