Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import pdfplumber
|
4 |
-
from transformers import
|
5 |
import timm
|
6 |
-
import torch
|
7 |
-
import pandas as pd
|
8 |
|
9 |
# Load pre-trained zero-shot model for text classification
|
10 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
@@ -27,18 +25,27 @@ disease_details = {
|
|
27 |
"diabetes": {"medication": "Metformin or insulin", "precaution": "Monitor sugar levels", "doctor": "Endocrinologist"},
|
28 |
}
|
29 |
|
30 |
-
#
|
31 |
-
doctor_password = "doctor123"
|
32 |
-
|
33 |
-
# Load PastelMedAW model
|
34 |
pastel_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/PastelMedAW")
|
35 |
pastel_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/PastelMedAW")
|
36 |
-
|
37 |
-
# Load LynxMedAW model
|
38 |
lynx_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/LynxMedAW")
|
39 |
lynx_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/LynxMedAW")
|
40 |
|
41 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
def register_patient(name, age, gender, password):
|
43 |
patient_id = len(patients_db) + 1
|
44 |
patients_db.append({
|
@@ -121,113 +128,33 @@ def doctor_dashboard(password):
|
|
121 |
f"π©ββοΈ Recommended Doctor: {patient['Doctor']}")
|
122 |
return "\n\n".join(details)
|
123 |
|
124 |
-
def doctor_consultant(prompt):
|
125 |
-
# Generate response from PastelMedAW
|
126 |
-
pastel_input = pastel_tokenizer(prompt, return_tensors="pt")
|
127 |
-
pastel_output = pastel_model.generate(**pastel_input, max_length=200, num_return_sequences=1)
|
128 |
-
pastel_response = pastel_tokenizer.decode(pastel_output[0], skip_special_tokens=True)
|
129 |
-
|
130 |
-
# Generate response from LynxMedAW
|
131 |
-
lynx_input = lynx_tokenizer(prompt, return_tensors="pt")
|
132 |
-
lynx_output = lynx_model.generate(**lynx_input, max_length=200, num_return_sequences=1)
|
133 |
-
lynx_response = lynx_tokenizer.decode(lynx_output[0], skip_special_tokens=True)
|
134 |
-
|
135 |
-
# Combine responses
|
136 |
-
combined_response = (
|
137 |
-
f"π©Ί **PastelMed Response:**\n{pastel_response}\n\n"
|
138 |
-
f"π©Ί **LynxMed Response:**\n{lynx_response}"
|
139 |
-
)
|
140 |
-
return combined_response
|
141 |
-
|
142 |
# Gradio Interfaces
|
143 |
registration_interface = gr.Interface(
|
144 |
fn=register_patient,
|
145 |
-
inputs=[gr.Textbox(label="Patient Name"),
|
146 |
-
gr.Number(label="Age"),
|
147 |
-
gr.Radio(label="Gender", choices=["Male", "Female", "Other"]),
|
148 |
-
gr.Textbox(label="Set Password", type="password")],
|
149 |
-
outputs="text",
|
150 |
-
)
|
151 |
-
|
152 |
-
pdf_extraction_interface = gr.Interface(
|
153 |
-
fn=extract_pdf_report,
|
154 |
-
inputs=gr.File(label="Upload PDF Report"),
|
155 |
outputs="text",
|
156 |
)
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
)
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
inputs=gr.Image(label="Upload an Eye Image", type="numpy"),
|
167 |
-
outputs="text",
|
168 |
-
)
|
169 |
-
|
170 |
-
doctor_space_interface = gr.Interface(
|
171 |
-
fn=doctor_space,
|
172 |
-
inputs=gr.Number(label="Patient ID"),
|
173 |
-
outputs="text",
|
174 |
-
)
|
175 |
-
|
176 |
-
pharmacist_space_interface = gr.Interface(
|
177 |
-
fn=pharmacist_space,
|
178 |
-
inputs=gr.Number(label="Patient ID"),
|
179 |
-
outputs="text",
|
180 |
-
)
|
181 |
-
|
182 |
-
patient_dashboard_interface = gr.Interface(
|
183 |
-
fn=patient_dashboard,
|
184 |
-
inputs=[gr.Number(label="Patient ID"), gr.Textbox(label="Password", type="password")],
|
185 |
-
outputs="text",
|
186 |
-
)
|
187 |
-
|
188 |
-
doctor_dashboard_interface = gr.Interface(
|
189 |
-
fn=doctor_dashboard,
|
190 |
-
inputs=gr.Textbox(label="Doctor Password", type="password"),
|
191 |
-
outputs="text",
|
192 |
-
)
|
193 |
-
|
194 |
-
doctor_consultant_interface = gr.Interface(
|
195 |
-
fn=doctor_consultant,
|
196 |
-
inputs=gr.Textbox(lines=5, label="Enter Symptoms or Query"),
|
197 |
-
outputs="text",
|
198 |
-
title="Doctor Consultant Assistant",
|
199 |
-
description="Get medical advice or suggestions using two advanced AI models: PastelMedAW and LynxMedAW.",
|
200 |
-
)
|
201 |
|
202 |
# Gradio App Layout
|
203 |
with gr.Blocks() as app:
|
204 |
gr.Markdown("# Medico GPT")
|
205 |
-
|
206 |
-
with gr.Tab("
|
207 |
-
|
208 |
-
|
209 |
-
with gr.Tab("
|
210 |
-
|
211 |
-
|
212 |
-
with gr.Tab("
|
213 |
-
|
214 |
-
|
215 |
-
with gr.Tab("Ophthalmologist Space"):
|
216 |
-
eye_disease_interface.render()
|
217 |
-
|
218 |
-
with gr.Tab("Doctor Space"):
|
219 |
-
doctor_space_interface.render()
|
220 |
-
|
221 |
-
with gr.Tab("Pharmacist Space"):
|
222 |
-
pharmacist_space_interface.render()
|
223 |
-
|
224 |
-
with gr.Tab("Patient Dashboard"):
|
225 |
-
patient_dashboard_interface.render()
|
226 |
-
|
227 |
-
with gr.Tab("Doctor Dashboard"):
|
228 |
-
doctor_dashboard_interface.render()
|
229 |
-
|
230 |
-
with gr.Tab("Doctor Consultant/Assistant"):
|
231 |
-
doctor_consultant_interface.render()
|
232 |
|
233 |
app.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import pdfplumber
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
5 |
import timm
|
|
|
|
|
6 |
|
7 |
# Load pre-trained zero-shot model for text classification
|
8 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
|
|
25 |
"diabetes": {"medication": "Metformin or insulin", "precaution": "Monitor sugar levels", "doctor": "Endocrinologist"},
|
26 |
}
|
27 |
|
28 |
+
# Doctor consultant models
|
|
|
|
|
|
|
29 |
pastel_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/PastelMedAW")
|
30 |
pastel_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/PastelMedAW")
|
|
|
|
|
31 |
lynx_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/LynxMedAW")
|
32 |
lynx_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/LynxMedAW")
|
33 |
|
34 |
+
# Passwords
|
35 |
+
doctor_password = "doctor123"
|
36 |
+
|
37 |
+
# Helper Functions
|
38 |
+
def generate_consultation_response(prompt):
|
39 |
+
pastel_input = pastel_tokenizer(prompt, return_tensors="pt")
|
40 |
+
pastel_response = pastel_model.generate(**pastel_input, max_length=200, num_return_sequences=1)
|
41 |
+
pastel_output = pastel_tokenizer.decode(pastel_response[0], skip_special_tokens=True)
|
42 |
+
|
43 |
+
lynx_input = lynx_tokenizer(prompt, return_tensors="pt")
|
44 |
+
lynx_response = lynx_model.generate(**lynx_input, max_length=200, num_return_sequences=1)
|
45 |
+
lynx_output = lynx_tokenizer.decode(lynx_response[0], skip_special_tokens=True)
|
46 |
+
|
47 |
+
return f"**PastelMedAW Response:**\n{pastel_output}\n\n**LynxMedAW Response:**\n{lynx_output}"
|
48 |
+
|
49 |
def register_patient(name, age, gender, password):
|
50 |
patient_id = len(patients_db) + 1
|
51 |
patients_db.append({
|
|
|
128 |
f"π©ββοΈ Recommended Doctor: {patient['Doctor']}")
|
129 |
return "\n\n".join(details)
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
# Gradio Interfaces
|
132 |
registration_interface = gr.Interface(
|
133 |
fn=register_patient,
|
134 |
+
inputs=[gr.Textbox(label="Patient Name"), gr.Number(label="Age"), gr.Radio(label="Gender", choices=["Male", "Female", "Other"]), gr.Textbox(label="Set Password", type="password")],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
outputs="text",
|
136 |
)
|
137 |
|
138 |
+
pdf_extraction_interface = gr.Interface(fn=extract_pdf_report, inputs=gr.File(label="Upload PDF Report"), outputs="text")
|
139 |
+
report_analysis_interface = gr.Interface(fn=analyze_report, inputs=[gr.Number(label="Patient ID"), gr.Textbox(label="Report Text")], outputs="text")
|
140 |
+
eye_disease_interface = gr.Interface(fn=predict_eye_disease, inputs=gr.Image(label="Upload Eye Image", type="numpy"), outputs="text")
|
141 |
+
doctor_space_interface = gr.Interface(fn=doctor_space, inputs=gr.Number(label="Patient ID"), outputs="text")
|
142 |
+
pharmacist_space_interface = gr.Interface(fn=pharmacist_space, inputs=gr.Number(label="Patient ID"), outputs="text")
|
143 |
+
patient_dashboard_interface = gr.Interface(fn=patient_dashboard, inputs=[gr.Number(label="Patient ID"), gr.Textbox(label="Password", type="password")], outputs="text")
|
144 |
+
doctor_dashboard_interface = gr.Interface(fn=doctor_dashboard, inputs=gr.Textbox(label="Doctor Password", type="password"), outputs="text")
|
145 |
+
doctor_consultant_interface = gr.Interface(fn=generate_consultation_response, inputs=gr.Textbox(label="Enter Symptoms or Query"), outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
# Gradio App Layout
|
148 |
with gr.Blocks() as app:
|
149 |
gr.Markdown("# Medico GPT")
|
150 |
+
with gr.Tab("Patient Registration"): registration_interface.render()
|
151 |
+
with gr.Tab("Analyze Medical Report"): report_analysis_interface.render()
|
152 |
+
with gr.Tab("Extract PDF Report"): pdf_extraction_interface.render()
|
153 |
+
with gr.Tab("Ophthalmologist Space"): eye_disease_interface.render()
|
154 |
+
with gr.Tab("Doctor Space"): doctor_space_interface.render()
|
155 |
+
with gr.Tab("Pharmacist Space"): pharmacist_space_interface.render()
|
156 |
+
with gr.Tab("Patient Dashboard"): patient_dashboard_interface.render()
|
157 |
+
with gr.Tab("Doctor Dashboard"): doctor_dashboard_interface.render()
|
158 |
+
with gr.Tab("Doctor Consultant"): doctor_consultant_interface.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
app.launch(share=True)
|