Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
# 1)
|
4 |
from models.db import init_db
|
5 |
init_db()
|
6 |
|
7 |
-
# 2)
|
8 |
from services.auth import authenticator, require_login
|
9 |
|
10 |
-
# 3) Core
|
11 |
from agent.gemini_agent import chat_with_gemini
|
12 |
from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal
|
13 |
-
from quantum.
|
14 |
from repositories.chat_repo import ChatRepo
|
15 |
|
16 |
-
# 4) Monitoring &
|
17 |
from services.logger import logger
|
18 |
from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
|
19 |
|
20 |
-
#
|
21 |
username = require_login()
|
22 |
st.set_page_config(page_title="Quantum Health AI", layout="wide")
|
23 |
st.image("assets/logo.png", width=64)
|
@@ -26,42 +26,40 @@ st.title(f"Welcome, {username}!")
|
|
26 |
tab1, tab2 = st.tabs(["π©Ί Consult", "π Reports"])
|
27 |
|
28 |
with tab1:
|
29 |
-
query = st.text_area("
|
30 |
|
31 |
if st.button("Ask Gemini"):
|
32 |
CHAT_COUNT.inc()
|
33 |
with st.spinner("Consulting AI..."):
|
34 |
response = chat_with_gemini(username, query)
|
35 |
-
logger.info(f"
|
36 |
-
st.markdown(f"**AI:** {response}")
|
37 |
ChatRepo().save(user=username, prompt=query, response=response)
|
38 |
|
39 |
-
with st.expander("π UMLS Lookup"):
|
40 |
-
|
41 |
-
st.write(
|
42 |
|
43 |
-
with st.expander("π¬ BioPortal Lookup"):
|
44 |
-
|
45 |
-
st.write(
|
46 |
|
47 |
-
if st.button("Quantum Optimize"):
|
48 |
OPTIMIZE_COUNT.inc()
|
49 |
-
with st.spinner("Running quantum optimizer..."):
|
50 |
-
plan =
|
51 |
-
logger.info(f"
|
52 |
-
st.markdown("### 𧬠Optimized
|
53 |
st.json(plan)
|
54 |
|
55 |
with tab2:
|
56 |
-
st.header("Generate PDF Report")
|
57 |
if st.button("Download Last 5 Chats"):
|
58 |
-
# Fetch last 5 messages for this user
|
59 |
recent = ChatRepo().get_recent(user=username, limit=5)
|
60 |
-
report_data = {"Recent Chats": recent}
|
61 |
from services.pdf_report import generate_pdf
|
62 |
-
|
63 |
-
with open(
|
64 |
-
st.download_button("Download
|
65 |
|
66 |
st.markdown("---")
|
67 |
-
st.caption("Powered by Gemini LLM
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
# 1) Ensure DB tables exist
|
4 |
from models.db import init_db
|
5 |
init_db()
|
6 |
|
7 |
+
# 2) Auth
|
8 |
from services.auth import authenticator, require_login
|
9 |
|
10 |
+
# 3) Core AI + Clinical NLP + Quantum
|
11 |
from agent.gemini_agent import chat_with_gemini
|
12 |
from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal
|
13 |
+
from quantum.optimizer import optimize_treatment
|
14 |
from repositories.chat_repo import ChatRepo
|
15 |
|
16 |
+
# 4) Monitoring & Logging
|
17 |
from services.logger import logger
|
18 |
from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
|
19 |
|
20 |
+
# βββ UI βββ
|
21 |
username = require_login()
|
22 |
st.set_page_config(page_title="Quantum Health AI", layout="wide")
|
23 |
st.image("assets/logo.png", width=64)
|
|
|
26 |
tab1, tab2 = st.tabs(["π©Ί Consult", "π Reports"])
|
27 |
|
28 |
with tab1:
|
29 |
+
query = st.text_area("Describe symptoms or enter a medical question:", height=100)
|
30 |
|
31 |
if st.button("Ask Gemini"):
|
32 |
CHAT_COUNT.inc()
|
33 |
with st.spinner("Consulting AI..."):
|
34 |
response = chat_with_gemini(username, query)
|
35 |
+
logger.info(f"[Chat] user={username} prompt={query}")
|
36 |
+
st.markdown(f"**AI Response:** {response}")
|
37 |
ChatRepo().save(user=username, prompt=query, response=response)
|
38 |
|
39 |
+
with st.expander("π UMLS Concept Lookup"):
|
40 |
+
umls_res = lookup_umls(query)
|
41 |
+
st.write(umls_res or "No UMLS concepts found.")
|
42 |
|
43 |
+
with st.expander("π¬ BioPortal Concept Lookup"):
|
44 |
+
bio_res = lookup_bioportal(query)
|
45 |
+
st.write(bio_res or "No BioPortal matches found.")
|
46 |
|
47 |
+
if st.button("Quantum Optimize Care Plan"):
|
48 |
OPTIMIZE_COUNT.inc()
|
49 |
+
with st.spinner("Running quantum-inspired optimizer..."):
|
50 |
+
plan = optimize_treatment(query)
|
51 |
+
logger.info(f"[Optimize] user={username} plan={plan}")
|
52 |
+
st.markdown("### 𧬠Optimized Treatment Plan")
|
53 |
st.json(plan)
|
54 |
|
55 |
with tab2:
|
56 |
+
st.header("Generate PDF Report of Recent Chats")
|
57 |
if st.button("Download Last 5 Chats"):
|
|
|
58 |
recent = ChatRepo().get_recent(user=username, limit=5)
|
|
|
59 |
from services.pdf_report import generate_pdf
|
60 |
+
pdf_path = generate_pdf({"Recent Chats": recent})
|
61 |
+
with open(pdf_path, "rb") as f:
|
62 |
+
st.download_button("Download PDF", f, file_name=pdf_path)
|
63 |
|
64 |
st.markdown("---")
|
65 |
+
st.caption("Powered by Gemini LLM β’ UMLS/BioPortal β’ Quantum-inspired optimization")
|