mgbam commited on
Commit
d2b44d5
·
verified ·
1 Parent(s): 140d9d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -34
app.py CHANGED
@@ -1,66 +1,128 @@
1
  # app.py
2
  """
3
  The main Gradio user interface for Project Asclepius.
4
- This file defines the layout and connects UI components to the backend logic.
 
 
5
  """
6
  import gradio as gr
 
 
 
7
  from modules import orchestrator
8
 
9
- # --- UI Layout and Components ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # Load custom CSS for a polished look
12
- with open("static/style.css", "r", encoding="utf-8") as f:
13
- custom_css = f.read()
14
 
15
- # Define the main application blocks
16
- with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
17
- # Header
18
- with gr.Row():
19
- # You can add your own logo.png to the static folder
20
- # gr.Image("static/logo.png", width=100, show_label=False, show_download_button=False)
21
- gr.Markdown("# 🧠 Project Asclepius: The Cognitive Medical Nexus")
22
 
23
- gr.Markdown("An AI-powered system that synthesizes public medical data to provide clear, evidence-based information. **This is not a diagnostic tool.**")
 
 
24
 
25
  # Define the main tabs for different functionalities
26
  with gr.Tabs():
27
- # --- TAB 1: Symptom Synthesizer ---
28
- with gr.TabItem("Symptom Synthesizer"):
 
 
 
29
  with gr.Row():
30
  with gr.Column(scale=2):
31
  symptom_input = gr.Textbox(
32
  lines=5,
33
  label="Describe Symptoms or Ask a Medical Question",
34
- placeholder="e.g., 'I have a sharp pain in my chest and feel dizzy' or 'What are the latest treatments for migraines?'"
 
 
 
 
 
35
  )
36
- # Optional image input can be added here
37
- # image_input = gr.Image(type="pil", label="Upload a relevant image (e.g., skin rash)", optional=True)
38
-
39
  with gr.Column(scale=1):
40
- submit_btn = gr.Button("Synthesize Information", variant="primary")
 
 
 
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  gr.Markdown("---")
43
- synthesis_output = gr.Markdown(label="Synthesized Report")
44
 
45
- # --- TAB 2: Research Deep Dive (Placeholder) ---
46
- with gr.TabItem("Research Deep Dive"):
47
- gr.Markdown("## Feature Coming Soon\nThis section will allow you to do a deep dive on a specific disease, gene, or drug, pulling in comprehensive research data.")
48
- # Add inputs and outputs for this tab here
 
 
 
 
 
 
 
 
49
 
50
- # --- TAB 3: Drug Interaction Analyzer (Placeholder) ---
51
- with gr.TabItem("Drug Interaction Analyzer"):
52
- gr.Markdown("## Feature Coming Soon\nThis tool will analyze potential interactions and safety concerns for a list of medications.")
53
- # Add inputs and outputs for this tab here
54
 
55
- # --- Event Handlers ---
56
- submit_btn.click(
 
 
 
 
 
 
 
 
 
57
  fn=orchestrator.run_symptom_synthesis,
58
- inputs=[symptom_input], # Add image_input here if using
59
  outputs=[synthesis_output],
60
  api_name="symptom_synthesis",
61
- show_progress="full" # Provides a great user experience
 
 
 
 
 
 
 
 
 
 
62
  )
63
 
64
- # Launch the application
65
  if __name__ == "__main__":
 
66
  demo.launch(debug=True)
 
1
  # app.py
2
  """
3
  The main Gradio user interface for Project Asclepius.
4
+ This file defines the complete, multi-tab layout and connects the UI components
5
+ to the powerful asynchronous backend logic in the orchestrator. It is designed
6
+ for a clean, professional, and responsive user experience.
7
  """
8
  import gradio as gr
9
+ from PIL import Image
10
+
11
+ # Import the master orchestrator which contains all our application logic
12
  from modules import orchestrator
13
 
14
+ # --- UI Configuration and Styling ---
15
+
16
+ # Load custom CSS for a polished, professional look
17
+ try:
18
+ with open("static/style.css", "r", encoding="utf-8") as f:
19
+ custom_css = f.read()
20
+ except FileNotFoundError:
21
+ print("Warning: style.css not found. Using default Gradio styles.")
22
+ custom_css = ""
23
+
24
+ # Block Title and Header
25
+ APP_TITLE = "🧠 Project Asclepius: The Cognitive Medical Nexus"
26
+ APP_DESCRIPTION = (
27
+ "Welcome. This is an AI-powered system that synthesizes public medical data from trusted sources "
28
+ "(like the National Library of Medicine) to provide clear, evidence-based information. "
29
+ "**This application does not provide medical advice, diagnosis, or treatment.**"
30
+ )
31
 
