""" app.py ------ This is the main Streamlit application. It provides a clinician-friendly interface to input a clinical query, displays the generated answer, and visualizes key clinical concepts via an interactive knowledge graph. """ import subprocess import sys import os # Force reinstall pydantic v1 to ensure compatibility with Chromadb. subprocess.run([sys.executable, "-m", "pip", "install", "--force-reinstall", "pydantic==1.10.7"]) # Set the Hugging Face Hub timeout. os.environ["HF_HUB_TIMEOUT"] = "60" import streamlit as st import streamlit.components.v1 as components from backend import process_medical_query, docs_cache from visualization import create_medical_graph def main(): st.set_page_config(page_title="AI-Powered Medical Knowledge Graph Assistant", layout="wide") st.title("AI-Powered Medical Knowledge Graph Assistant") st.markdown( """ **Using BioGPT-Large-PubMedQA + PubMed + Chroma** for advanced retrieval-augmented generation. Enter your clinical query below to retrieve and synthesize relevant medical literature. """ ) user_query = st.text_input("Enter biomedical/medical query", "Malaria and cough treatment") if st.button("Submit"): with st.spinner("Generating answer..."): final_answer, sub_questions, initial_answer, critique = process_medical_query(user_query) st.subheader("AI Answer") st.write(final_answer) st.subheader("Knowledge Graph") docs = docs_cache.get(user_query, []) if docs: graph_html = create_medical_graph(user_query, docs) components.html(graph_html, height=600, scrolling=True) else: st.info("No documents to visualize.") if __name__ == "__main__": main()