Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -70,8 +70,7 @@ api_key = os.getenv("OPENAI_API_KEY")
|
|
70 |
|
71 |
|
72 |
|
73 |
-
|
74 |
-
@st.cache_data(persist="disk")
|
75 |
def load_vector_store(file_path, store_name, force_reload=False):
|
76 |
local_repo_path = "Private_Book"
|
77 |
vector_store_path = os.path.join(local_repo_path, f"{store_name}.pkl")
|
@@ -233,8 +232,8 @@ def save_conversation(chat_histories, session_id):
|
|
233 |
|
234 |
def display_session_id():
|
235 |
session_id = st.session_state['session_id']
|
236 |
-
st.sidebar.markdown(f"**
|
237 |
-
st.sidebar.markdown("
|
238 |
|
239 |
|
240 |
def page1():
|
@@ -251,7 +250,7 @@ def page1():
|
|
251 |
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
252 |
|
253 |
with col1:
|
254 |
-
st.title("
|
255 |
|
256 |
with col2:
|
257 |
# Load and display the image in the right column, which will be the top-right corner of the page
|
@@ -302,51 +301,50 @@ def page1():
|
|
302 |
if query:
|
303 |
full_query = ask_bot(query)
|
304 |
st.session_state['chat_history_page1'].append(("User", query, "new"))
|
305 |
-
|
306 |
# Start timing
|
307 |
start_time = time.time()
|
308 |
-
|
309 |
-
|
|
|
|
|
|
|
|
|
310 |
chain = load_chatbot()
|
311 |
docs = VectorStore.similarity_search(query=query, k=5)
|
312 |
with get_openai_callback() as cb:
|
313 |
response = chain.run(input_documents=docs, question=full_query)
|
314 |
-
response = handle_no_answer(response)
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
344 |
-
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)
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
# Clear the input field after the query is made
|
349 |
-
query = ""
|
350 |
|
351 |
# Mark all messages as old after displaying
|
352 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
@@ -371,7 +369,7 @@ def page2():
|
|
371 |
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
372 |
|
373 |
with col1:
|
374 |
-
st.title("
|
375 |
|
376 |
with col2:
|
377 |
# Load and display the image in the right column, which will be the top-right corner of the page
|
@@ -395,7 +393,7 @@ def page2():
|
|
395 |
|
396 |
new_messages_placeholder = st.empty()
|
397 |
|
398 |
-
query = st.text_input("
|
399 |
|
400 |
add_vertical_space(2) # Adjust as per the desired spacing
|
401 |
|
@@ -427,8 +425,11 @@ def page2():
|
|
427 |
|
428 |
# Start timing
|
429 |
start_time = time.time()
|
|
|
|
|
|
|
430 |
|
431 |
-
with st.spinner('
|
432 |
chain = load_chatbot()
|
433 |
docs = VectorStore.similarity_search(query=query, k=5)
|
434 |
with get_openai_callback() as cb:
|
@@ -442,9 +443,8 @@ def page2():
|
|
442 |
|
443 |
# Calculate duration
|
444 |
duration = end_time - start_time
|
445 |
-
st.text(f"Response time: {duration:.2f} seconds")
|
446 |
|
447 |
-
st.session_state['chat_history_page2'].append(("
|
448 |
|
449 |
|
450 |
# Combine chat histories from all pages
|
@@ -462,8 +462,10 @@ def page2():
|
|
462 |
for chat in new_messages:
|
463 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
464 |
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)
|
465 |
-
|
466 |
-
|
|
|
|
|
467 |
# Clear the input field after the query is made
|
468 |
query = ""
|
469 |
|
@@ -514,7 +516,7 @@ def page3():
|
|
514 |
|
515 |
new_messages_placeholder = st.empty()
|
516 |
|
517 |
-
query = st.text_input("
|
518 |
|
519 |
add_vertical_space(2) # Adjust as per the desired spacing
|
520 |
|
@@ -547,7 +549,10 @@ def page3():
|
|
547 |
# Start timing
|
548 |
start_time = time.time()
|
549 |
|
550 |
-
|
|
|
|
|
|
|
551 |
chain = load_chatbot()
|
552 |
docs = VectorStore.similarity_search(query=query, k=5)
|
553 |
with get_openai_callback() as cb:
|
@@ -561,9 +566,8 @@ def page3():
|
|
561 |
|
562 |
# Calculate duration
|
563 |
duration = end_time - start_time
|
564 |
-
st.text(f"Response time: {duration:.2f} seconds")
|
565 |
|
566 |
-
st.session_state['chat_history_page3'].append(("
|
567 |
|
568 |
# Combine chat histories from all pages
|
569 |
all_chat_histories = [
|
@@ -581,8 +585,10 @@ def page3():
|
|
581 |
for chat in new_messages:
|
582 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
583 |
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)
|
|
|
|
|
|
|
584 |
|
585 |
-
|
586 |
|
587 |
# Clear the input field after the query is made
|
588 |
query = ""
|
@@ -596,7 +602,7 @@ def page3():
|
|
596 |
|
597 |
def page4():
|
598 |
try:
|
599 |
-
st.header(":mailbox:
|
600 |
st.markdown("Ihre Session-ID finden Sie auf der linken Seite!")
|
601 |
|
602 |
contact_form = """
|
@@ -628,31 +634,31 @@ def page4():
|
|
628 |
def display_session_id():
|
629 |
session_id = st.session_state['session_id']
|
630 |
st.sidebar.markdown(f"**Your Session ID:** `{session_id}`")
|
631 |
-
st.sidebar.markdown("
|
632 |
|
633 |
# Main function
|
634 |
def main():
|
635 |
# Sidebar content
|
636 |
with st.sidebar:
|
637 |
st.title('BinDoc GmbH')
|
638 |
-
st.markdown("
|
639 |
add_vertical_space(1)
|
640 |
-
page = st.sidebar.selectbox("
|
641 |
add_vertical_space(4)
|
642 |
display_session_id() # Display the session ID in the sidebar
|
643 |
st.write('Made with ❤️ by BinDoc GmbH')
|
644 |
|
645 |
|
646 |
# Main area content based on page selection
|
647 |
-
if page == "
|
648 |
page1()
|
649 |
-
elif page == "
|
650 |
page2()
|
651 |
-
elif page == "Kosten- und Strukturdaten
|
652 |
page3()
|
653 |
-
elif page == "
|
654 |
page4()
|
655 |
|
656 |
|
657 |
if __name__ == "__main__":
|
658 |
-
main()
|
|
|
70 |
|
71 |
|
72 |
|
73 |
+
@st.cache_resource
|
|
|
74 |
def load_vector_store(file_path, store_name, force_reload=False):
|
75 |
local_repo_path = "Private_Book"
|
76 |
vector_store_path = os.path.join(local_repo_path, f"{store_name}.pkl")
|
|
|
232 |
|
233 |
def display_session_id():
|
234 |
session_id = st.session_state['session_id']
|
235 |
+
st.sidebar.markdown(f"**Ihre Session ID:** `{session_id}`")
|
236 |
+
st.sidebar.markdown("Verwenden Sie diese ID als Referenz bei Mitteilungen oder Rückmeldungen.")
|
237 |
|
238 |
|
239 |
def page1():
|
|
|
250 |
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
251 |
|
252 |
with col1:
|
253 |
+
st.title("Alles zur aktuellen Krankenhausreform!")
|
254 |
|
255 |
with col2:
|
256 |
# Load and display the image in the right column, which will be the top-right corner of the page
|
|
|
301 |
if query:
|
302 |
full_query = ask_bot(query)
|
303 |
st.session_state['chat_history_page1'].append(("User", query, "new"))
|
304 |
+
|
305 |
# Start timing
|
306 |
start_time = time.time()
|
307 |
+
|
308 |
+
# Create a placeholder for the response time
|
309 |
+
response_time_placeholder = st.empty()
|
310 |
+
|
311 |
+
# Include the spinner around all processing and display operations
|
312 |
+
with st.spinner('Eve denkt über Ihre Frage nach...'):
|
313 |
chain = load_chatbot()
|
314 |
docs = VectorStore.similarity_search(query=query, k=5)
|
315 |
with get_openai_callback() as cb:
|
316 |
response = chain.run(input_documents=docs, question=full_query)
|
317 |
+
response = handle_no_answer(response)
|
318 |
+
|
319 |
+
# Stop timing
|
320 |
+
end_time = time.time()
|
321 |
+
|
322 |
+
# Calculate duration
|
323 |
+
duration = end_time - start_time
|
324 |
+
|
325 |
+
st.session_state['chat_history_page1'].append(("Eve", response, "new"))
|
326 |
+
|
327 |
+
# Combine chat histories from all pages
|
328 |
+
all_chat_histories = [
|
329 |
+
st.session_state['chat_history_page1'],
|
330 |
+
st.session_state['chat_history_page2'],
|
331 |
+
st.session_state['chat_history_page3']
|
332 |
+
]
|
333 |
+
|
334 |
+
# Save the combined chat histories
|
335 |
+
save_conversation(all_chat_histories, st.session_state['session_id'])
|
336 |
+
|
337 |
+
# Display new messages at the bottom
|
338 |
+
new_messages = st.session_state['chat_history_page1'][-2:]
|
339 |
+
for chat in new_messages:
|
340 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
341 |
+
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)
|
342 |
+
|
343 |
+
# Update the response time placeholder after the messages are displayed
|
344 |
+
response_time_placeholder.text(f"Response time: {duration:.2f} seconds")
|
345 |
+
|
|
|
|
|
|
|
|
|
|
|
346 |
# Clear the input field after the query is made
|
347 |
+
query = ""
|
348 |
|
349 |
# Mark all messages as old after displaying
|
350 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
|
|
369 |
col1, col2 = st.columns([3, 1]) # Adjust the ratio to your liking
|
370 |
|
371 |
with col1:
|
372 |
+
st.title("Die wichtigsten 100 Kennzahlen und KPIs!")
|
373 |
|
374 |
with col2:
|
375 |
# Load and display the image in the right column, which will be the top-right corner of the page
|
|
|
393 |
|
394 |
new_messages_placeholder = st.empty()
|
395 |
|
396 |
+
query = st.text_input("Geben Sie hier Ihre Frage ein / Enter your question here:")
|
397 |
|
398 |
add_vertical_space(2) # Adjust as per the desired spacing
|
399 |
|
|
|
425 |
|
426 |
# Start timing
|
427 |
start_time = time.time()
|
428 |
+
|
429 |
+
# Create a placeholder for the response time
|
430 |
+
response_time_placeholder = st.empty()
|
431 |
|
432 |
+
with st.spinner('Eve denkt über Ihre Frage nach...'):
|
433 |
chain = load_chatbot()
|
434 |
docs = VectorStore.similarity_search(query=query, k=5)
|
435 |
with get_openai_callback() as cb:
|
|
|
443 |
|
444 |
# Calculate duration
|
445 |
duration = end_time - start_time
|
|
|
446 |
|
447 |
+
st.session_state['chat_history_page2'].append(("Eve", response, "new"))
|
448 |
|
449 |
|
450 |
# Combine chat histories from all pages
|
|
|
462 |
for chat in new_messages:
|
463 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
464 |
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)
|
465 |
+
|
466 |
+
# Update the response time placeholder after the messages are displayed
|
467 |
+
response_time_placeholder.text(f"Response time: {duration:.2f} seconds")
|
468 |
+
|
469 |
# Clear the input field after the query is made
|
470 |
query = ""
|
471 |
|
|
|
516 |
|
517 |
new_messages_placeholder = st.empty()
|
518 |
|
519 |
+
query = st.text_input("Geben Sie hier Ihre Frage ein / Enter your question here:")
|
520 |
|
521 |
add_vertical_space(2) # Adjust as per the desired spacing
|
522 |
|
|
|
549 |
# Start timing
|
550 |
start_time = time.time()
|
551 |
|
552 |
+
# Create a placeholder for the response time
|
553 |
+
response_time_placeholder = st.empty()
|
554 |
+
|
555 |
+
with st.spinner('Eve denkt über Ihre Frage nach...'):
|
556 |
chain = load_chatbot()
|
557 |
docs = VectorStore.similarity_search(query=query, k=5)
|
558 |
with get_openai_callback() as cb:
|
|
|
566 |
|
567 |
# Calculate duration
|
568 |
duration = end_time - start_time
|
|
|
569 |
|
570 |
+
st.session_state['chat_history_page3'].append(("Eve", response, "new"))
|
571 |
|
572 |
# Combine chat histories from all pages
|
573 |
all_chat_histories = [
|
|
|
585 |
for chat in new_messages:
|
586 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
587 |
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)
|
588 |
+
|
589 |
+
# Update the response time placeholder after the messages are displayed
|
590 |
+
response_time_placeholder.text(f"Response time: {duration:.2f} seconds")
|
591 |
|
|
|
592 |
|
593 |
# Clear the input field after the query is made
|
594 |
query = ""
|
|
|
602 |
|
603 |
def page4():
|
604 |
try:
|
605 |
+
st.header(":mailbox: Kontakt & Feedback!")
|
606 |
st.markdown("Ihre Session-ID finden Sie auf der linken Seite!")
|
607 |
|
608 |
contact_form = """
|
|
|
634 |
def display_session_id():
|
635 |
session_id = st.session_state['session_id']
|
636 |
st.sidebar.markdown(f"**Your Session ID:** `{session_id}`")
|
637 |
+
st.sidebar.markdown("Verwenden Sie diese ID als Referenz bei Mitteilungen oder Rückmeldungen.")
|
638 |
|
639 |
# Main function
|
640 |
def main():
|
641 |
# Sidebar content
|
642 |
with st.sidebar:
|
643 |
st.title('BinDoc GmbH')
|
644 |
+
st.markdown("Tauchen Sie ein in eine revolutionäre Erfahrung mit BinDocs Chat-App - angetrieben von fortschrittlichster KI-Technologie.")
|
645 |
add_vertical_space(1)
|
646 |
+
page = st.sidebar.selectbox("Wählen Sie eine Seite aus:", ["Krankenhausreform!", "Kennzahlen und KPIs!", "Kosten- und Strukturdaten", "Kontakt & Feedback!"])
|
647 |
add_vertical_space(4)
|
648 |
display_session_id() # Display the session ID in the sidebar
|
649 |
st.write('Made with ❤️ by BinDoc GmbH')
|
650 |
|
651 |
|
652 |
# Main area content based on page selection
|
653 |
+
if page == "Krankenhausreform!":
|
654 |
page1()
|
655 |
+
elif page == "Kennzahlen und KPIs!":
|
656 |
page2()
|
657 |
+
elif page == "Kosten- und Strukturdaten":
|
658 |
page3()
|
659 |
+
elif page == "Kontakt & Feedback!":
|
660 |
page4()
|
661 |
|
662 |
|
663 |
if __name__ == "__main__":
|
664 |
+
main()
|