File size: 2,388 Bytes
6145bc0 64f8a92 bea13ba 64f8a92 bea13ba 0a2437f 64f8a92 bea13ba 0a2437f bea13ba 0a2437f bea13ba 64f8a92 0a2437f bea13ba 0a2437f bea13ba 64f8a92 0a2437f bea13ba 64f8a92 bea13ba 64f8a92 bea13ba 0a2437f bea13ba 0a2437f bea13ba 64f8a92 0a2437f bea13ba 64f8a92 bea13ba 64f8a92 bea13ba |
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 |
import streamlit as st
# 1) Ensure DB tables exist
from models.db import init_db
init_db()
# 2) Auth
from services.auth import authenticator, require_login
# 3) Core AI + Clinical NLP + Quantum
from agent.gemini_agent import chat_with_gemini
from clinical_nlp.umls_bioportal import lookup_umls, lookup_bioportal
from quantum.optimizer import optimize_treatment
from repositories.chat_repo import ChatRepo
# 4) Monitoring & Logging
from services.logger import logger
from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
# βββ UI βββ
username = require_login()
st.set_page_config(page_title="Quantum Health AI", layout="wide")
st.image("assets/logo.png", width=64)
st.title(f"Welcome, {username}!")
tab1, tab2 = st.tabs(["π©Ί Consult", "π Reports"])
with tab1:
query = st.text_area("Describe symptoms or enter a medical question:", height=100)
if st.button("Ask Gemini"):
CHAT_COUNT.inc()
with st.spinner("Consulting AI..."):
response = chat_with_gemini(username, query)
logger.info(f"[Chat] user={username} prompt={query}")
st.markdown(f"**AI Response:** {response}")
ChatRepo().save(user=username, prompt=query, response=response)
with st.expander("π UMLS Concept Lookup"):
umls_res = lookup_umls(query)
st.write(umls_res or "No UMLS concepts found.")
with st.expander("π¬ BioPortal Concept Lookup"):
bio_res = lookup_bioportal(query)
st.write(bio_res or "No BioPortal matches found.")
if st.button("Quantum Optimize Care Plan"):
OPTIMIZE_COUNT.inc()
with st.spinner("Running quantum-inspired optimizer..."):
plan = optimize_treatment(query)
logger.info(f"[Optimize] user={username} plan={plan}")
st.markdown("### 𧬠Optimized Treatment Plan")
st.json(plan)
with tab2:
st.header("Generate PDF Report of Recent Chats")
if st.button("Download Last 5 Chats"):
recent = ChatRepo().get_recent(user=username, limit=5)
from services.pdf_report import generate_pdf
pdf_path = generate_pdf({"Recent Chats": recent})
with open(pdf_path, "rb") as f:
st.download_button("Download PDF", f, file_name=pdf_path)
st.markdown("---")
st.caption("Powered by Gemini LLM β’ UMLS/BioPortal β’ Quantum-inspired optimization")
|