Anne31415 commited on
Commit
2c94a5a
·
verified ·
1 Parent(s): 15a43d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -122
app.py CHANGED
@@ -501,131 +501,15 @@ def page2():
501
 
502
  def page3():
503
  try:
504
- hide_streamlit_style = """
505
- <style>
506
- #MainMenu {visibility: hidden;}
507
- footer {visibility: hidden;}
508
- </style>
509
- """
510
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
511
-
512
- # Create columns for layout
513
- col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
514
-
515
- with col1:
516
- st.title("Kosten- und Strukturdaten der Krankenhäuser")
517
-
518
- with col2:
519
- # Load and display the image in the right column, which will be the top-right corner of the page
520
- image = Image.open('BinDoc Logo (Quadratisch).png')
521
- st.image(image, use_column_width='always')
522
 
523
- if not os.path.exists(pdf_path3):
524
- st.error("File not found. Please check the file path.")
525
- return
526
-
527
-
528
- # Initialize CromA client
529
- chroma_client = chromadb.Client()
530
-
531
- try:
532
- # Attempt to create the collection
533
- collection = chroma_client.create_collection(name="Kosten_Strukturdaten0602204")
534
- except Exception as e:
535
- # If the collection already exists, fetch the existing collection
536
- if 'already exists' in str(e):
537
- collection = chroma_client.get_collection(name="Kosten_Strukturdaten0602204")
538
- else:
539
- # If the error is due to some other reason, re-raise the exception
540
- raise e
541
-
542
- # Add the extracted text from PDF to the Chroma collection
543
- collection.add(
544
- documents=[pdf_text],
545
- metadatas=[{"source": pdf_path3}], # Add any relevant metadata for your document
546
- ids=[("Kosten_Strukturdaten0602204")]
547
- )
548
-
549
- display_chat_history(st.session_state['chat_history_page3'])
550
-
551
- st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
552
- st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
553
- st.write("<!-- End Spacer -->", unsafe_allow_html=True)
554
-
555
- new_messages_placeholder = st.empty()
556
-
557
- query = st.text_input("Geben Sie hier Ihre Frage ein / Enter your question here:")
558
-
559
- add_vertical_space(2) # Adjust as per the desired spacing
560
-
561
- # Create two columns for the buttons
562
- col1, col2 = st.columns(2)
563
-
564
- with col1:
565
- if st.button("Test1"):
566
- query = "Test1"
567
-
568
- with col2:
569
- if st.button("Test2"):
570
- query = "Test2"
571
-
572
-
573
- # Handling query input
574
- if query:
575
- full_query = ask_bot(query)
576
- st.session_state['chat_history_page3'].append(("User", query, "new"))
577
-
578
- # Start timing for response
579
- start_time = time.time()
580
-
581
- # Querying the CromA collection
582
- results = collection.query(
583
- query_texts=[full_query],
584
- n_results=5 # Adjust the number of results as needed
585
- )
586
-
587
- # Calculate the response duration
588
- end_time = time.time()
589
- duration = end_time - start_time
590
-
591
- # Process and display response from CromA results
592
- if results:
593
- # TODO: Adjust the following logic based on CromA's actual result structure
594
- response = f"Top result: {results[0]['text']}" # Example response using the first result
595
- else:
596
- response = "No results found for your query."
597
-
598
- st.session_state['chat_history_page3'].append(("Eve", response, "new"))
599
-
600
-
601
- # Combine chat histories from all pages
602
- all_chat_histories = [
603
- st.session_state['chat_history_page1'],
604
- st.session_state['chat_history_page2'],
605
- st.session_state['chat_history_page3']
606
- ]
607
-
608
- # Save the combined chat histories
609
- save_conversation(all_chat_histories, st.session_state['session_id'])
610
-
611
- # Display new messages at the bottom
612
- new_messages = st.session_state['chat_history_page3'][-2:]
613
- for chat in new_messages:
614
- background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
615
- 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)
616
-
617
- # Update the response time placeholder after the messages are displayed
618
- response_time_placeholder.text(f"Response time: {duration:.2f} seconds")
619
-
620
- # Clear the input field after the query is made
621
- query = ""
622
-
623
- # Mark all messages as old after displaying
624
- st.session_state['chat_history_page3'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page3']]
625
 
626
  except Exception as e:
627
- st.error(f"An error occurred: {repr(e)}") # Optionally log the exception details to a file or error tracking service
628
-
629
 
630
 
631
 
 
501
 
502
  def page3():
503
  try:
504
+ # Minimal layout setup
505
+ st.title("Kosten- und Strukturdaten der Krankenhäuser")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
 
507
+ # Simple interaction
508
+ if st.button("Test Button"):
509
+ st.write("Button clicked.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
 
511
  except Exception as e:
512
+ st.error(f"An error occurred: {repr(e)}")
 
513
 
514
 
515