Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,9 @@ if 'chat_history_page1' not in st.session_state:
|
|
27 |
if 'chat_history_page2' not in st.session_state:
|
28 |
st.session_state['chat_history_page2'] = []
|
29 |
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
# Step 1: Clone the Dataset Repository
|
@@ -41,9 +44,9 @@ repo.git_pull() # Pull the latest changes (if any)
|
|
41 |
# Step 2: Load the PDF File
|
42 |
pdf_path = "Private_Book/09012024_Kombi_2.pdf" # Replace with your PDF file path
|
43 |
|
44 |
-
|
45 |
-
pdf_path2 = "Private_Book/Deutsche_Kodierrichtlinien_23.pdf" # Replace with your PDF file path
|
46 |
|
|
|
47 |
|
48 |
api_key = os.getenv("OPENAI_API_KEY")
|
49 |
# Retrieve the API key from st.secrets
|
@@ -391,6 +394,116 @@ def page2():
|
|
391 |
|
392 |
|
393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
|
395 |
|
396 |
def main():
|
@@ -408,6 +521,8 @@ def main():
|
|
408 |
page1()
|
409 |
elif page == "Coding Assistance Bot":
|
410 |
page2()
|
|
|
|
|
411 |
|
412 |
|
413 |
if __name__ == "__main__":
|
|
|
27 |
if 'chat_history_page2' not in st.session_state:
|
28 |
st.session_state['chat_history_page2'] = []
|
29 |
|
30 |
+
if 'chat_history_page3' not in st.session_state:
|
31 |
+
st.session_state['chat_history_page3'] = []
|
32 |
+
|
33 |
|
34 |
|
35 |
# Step 1: Clone the Dataset Repository
|
|
|
44 |
# Step 2: Load the PDF File
|
45 |
pdf_path = "Private_Book/09012024_Kombi_2.pdf" # Replace with your PDF file path
|
46 |
|
47 |
+
pdf_path2 = "Private_Book/Grunddaten_krankenhaeuser-2018_21.pdf"
|
|
|
48 |
|
49 |
+
pdf_path3 = "Private_Book/Deutsche_Kodierrichtlinien_23.pdf"
|
50 |
|
51 |
api_key = os.getenv("OPENAI_API_KEY")
|
52 |
# Retrieve the API key from st.secrets
|
|
|
394 |
|
395 |
|
396 |
|
397 |
+
def page3():
|
398 |
+
try:
|
399 |
+
hide_streamlit_style = """
|
400 |
+
<style>
|
401 |
+
#MainMenu {visibility: hidden;}
|
402 |
+
footer {visibility: hidden;}
|
403 |
+
</style>
|
404 |
+
"""
|
405 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
406 |
+
|
407 |
+
# Create columns for layout
|
408 |
+
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
409 |
+
|
410 |
+
with col1:
|
411 |
+
st.title("Test!")
|
412 |
+
|
413 |
+
with col2:
|
414 |
+
# Load and display the image in the right column, which will be the top-right corner of the page
|
415 |
+
image = Image.open('BinDoc Logo (Quadratisch).png')
|
416 |
+
st.image(image, use_column_width='always')
|
417 |
+
|
418 |
+
|
419 |
+
# Start tracking user interactions
|
420 |
+
with streamlit_analytics.track():
|
421 |
+
|
422 |
+
if not os.path.exists(pdf_path2):
|
423 |
+
st.error("File not found. Please check the file path.")
|
424 |
+
return
|
425 |
+
|
426 |
+
VectorStore = load_vector_store(pdf_path3, "vector_store_page3", force_reload=False)
|
427 |
+
|
428 |
+
|
429 |
+
|
430 |
+
display_chat_history(st.session_state['chat_history_page3'])
|
431 |
+
|
432 |
+
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
433 |
+
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
434 |
+
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
435 |
+
|
436 |
+
new_messages_placeholder = st.empty()
|
437 |
+
|
438 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
439 |
+
|
440 |
+
add_vertical_space(2) # Adjust as per the desired spacing
|
441 |
+
|
442 |
+
# Create two columns for the buttons
|
443 |
+
col1, col2 = st.columns(2)
|
444 |
+
|
445 |
+
with col1:
|
446 |
+
if st.button("Wann kodiere ich etwas als Hauptdiagnose und wann als Nebendiagnose?"):
|
447 |
+
query = "Wann kodiere ich etwas als Hauptdiagnose und wann als Nebendiagnose?"
|
448 |
+
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?"):
|
449 |
+
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?")
|
450 |
+
if st.button("Hauptdiagnose: Hirntumor wie kodiere ich das?"):
|
451 |
+
query = "Hauptdiagnose: Hirntumor wie kodiere ich das?"
|
452 |
+
|
453 |
+
|
454 |
+
with col2:
|
455 |
+
if st.button("Welche Prozeduren werden normalerweise nicht verschlüsselt?"):
|
456 |
+
query = "Welche Prozeduren werden normalerweise nicht verschlüsselt?"
|
457 |
+
if st.button("Was muss ich bei der Kodierung der Folgezusänden von Krankheiten beachten?"):
|
458 |
+
query = "Was muss ich bei der Kodierung der Folgezusänden von Krankheiten beachten?"
|
459 |
+
if st.button("Was mache ich bei einer Verdachtsdiagnose, wenn mein Patien nach Hause entlassen wird?"):
|
460 |
+
query = "Was mache ich bei einer Verdachtsdiagnose, wenn mein Patien nach Hause entlassen wird?"
|
461 |
+
|
462 |
+
|
463 |
+
if query:
|
464 |
+
st.session_state['chat_history_page3'].append(("User", query, "new"))
|
465 |
+
|
466 |
+
# Start timing
|
467 |
+
start_time = time.time()
|
468 |
+
|
469 |
+
with st.spinner('Bot is thinking...'):
|
470 |
+
chain = load_chatbot()
|
471 |
+
docs = VectorStore.similarity_search(query=query, k=3)
|
472 |
+
with get_openai_callback() as cb:
|
473 |
+
response = chain.run(input_documents=docs, question=query)
|
474 |
+
response = handle_no_answer(response) # Process the response through the new function
|
475 |
+
|
476 |
+
|
477 |
+
|
478 |
+
# Stop timing
|
479 |
+
end_time = time.time()
|
480 |
+
|
481 |
+
# Calculate duration
|
482 |
+
duration = end_time - start_time
|
483 |
+
|
484 |
+
# You can use Streamlit's text function to display the timing
|
485 |
+
st.text(f"Response time: {duration:.2f} seconds")
|
486 |
+
|
487 |
+
st.session_state['chat_history_page3'].append(("Bot", response, "new"))
|
488 |
+
|
489 |
+
|
490 |
+
# Display new messages at the bottom
|
491 |
+
new_messages = st.session_state['chat_history_page3'][-2:]
|
492 |
+
for chat in new_messages:
|
493 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
494 |
+
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)
|
495 |
+
|
496 |
+
|
497 |
+
# Clear the input field after the query is made
|
498 |
+
query = ""
|
499 |
+
|
500 |
+
# Mark all messages as old after displaying
|
501 |
+
st.session_state['chat_history_page3'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page3']]
|
502 |
+
|
503 |
+
except Exception as e:
|
504 |
+
st.error(f"Upsi, an unexpected error occurred: {e}")
|
505 |
+
# Optionally log the exception details to a file or error tracking service
|
506 |
+
|
507 |
|
508 |
|
509 |
def main():
|
|
|
521 |
page1()
|
522 |
elif page == "Coding Assistance Bot":
|
523 |
page2()
|
524 |
+
elif page == "Test Assistance Bot":
|
525 |
+
page3()
|
526 |
|
527 |
|
528 |
if __name__ == "__main__":
|