|
import streamlit as st |
|
from styles import apply_styling |
|
from utils import remove_reasoning_and_sources, clean_explanation |
|
from session_state import initialize_session_state, add_message_to_history, get_full_history |
|
from chat_display import display_chat_history, show_typing_indicator, display_legal_disclaimer |
|
from model import ( |
|
orchestrator_chat, |
|
fetch_medical_evidence, |
|
extract_and_link_sources, |
|
parse_doctor_response |
|
) |
|
from report_generator import ( |
|
extract_medical_json, |
|
build_medical_report, |
|
generate_and_download_report, |
|
show_email_form |
|
) |
|
|
|
|
|
st.set_page_config( |
|
page_title="Daease", |
|
page_icon=None, |
|
layout="wide", |
|
initial_sidebar_state="expanded" |
|
) |
|
|
|
|
|
apply_styling() |
|
|
|
|
|
initialize_session_state() |
|
|
|
|
|
if 'conversation_lock' not in st.session_state: |
|
st.session_state.conversation_lock = False |
|
|
|
|
|
with st.sidebar: |
|
st.header("Features") |
|
st.session_state.use_rag = st.toggle("Database Search", value=False, |
|
help="Toggle to enable or disable medical database search") |
|
|
|
|
|
if st.button("Generate Report", use_container_width=True): |
|
|
|
if not st.session_state.get('processing', False) and not st.session_state.get('conversation_lock', False): |
|
st.session_state.show_report_form = True |
|
|
|
st.session_state.report_step = 1 |
|
st.rerun() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if st.session_state.get('show_report_form', False) and not st.session_state.get('processing', False) and not st.session_state.get('conversation_lock', False): |
|
st.subheader("Report Information") |
|
generate_and_download_report() |
|
|
|
|
|
st.title("What are you Diagnosing Today?") |
|
|
|
|
|
display_chat_history() |
|
|
|
|
|
show_typing_indicator() |
|
|
|
|
|
if prompt := st.chat_input("Describe your symptoms or ask a medical question..."): |
|
|
|
st.session_state.conversation_lock = True |
|
|
|
|
|
add_message_to_history({"role": "user", "content": prompt}) |
|
|
|
|
|
st.session_state.processing = True |
|
|
|
|
|
st.rerun() |
|
|
|
|
|
if st.session_state.processing: |
|
try: |
|
|
|
full_history = get_full_history() |
|
|
|
if full_history: |
|
current_user_prompt_message = full_history[-1] |
|
|
|
|
|
history_for_orchestrator = full_history[:-1] |
|
|
|
|
|
current_query = current_user_prompt_message["content"] |
|
|
|
reply, explanation, follow_up_questions, evidence = orchestrator_chat( |
|
history_for_orchestrator, |
|
current_query, |
|
use_rag=st.session_state.use_rag, |
|
is_follow_up=len(history_for_orchestrator) > 0 |
|
) |
|
|
|
|
|
cleaned_reply = remove_reasoning_and_sources(reply) |
|
cleaned_explanation = clean_explanation(explanation) if explanation else "" |
|
|
|
|
|
formatted_follow_up = follow_up_questions |
|
|
|
|
|
print(f"Follow-up questions to be stored: {formatted_follow_up}") |
|
|
|
|
|
assistant_message = { |
|
"role": "assistant", |
|
"content": cleaned_reply, |
|
"explanation": cleaned_explanation, |
|
"follow_up_questions": formatted_follow_up, |
|
"evidence": evidence if evidence else [] |
|
} |
|
|
|
|
|
add_message_to_history(assistant_message) |
|
finally: |
|
|
|
st.session_state.processing = False |
|
|
|
st.session_state.conversation_lock = False |
|
|
|
|
|
st.rerun() |
|
|
|
|
|
display_legal_disclaimer() |
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
import os |
|
import sys |
|
current_dir = os.path.dirname(os.path.abspath(__file__)) |
|
if current_dir not in sys.path: |
|
sys.path.insert(0, current_dir) |