Update app.py
Browse files
app.py
CHANGED
|
@@ -1,100 +1,97 @@
|
|
| 1 |
-
"""
|
| 2 |
-
AI Healthcare Assistant - Main Application
|
| 3 |
-
Entry point that orchestrates UI, agents, and workflow
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import streamlit as st
|
| 7 |
-
from config import initialize_clients, get_api_keys
|
| 8 |
-
from agents import AgentState, create_workflow
|
| 9 |
-
from ui import (
|
| 10 |
-
apply_custom_css,
|
| 11 |
-
render_header,
|
| 12 |
-
render_sidebar,
|
| 13 |
-
render_input_section,
|
| 14 |
-
render_analyze_button,
|
| 15 |
-
render_results,
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
groq_api_key
|
| 32 |
-
|
| 33 |
-
st.
|
| 34 |
-
st.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
st.
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
apply_custom_css()
|
| 45 |
-
|
| 46 |
-
# Render header
|
| 47 |
-
render_header()
|
| 48 |
-
|
| 49 |
-
# Render sidebar
|
| 50 |
-
render_sidebar()
|
| 51 |
-
|
| 52 |
-
# Render input section
|
| 53 |
-
user_input = render_input_section()
|
| 54 |
-
|
| 55 |
-
# Render analyze button
|
| 56 |
-
analyze_button = render_analyze_button()
|
| 57 |
-
|
| 58 |
-
# Initialize workflow in session state
|
| 59 |
-
if "workflow" not in st.session_state:
|
| 60 |
-
st.session_state.workflow = create_workflow(llm, tavily_client)
|
| 61 |
-
|
| 62 |
-
if "results" not in st.session_state:
|
| 63 |
-
st.session_state.results = None
|
| 64 |
-
|
| 65 |
-
# Process analysis
|
| 66 |
-
if analyze_button and user_input:
|
| 67 |
-
with st.spinner("🧠 Analyzing symptoms and gathering information..."):
|
| 68 |
-
try:
|
| 69 |
-
# Initialize state
|
| 70 |
-
initial_state: AgentState = {
|
| 71 |
-
"user_input": user_input,
|
| 72 |
-
"symptom_analysis": "",
|
| 73 |
-
"medication_advice": "",
|
| 74 |
-
"home_remedies": "",
|
| 75 |
-
"diet_lifestyle": "",
|
| 76 |
-
"doctor_recommendations": "",
|
| 77 |
-
"error": ""
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
# Run workflow
|
| 81 |
-
result = st.session_state.workflow.invoke(initial_state)
|
| 82 |
-
st.session_state.results = result
|
| 83 |
-
|
| 84 |
-
except Exception as e:
|
| 85 |
-
st.error(f"Error processing request: {str(e)}")
|
| 86 |
-
st.session_state.results = None
|
| 87 |
-
|
| 88 |
-
# Display results
|
| 89 |
-
if st.session_state.results:
|
| 90 |
-
render_results(st.session_state.results)
|
| 91 |
-
|
| 92 |
-
# Render
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
if __name__ == "__main__":
|
| 100 |
-
main()
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AI Healthcare Assistant - Main Application
|
| 3 |
+
Entry point that orchestrates UI, agents, and workflow
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import streamlit as st
|
| 7 |
+
from config import initialize_clients, get_api_keys
|
| 8 |
+
from agents import AgentState, create_workflow
|
| 9 |
+
from ui import (
|
| 10 |
+
apply_custom_css,
|
| 11 |
+
render_header,
|
| 12 |
+
render_sidebar,
|
| 13 |
+
render_input_section,
|
| 14 |
+
render_analyze_button,
|
| 15 |
+
render_results,
|
| 16 |
+
render_footer
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
"""Main application function"""
|
| 22 |
+
st.set_page_config(
|
| 23 |
+
page_title="AI Healthcare Assistant",
|
| 24 |
+
page_icon="🩺",
|
| 25 |
+
layout="wide",
|
| 26 |
+
initial_sidebar_state="expanded"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Check for API keys
|
| 30 |
+
groq_api_key, tavily_api_key = get_api_keys()
|
| 31 |
+
if not groq_api_key or not tavily_api_key:
|
| 32 |
+
st.error("⚠️ Please set GROQ_API_KEY and TAVILY_API_KEY in your .env file")
|
| 33 |
+
st.info("Create a `.env` file in the project root with:\n```\nGROQ_API_KEY=your_key_here\nTAVILY_API_KEY=your_key_here\n```")
|
| 34 |
+
st.stop()
|
| 35 |
+
|
| 36 |
+
# Initialize API clients
|
| 37 |
+
llm, tavily_client, error = initialize_clients()
|
| 38 |
+
if error:
|
| 39 |
+
st.error(f"Error initializing clients: {error}")
|
| 40 |
+
st.stop()
|
| 41 |
+
|
| 42 |
+
# Apply custom CSS with theme support
|
| 43 |
+
theme = st.session_state.get("theme", "light")
|
| 44 |
+
apply_custom_css(theme)
|
| 45 |
+
|
| 46 |
+
# Render header
|
| 47 |
+
render_header()
|
| 48 |
+
|
| 49 |
+
# Render sidebar
|
| 50 |
+
render_sidebar()
|
| 51 |
+
|
| 52 |
+
# Render input section
|
| 53 |
+
user_input = render_input_section()
|
| 54 |
+
|
| 55 |
+
# Render analyze button
|
| 56 |
+
analyze_button = render_analyze_button()
|
| 57 |
+
|
| 58 |
+
# Initialize workflow in session state
|
| 59 |
+
if "workflow" not in st.session_state:
|
| 60 |
+
st.session_state.workflow = create_workflow(llm, tavily_client)
|
| 61 |
+
|
| 62 |
+
if "results" not in st.session_state:
|
| 63 |
+
st.session_state.results = None
|
| 64 |
+
|
| 65 |
+
# Process analysis
|
| 66 |
+
if analyze_button and user_input:
|
| 67 |
+
with st.spinner("🧠 Analyzing symptoms and gathering information..."):
|
| 68 |
+
try:
|
| 69 |
+
# Initialize state
|
| 70 |
+
initial_state: AgentState = {
|
| 71 |
+
"user_input": user_input,
|
| 72 |
+
"symptom_analysis": "",
|
| 73 |
+
"medication_advice": "",
|
| 74 |
+
"home_remedies": "",
|
| 75 |
+
"diet_lifestyle": "",
|
| 76 |
+
"doctor_recommendations": "",
|
| 77 |
+
"error": ""
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
# Run workflow
|
| 81 |
+
result = st.session_state.workflow.invoke(initial_state)
|
| 82 |
+
st.session_state.results = result
|
| 83 |
+
|
| 84 |
+
except Exception as e:
|
| 85 |
+
st.error(f"Error processing request: {str(e)}")
|
| 86 |
+
st.session_state.results = None
|
| 87 |
+
|
| 88 |
+
# Display results
|
| 89 |
+
if st.session_state.results:
|
| 90 |
+
render_results(st.session_state.results)
|
| 91 |
+
|
| 92 |
+
# Render footer
|
| 93 |
+
render_footer()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
main()
|
|
|
|
|
|
|
|
|