Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
135 lines (114 loc) Β· 4.47 KB
/
Copy pathapp.py
File metadata and controls
135 lines (114 loc) Β· 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# streamlit_demo.py
import streamlit as st
import requests
import base64
from datetime import datetime
# ========================
# CONFIGURATION
# ========================
st.set_page_config(
page_title="MedConnect AI - Remote Medical Assistant",
page_icon="π₯",
layout="centered"
)
st.title("π₯ MedConnect AI")
st.markdown("*Your intelligent medical assistant β connecting you to the right doctor, in your language.*")
API_URL = "https://medconnect-ai-4fnj.onrender.com/conversation"
RESET_URL = "https://medconnect-ai-4fnj.onrender.com/reset"
# Supported languages
LANGUAGES = {
"English": "english",
"Hausa": "hausa",
"Yoruba": "yoruba",
"Igbo": "igbo"
}
# ========================
# SESSION STATE
# ========================
if "messages" not in st.session_state:
st.session_state.messages = []
if "conversation_active" not in st.session_state:
st.session_state.conversation_active = True
# ========================
# SIDEBAR CONTROLS
# ========================
with st.sidebar:
st.header("βοΈ Settings")
selected_lang_name = st.selectbox("Language", options=list(LANGUAGES.keys()), index=0)
language = LANGUAGES[selected_lang_name]
premium = st.toggle("Premium User", value=False)
st.markdown("---")
if st.button("ποΈ New Conversation"):
requests.post(RESET_URL)
st.session_state.messages = []
st.success("Conversation reset!")
st.rerun()
st.markdown("---")
st.caption("MedConnect AI V3 β’ LangGraph Multi-Agent System")
# ========================
# CHAT INTERFACE
# ========================
# Display chat messages
for message in st.session_state.messages:
if message["role"] == "user":
with st.chat_message("user"):
st.markdown(message["content"])
else:
with st.chat_message("assistant"):
st.markdown(message["content"])
# Show doctor match if available
if message.get("doctorid"):
st.success(f"β
Connected to Doctor ID: **{message['doctorid']}**")
if message.get("medical_summary"):
with st.expander("π View Medical Summary (SOAP Note)"):
st.text(message["medical_summary"])
# User input
if prompt := st.chat_input("Describe your symptoms or ask a medical question..."):
# Append user message
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
# Prepare payload
payload = {
"message": prompt,
"audio": "", # No audio in Streamlit demo
"premium": premium,
"language": language
}
# Show thinking spinner
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
try:
response = requests.post(API_URL, json=payload)
if response.status_code == 200:
data = response.json()
agent_message = data.get("message", "Sorry, I didn't understand that.")
doctorid = data.get("doctorid", "")
medical_summary = data.get("medical_summary", "")
st.markdown(agent_message)
# Store assistant message
msg_data = {
"role": "assistant",
"content": agent_message,
"doctorid": doctorid,
"medical_summary": medical_summary
}
st.session_state.messages.append(msg_data)
# Highlight doctor match
if doctorid:
st.success(f"β
You have been matched with Doctor ID: **{doctorid}**")
st.balloons()
if medical_summary:
with st.expander("π View Generated SOAP Note"):
st.text(medical_summary)
else:
st.error(f"Error: {response.status_code} - {response.text}")
except requests.exceptions.ConnectionError:
st.error("π¨ Cannot connect to the agent server. Make sure `uvicorn main:app --reload` is running.")
except Exception as e:
st.error(f"Unexpected error: {e}")
# ========================
# FOOTER
# ========================
st.markdown("---")
st.caption("Powered by Gemini Flash β’ Fine-tuned MedConnectAI β’ LangGraph β’ Built for African Healthcare π")