File size: 6,560 Bytes
4d349c5
 
 
d2b44d5
 
 
4d349c5
 
d2b44d5
 
 
4d349c5
 
d2b44d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d349c5
d2b44d5
4d349c5
d2b44d5
4d349c5
d2b44d5
 
 
4d349c5
 
 
d2b44d5
 
 
 
 
4d349c5
 
 
 
 
d2b44d5
 
 
 
97cc0b3
4d349c5
 
d2b44d5
 
 
 
4d349c5
d2b44d5
 
 
 
 
 
 
 
 
 
 
 
 
 
4d349c5
d2b44d5
4d349c5
d2b44d5
 
 
 
 
 
 
 
 
 
 
 
4d349c5
d2b44d5
4d349c5
d2b44d5
 
 
 
 
 
 
 
 
 
 
4d349c5
d2b44d5
4d349c5
 
d2b44d5
 
 
 
 
 
 
 
 
 
 
4d349c5
 
d2b44d5
4d349c5
f8afaa0
 
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# app.py
"""
The main Gradio user interface for Project Asclepius.
This file defines the complete, multi-tab layout and connects the UI components
to the powerful asynchronous backend logic in the orchestrator. It is designed
for a clean, professional, and responsive user experience.
"""
import gradio as gr
from PIL import Image

# Import the master orchestrator which contains all our application logic
from modules import orchestrator

# --- UI Configuration and Styling ---

# Load custom CSS for a polished, professional look
try:
    with open("static/style.css", "r", encoding="utf-8") as f:
        custom_css = f.read()
except FileNotFoundError:
    print("Warning: style.css not found. Using default Gradio styles.")
    custom_css = ""

# Block Title and Header
APP_TITLE = "🧠 Project Asclepius: The Cognitive Medical Nexus"
APP_DESCRIPTION = (
    "Welcome. This is an AI-powered system that synthesizes public medical data from trusted sources "
    "(like the National Library of Medicine) to provide clear, evidence-based information. "
    "**This application does not provide medical advice, diagnosis, or treatment.**"
)

# --- Gradio Application Layout ---

with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), css=custom_css, title="Project Asclepius") as demo:

    # Main Header
    gr.Markdown(f"# {APP_TITLE}")
    gr.Markdown(APP_DESCRIPTION)

    # Define the main tabs for different functionalities
    with gr.Tabs():

        # =====================================================================
        # TAB 1: Symptom & Condition Synthesizer
        # =====================================================================
        with gr.TabItem("Symptom & Condition Synthesizer"):
            with gr.Row():
                with gr.Column(scale=2):
                    symptom_input = gr.Textbox(
                        lines=5,
                        label="Describe Symptoms or Ask a Medical Question",
                        placeholder="e.g., 'I have a sharp pain behind my right eye and I'm sensitive to light' or 'What are the latest treatments for psoriatic arthritis?'"
                    )
                    image_input = gr.Image(
                        type="pil",
                        label="Optional: Upload a Relevant Image (e.g., skin rash)"
                    )
                with gr.Column(scale=1):
                    synthesis_submit_btn = gr.Button("Synthesize Information", variant="primary", scale=1)

            gr.Markdown("---")
            synthesis_output = gr.Markdown(label="Synthesized Report", value="Your synthesized report will appear here...")

        # =====================================================================
        # TAB 2: Drug Interaction & Safety Analyzer
        # =====================================================================
        with gr.TabItem("Drug Interaction & Safety Analyzer"):
            with gr.Row():
                with gr.Column(scale=2):
                    drug_input = gr.Textbox(
                        lines=5,
                        label="Enter a List of Medications (separated by commas)",
                        placeholder="e.g., lisinopril, metformin, atorvastatin, aspirin, ozempic"
                    )
                with gr.Column(scale=1):
                    interaction_submit_btn = gr.Button("Analyze Drug Safety", variant="primary", scale=1)
            
            gr.Markdown("---")
            interaction_output = gr.Markdown(label="Drug Safety Report", value="Your drug safety and interaction report will appear here...")

        # =====================================================================
        # TAB 3: About & Disclaimer
        # =====================================================================
        with gr.TabItem("About & Disclaimer"):
            gr.Markdown(
                """
                ## About Project Asclepius
                Project Asclepius is a proof-of-concept demonstrating how modern AI can be combined with high-quality, open-source medical APIs to make complex information more accessible. It is built using the Gradio framework, powered by Google's Gemini large language model, and leverages real-time data from:
                - **PubMed:** For biomedical literature and research abstracts.
                - **ClinicalTrials.gov:** For information on active clinical studies.
                - **OpenFDA:** For drug adverse event reports and recalls.
                - **RxNorm:** For standardizing drug names and checking for interactions.

                This tool is for informational and educational purposes only.

                ## **⚠️ Full Disclaimer**
                **This tool is NOT a substitute for professional medical advice, diagnosis, or treatment.** The information provided is generated by an AI model synthesizing publicly available data and may contain inaccuracies, be incomplete, or be misinterpreted. The AI is not a doctor.
                
                **ALWAYS seek the advice of your physician or other qualified health provider** with any questions you may have regarding a medical condition. Never disregard professional medical advice or delay in seeking it because of something you have read on this platform. Reliance on any information provided by this application is solely at your own risk.
                """
            )

    # --- Wire the UI Components to the Backend Orchestrator ---

    # Handler for the Symptom Synthesizer tab
    synthesis_submit_btn.click(
        fn=orchestrator.run_symptom_synthesis,
        inputs=[symptom_input, image_input],
        outputs=[synthesis_output],
        api_name="symptom_synthesis",
        # Provide excellent user feedback during the async process
        show_progress="full"
    )

    # Handler for the Drug Interaction Analyzer tab
    interaction_submit_btn.click(
        fn=orchestrator.run_drug_interaction_analysis,
        inputs=[drug_input],
        outputs=[interaction_output],
        api_name="drug_interaction_analysis",
        show_progress="full"
    )

# --- Launch the Application ---
if __name__ == "__main__":
    # ==============================================================================
    # CORRECTED LINE: We disable the experimental SSR mode for better stability on HF Spaces.
    # We also remove `debug=True` as it's not needed for production deployment.
    demo.launch(ssr_mode=False)
    # ==============================================================================