Spaces:
Running
Running
| import os, json, requests, streamlit as st | |
| from backend.rag_engine import get_embedder,get_chroma,retrieve,seed_index | |
| from backend.soap_generator import compose_soap | |
| from utils.constants import DOCS_DIR,CHAT_ENDPOINT | |
| st.set_page_config(page_title='MediAssist v13',page_icon='🩺',layout='wide') | |
| def emb():return get_embedder() | |
| def col():return get_chroma()[1] | |
| def chat(prompt): | |
| token=os.getenv('HF_API_TOKEN') | |
| if not token:return 'Missing HF_API_TOKEN' | |
| r=requests.post(CHAT_ENDPOINT,headers={"Authorization":f"Bearer {token}"},json={"inputs":prompt},timeout=200) | |
| d=r.json() | |
| if isinstance(d,list) and "generated_text" in d[0]: | |
| return d[0]["generated_text"] | |
| return str(d) | |
| st.title("🩺 MediAssist v13 — AI Gynae Assistant") | |
| with st.sidebar: | |
| if st.button("Seed Index"): | |
| n=seed_index(col(),emb(),DOCS_DIR);st.success(f"Indexed {n} chunks") | |
| txt=st.text_area("Patient narrative") | |
| if st.button("Generate Report"): | |
| items=retrieve(col(),emb(),txt,5) | |
| soap=compose_soap(txt,items) | |
| ctx="\n".join([i["text"] for i in items]) | |
| prompt=f"Use this context to create a refined clinical report:\n{ctx}\nPatient: {txt}" | |
| reply=chat(prompt) | |
| st.subheader("AI Draft Report");st.write(reply) | |
| st.subheader("SOAP");st.json(soap) | |