32
+ # --- Gradio Application Layout ---
 
 
33
 
34
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), css=custom_css, title="Project Asclepius") as demo:
 
 
 
 
 
 
35
 
36
+ # Main Header
37
+ gr.Markdown(f"# {APP_TITLE}")
38
+ gr.Markdown(APP_DESCRIPTION)
39
 
40
  # Define the main tabs for different functionalities
41
  with gr.Tabs():
42
+
43
+ # =====================================================================
44
+ # TAB 1: Symptom & Condition Synthesizer
45
+ # =====================================================================
46
+ with gr.TabItem("Symptom & Condition Synthesizer"):
47
  with gr.Row():
48
  with gr.Column(scale=2):
49
  symptom_input = gr.Textbox(
50
  lines=5,
51
  label="Describe Symptoms or Ask a Medical Question",
52
+ 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?'"
53
+ )
54
+ image_input = gr.Image(
55
+ type="pil",
56
+ label="Optional: Upload a Relevant Image",
57
+ info="For visual symptoms like a skin rash or swelling. The AI will describe what it sees objectively."
58
  )
 
 
 
59
  with gr.Column(scale=1):
60
+ synthesis_submit_btn = gr.Button("Synthesize Information", variant="primary", scale=1)
61
+
62
+ gr.Markdown("---")
63
+ synthesis_output = gr.Markdown(label="Synthesized Report", value="Your synthesized report will appear here...")
64
 
65
+ # =====================================================================
66
+ # TAB 2: Drug Interaction & Safety Analyzer
67
+ # =====================================================================
68
+ with gr.TabItem("Drug Interaction & Safety Analyzer"):
69
+ with gr.Row():
70
+ with gr.Column(scale=2):
71
+ drug_input = gr.Textbox(
72
+ lines=5,
73
+ label="Enter a List of Medications (separated by commas)",
74
+ placeholder="e.g., lisinopril, metformin, atorvastatin, aspirin, ozempic"
75
+ )
76
+ with gr.Column(scale=1):
77
+ interaction_submit_btn = gr.Button("Analyze Drug Safety", variant="primary", scale=1)
78
+
79
  gr.Markdown("---")
80
+ interaction_output = gr.Markdown(label="Drug Safety Report", value="Your drug safety and interaction report will appear here...")
81
 
82
+ # =====================================================================
83
+ # TAB 3: About & Disclaimer
84
+ # =====================================================================
85
+ with gr.TabItem("About & Disclaimer"):
86
+ gr.Markdown(
87
+ """
88
+ ## About Project Asclepius
89
+ 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:
90
+ - **PubMed:** For biomedical literature and research abstracts.
91
+ - **ClinicalTrials.gov:** For information on active clinical studies.
92
+ - **OpenFDA:** For drug adverse event reports and recalls.
93
+ - **RxNorm:** For standardizing drug names and checking for interactions.
94
 
95
+ This tool is for informational and educational purposes only.
 
 
 
96
 
97
+ ## **⚠️ Full Disclaimer**
98
+ **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.
99
+
100
+ **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.
101
+ """
102
+ )
103
+
104
+ # --- Wire the UI Components to the Backend Orchestrator ---
105
+
106
+ # Handler for the Symptom Synthesizer tab
107
+ synthesis_submit_btn.click(
108
  fn=orchestrator.run_symptom_synthesis,
109
+ inputs=[symptom_input, image_input],
110
  outputs=[synthesis_output],
111
  api_name="symptom_synthesis",
112
+ # Provide excellent user feedback during the async process
113
+ show_progress="full"
114
+ )
115
+
116
+ # Handler for the Drug Interaction Analyzer tab
117
+ interaction_submit_btn.click(
118
+ fn=orchestrator.run_drug_interaction_analysis,
119
+ inputs=[drug_input],
120
+ outputs=[interaction_output],
121
+ api_name="drug_interaction_analysis",
122
+ show_progress="full"
123
  )
124
 
125
+ # --- Launch the Application ---
126
  if __name__ == "__main__":
127
+ # The `share=True` argument can be used to create a public link if running locally
128
  demo.launch(debug=True)