mgbam commited on
Commit
0a2437f
Β·
verified Β·
1 Parent(s): b8c0463

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -59
app.py CHANGED
@@ -1,60 +1,50 @@
1
  import streamlit as st
2
- from agent.gemini_agent import run_gemini_chat
3
- from agent.clinical_nlp import umls_concept_lookup, bioportal_concept_lookup
4
- from quantum.optimizer import optimize_treatment
5
-
6
- st.set_page_config(page_title="Quantum Healthcare AI", layout="wide")
7
-
8
- st.markdown("""
9
- <div style='display:flex;align-items:center'>
10
- <img src='https://cdn-icons-png.flaticon.com/512/891/891419.png' width='56' style='margin-right:15px;'/>
11
- <h1 style='display:inline'>Quantum-AI Healthcare Assistant</h1>
12
- </div>
13
- """, unsafe_allow_html=True)
14
-
15
- st.write("**Ask anything about symptoms, conditions, diagnosis, or optimal care. Get instant LLM answers, clinical concept mapping, and even quantum-inspired optimization.**")
16
-
17
- query = st.text_area("Describe symptoms, a clinical problem, or a medical question:", height=70)
18
-
19
- cols = st.columns([1,1])
20
- with cols[0]:
21
- get_ai = st.button("Get AI & Clinical Insight")
22
- with cols[1]:
23
- run_quantum = st.button("Quantum Optimize Care Plan")
24
-
25
- if get_ai and query.strip():
26
- with st.spinner("Gemini AI is reviewing your query..."):
27
- ai_response = run_gemini_chat(query)
28
- st.markdown(f"**Gemini Agent:**\n\n{ai_response}")
29
-
30
- st.markdown("---")
31
- with st.expander("πŸ”Ž UMLS Concept Mapping"):
32
- concepts = umls_concept_lookup(query)
33
- if concepts:
34
- for c in concepts:
35
- if 'error' in c:
36
- st.error(c['error'])
37
- else:
38
- st.write(f"**{c['name']}** | ID: `{c['ui']}` | Source: *{c['rootSource']}*")
39
- else:
40
- st.info("No UMLS concepts found.")
41
-
42
- with st.expander("πŸ”¬ BioPortal Ontology Lookup"):
43
- concepts = bioportal_concept_lookup(query)
44
- if concepts:
45
- for c in concepts:
46
- if 'error' in c:
47
- st.error(c['error'])
48
- else:
49
- st.write(f"**{c['prefLabel']}** | [Ontology]({c['ontology']}) | [Concept ID]({c['id']})")
50
- else:
51
- st.info("No BioPortal concepts found.")
52
-
53
- if run_quantum and query.strip():
54
- with st.spinner("Quantum optimizer working..."):
55
- plan = optimize_treatment(query)
56
- st.markdown("### 🧬 Optimized Care Plan")
57
- st.json(plan)
58
-
59
- st.markdown("---")
60
- st.caption("Powered by Gemini LLM, UMLS, BioPortal, and quantum-inspired algorithms. For research use only. No patient data is stored.")
 
1
  import streamlit as st
2
+ from services.auth import authenticator, require_login
3
+ from services.logger import logger
4
+ from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
5
+ from agent.gemini_agent import chat_with_gemini
6
+ from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal
7
+ from quantum.bf_dcqo import optimize_hubo
8
+ from services.pdf_report import generate_pdf
9
+ from repositories.chat_repo import ChatRepo
10
+
11
+ # Initialize DB
12
+ from models.db import init_db
13
+ init_db()
14
+
15
+ # UI
16
+ username = require_login()
17
+ st.set_page_config(page_title="Quantum Health AI", layout="wide")
18
+ st.image("assets/logo.png", width=64)
19
+ st.title(f"Welcome, {username}!")
20
+
21
+ tab1, tab2 = st.tabs(["🩺 Consult", "πŸ“Š Reports"])
22
+
23
+ with tab1:
24
+ query = st.text_area("Enter clinical query or symptoms:")
25
+ if st.button("Ask Gemini"):
26
+ CHAT_COUNT.inc()
27
+ with st.spinner("Consulting AI..."):
28
+ response = chat_with_gemini(username, query)
29
+ st.markdown(f"**AI**: {response}")
30
+ # save chat
31
+ ChatRepo().save(username, query, response)
32
+ # clinical NLP
33
+ with st.expander("UMLS Results"):
34
+ st.write(lookup_umls(query))
35
+ with st.expander("BioPortal Results"):
36
+ st.write(lookup_bioportal(query))
37
+
38
+ if st.button("Quantum Optimize"):
39
+ OPTIMIZE_COUNT.inc()
40
+ with st.spinner("Running quantum optimizer..."):
41
+ result = optimize_hubo({"query":query})
42
+ st.json(result)
43
+
44
+ with tab2:
45
+ if st.button("Generate PDF Report"):
46
+ # gather last 5 messages
47
+ pdf_data = {"Last Chats": ChatRepo().get_recent(username, limit=5)}
48
+ fname = generate_pdf(pdf_data)
49
+ st.success("Report Generated")
50
+ st.download_button("Download Report", data=open(fname,"rb"), file_name=fname)