mgbam commited on
Commit
bea13ba
Β·
verified Β·
1 Parent(s): 64f8a92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -27
app.py CHANGED
@@ -1,23 +1,23 @@
1
  import streamlit as st
2
 
3
- # 1) Initialize DB tables before anything else
4
  from models.db import init_db
5
  init_db()
6
 
7
- # 2) Authentication (after DB is ready)
8
  from services.auth import authenticator, require_login
9
 
10
- # 3) Core services & repos
11
  from agent.gemini_agent import chat_with_gemini
12
  from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal
13
- from quantum.bf_dcqo import optimize_hubo
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 Setup ===
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("Enter clinical query or symptoms:", 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"User={username} Prompt={query}")
36
- st.markdown(f"**AI:** {response}")
37
  ChatRepo().save(user=username, prompt=query, response=response)
38
 
39
- with st.expander("πŸ”Ž UMLS Lookup"):
40
- umls_results = lookup_umls(query)
41
- st.write(umls_results or "No UMLS concepts found.")
42
 
43
- with st.expander("πŸ”¬ BioPortal Lookup"):
44
- bio_results = lookup_bioportal(query)
45
- st.write(bio_results or "No BioPortal concepts found.")
46
 
47
- if st.button("Quantum Optimize"):
48
  OPTIMIZE_COUNT.inc()
49
- with st.spinner("Running quantum optimizer..."):
50
- plan = optimize_hubo({"query": query})
51
- logger.info(f"Quantum plan for {username}: {plan}")
52
- st.markdown("### 🧬 Optimized Care Plan")
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
- pdf_file = generate_pdf(report_data)
63
- with open(pdf_file, "rb") as f:
64
- st.download_button("Download Report", f, file_name=pdf_file)
65
 
66
  st.markdown("---")
67
- st.caption("Powered by Gemini LLM, UMLS, BioPortal & quantum-inspired optimization. For research use only.")
 
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")