File size: 4,913 Bytes
6145bc0 64f8a92 84b93bb 64f8a92 84b93bb 864b488 84b93bb 864b488 84b93bb 864b488 84b93bb 0a2437f 864b488 64f8a92 84b93bb 0a2437f bea13ba 0a2437f 84b93bb 64f8a92 0a2437f 84b93bb 0a2437f 84b93bb 0a2437f 84b93bb 64f8a92 0a2437f 84b93bb 0a2437f 84b93bb bea13ba 64f8a92 bea13ba 84b93bb 64f8a92 bea13ba 84b93bb 0a2437f 84b93bb 0a2437f 84b93bb bea13ba 84b93bb 64f8a92 0a2437f bea13ba 64f8a92 bea13ba 64f8a92 84b93bb 64f8a92 864b488 |
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 |
import streamlit as st
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1) Initialize DB (imports models under the hood, then create_all)
from models.db import init_db
init_db()
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 2) First-run admin signup (before any queries to the user table)
from repositories.user_repo import UserRepo
from config.settings import settings
repo = UserRepo(settings.database_url)
if not repo.get_all_users():
st.title("π Welcome to Quantum Healthcare AI")
st.warning("No users exist yet. Create the first admin account below:")
new_user = st.text_input("Username")
new_name = st.text_input("Full name")
new_pw = st.text_input("Password", type="password")
if st.button("Create Admin User"):
if new_user and new_name and new_pw:
repo.add_user(new_user, new_name, new_pw)
st.success(f"β
Admin `{new_user}` created! Refresh the page to log in.")
else:
st.error("All fields are required.")
st.stop()
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 3) Authentication
from services.auth import authenticator, require_login
username = require_login()
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 4) Core services & repositories
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
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 5) Logging & metrics
from services.logger import logger
from services.metrics import CHAT_COUNT, OPTIMIZE_COUNT
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 6) UI Layout
st.set_page_config(page_title="Quantum Healthcare AI", layout="wide")
st.image("assets/logo.png", width=64)
st.title(f"Hello, {username}!")
tab1, tab2 = st.tabs(["π©Ί Consult", "π Reports"])
with tab1:
query = st.text_area("Describe your symptoms or ask a clinical question:", height=100)
if st.button("Ask Gemini"):
CHAT_COUNT.inc()
with st.spinner("π€ Consulting Gemini..."):
response = chat_with_gemini(username, query)
logger.info(f"[Chat] user={username} prompt={query!r}")
st.markdown(f"**AI Response:** {response}")
ChatRepo().save(user=username, prompt=query, response=response)
with st.expander("π UMLS Concept Lookup"):
umls_results = lookup_umls(query)
st.write(umls_results or "No concepts found in UMLS.")
with st.expander("π¬ BioPortal Concept Lookup"):
bio_results = lookup_bioportal(query)
st.write(bio_results or "No matches found in BioPortal.")
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")
|