Spaces:
Sleeping
Sleeping
ahmed-7124
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import pdfplumber
|
4 |
-
from transformers import pipeline
|
5 |
import timm
|
6 |
import torch
|
7 |
import pandas as pd
|
@@ -16,6 +16,10 @@ image_model.eval()
|
|
16 |
# Load saved TensorFlow eye disease detection model
|
17 |
eye_model = tf.keras.models.load_model('model.h5')
|
18 |
|
|
|
|
|
|
|
|
|
19 |
# Patient database
|
20 |
patients_db = []
|
21 |
|
@@ -44,7 +48,7 @@ def register_patient(name, age, gender, password):
|
|
44 |
"Precautions": "",
|
45 |
"Doctor": ""
|
46 |
})
|
47 |
-
return f"
|
48 |
|
49 |
def analyze_report(patient_id, report_text):
|
50 |
candidate_labels = list(disease_details.keys())
|
@@ -58,7 +62,7 @@ def analyze_report(patient_id, report_text):
|
|
58 |
for patient in patients_db:
|
59 |
if patient['ID'] == patient_id:
|
60 |
patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution, Doctor=doctor)
|
61 |
-
return f"
|
62 |
|
63 |
def extract_pdf_report(pdf):
|
64 |
text = ""
|
@@ -80,39 +84,45 @@ def predict_eye_disease(input_image):
|
|
80 |
def doctor_space(patient_id):
|
81 |
for patient in patients_db:
|
82 |
if patient["ID"] == patient_id:
|
83 |
-
return f"
|
84 |
-
return "
|
85 |
|
86 |
def pharmacist_space(patient_id):
|
87 |
for patient in patients_db:
|
88 |
if patient["ID"] == patient_id:
|
89 |
-
return f"
|
90 |
-
return "
|
91 |
|
92 |
def patient_dashboard(patient_id, password):
|
93 |
for patient in patients_db:
|
94 |
if patient["ID"] == patient_id and patient["Password"] == password:
|
95 |
-
return (f"
|
96 |
-
f"
|
97 |
-
f"
|
98 |
-
f"
|
99 |
-
f"
|
100 |
-
return "
|
101 |
|
102 |
def doctor_dashboard(password):
|
103 |
if password != doctor_password:
|
104 |
-
return "
|
105 |
if not patients_db:
|
106 |
return "No patient records available."
|
107 |
details = []
|
108 |
for patient in patients_db:
|
109 |
-
details.append(f"
|
110 |
-
f"
|
111 |
-
f"
|
112 |
-
f"
|
113 |
-
f"
|
114 |
return "\n\n".join(details)
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
# Gradio Interfaces
|
117 |
registration_interface = gr.Interface(
|
118 |
fn=register_patient,
|
@@ -173,32 +183,41 @@ doctor_dashboard_interface = gr.Interface(
|
|
173 |
outputs="text",
|
174 |
)
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
# Gradio App Layout
|
177 |
with gr.Blocks() as app:
|
178 |
gr.Markdown("# Medico GPT")
|
179 |
-
|
180 |
with gr.Tab("Patient Registration"):
|
181 |
registration_interface.render()
|
182 |
-
|
183 |
with gr.Tab("Analyze Medical Report"):
|
184 |
report_analysis_interface.render()
|
185 |
-
|
186 |
with gr.Tab("Extract PDF Report"):
|
187 |
pdf_extraction_interface.render()
|
188 |
-
|
189 |
with gr.Tab("Ophthalmologist Space"):
|
190 |
eye_disease_interface.render()
|
191 |
-
|
192 |
with gr.Tab("Doctor Space"):
|
193 |
doctor_space_interface.render()
|
194 |
-
|
195 |
with gr.Tab("Pharmacist Space"):
|
196 |
pharmacist_space_interface.render()
|
197 |
-
|
198 |
with gr.Tab("Patient Dashboard"):
|
199 |
patient_dashboard_interface.render()
|
200 |
-
|
201 |
with gr.Tab("Doctor Dashboard"):
|
202 |
doctor_dashboard_interface.render()
|
203 |
|
204 |
-
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import pdfplumber
|
4 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
5 |
import timm
|
6 |
import torch
|
7 |
import pandas as pd
|
|
|
16 |
# Load saved TensorFlow eye disease detection model
|
17 |
eye_model = tf.keras.models.load_model('model.h5')
|
18 |
|
19 |
+
# Load doctor consultation model
|
20 |
+
doctor_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/dgptAW")
|
21 |
+
doctor_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/dgptAW")
|
22 |
+
|
23 |
# Patient database
|
24 |
patients_db = []
|
25 |
|
|
|
48 |
"Precautions": "",
|
49 |
"Doctor": ""
|
50 |
})
|
51 |
+
return f"\u2705 Patient {name} registered successfully. Patient ID: {patient_id}"
|
52 |
|
53 |
def analyze_report(patient_id, report_text):
|
54 |
candidate_labels = list(disease_details.keys())
|
|
|
62 |
for patient in patients_db:
|
63 |
if patient['ID'] == patient_id:
|
64 |
patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution, Doctor=doctor)
|
65 |
+
return f"\ud83d\udd0d Diagnosis: {diagnosis}"
|
66 |
|
67 |
def extract_pdf_report(pdf):
|
68 |
text = ""
|
|
|
84 |
def doctor_space(patient_id):
|
85 |
for patient in patients_db:
|
86 |
if patient["ID"] == patient_id:
|
87 |
+
return f"\u26a0 Precautions: {patient['Precautions']}\n\ud83d\udc69\u200d\u2695 Recommended Doctor: {patient['Doctor']}"
|
88 |
+
return "\u274c Patient not found. Please check the ID."
|
89 |
|
90 |
def pharmacist_space(patient_id):
|
91 |
for patient in patients_db:
|
92 |
if patient["ID"] == patient_id:
|
93 |
+
return f"\ud83d\udc8a Medications: {patient['Medications']}"
|
94 |
+
return "\u274c Patient not found. Please check the ID."
|
95 |
|
96 |
def patient_dashboard(patient_id, password):
|
97 |
for patient in patients_db:
|
98 |
if patient["ID"] == patient_id and patient["Password"] == password:
|
99 |
+
return (f"\ud83e\ude7a Name: {patient['Name']}\n"
|
100 |
+
f"\ud83d\udccb Diagnosis: {patient['Diagnosis']}\n"
|
101 |
+
f"\ud83d\udc8a Medications: {patient['Medications']}\n"
|
102 |
+
f"\u26a0 Precautions: {patient['Precautions']}\n"
|
103 |
+
f"\ud83d\udc69\u200d\u2695 Recommended Doctor: {patient['Doctor']}")
|
104 |
+
return "\u274c Access Denied: Invalid ID or Password."
|
105 |
|
106 |
def doctor_dashboard(password):
|
107 |
if password != doctor_password:
|
108 |
+
return "\u274c Access Denied: Incorrect Password"
|
109 |
if not patients_db:
|
110 |
return "No patient records available."
|
111 |
details = []
|
112 |
for patient in patients_db:
|
113 |
+
details.append(f"\ud83e\ude7a Name: {patient['Name']}\n"
|
114 |
+
f"\ud83d\udccb Diagnosis: {patient['Diagnosis']}\n"
|
115 |
+
f"\ud83d\udc8a Medications: {patient['Medications']}\n"
|
116 |
+
f"\u26a0 Precautions: {patient['Precautions']}\n"
|
117 |
+
f"\ud83d\udc69\u200d\u2695 Recommended Doctor: {patient['Doctor']}")
|
118 |
return "\n\n".join(details)
|
119 |
|
120 |
+
def doctor_consult(query):
|
121 |
+
inputs = doctor_tokenizer.encode(query, return_tensors="pt")
|
122 |
+
outputs = doctor_model.generate(inputs, max_length=200, num_return_sequences=1, pad_token_id=doctor_tokenizer.eos_token_id)
|
123 |
+
response = doctor_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
124 |
+
return response
|
125 |
+
|
126 |
# Gradio Interfaces
|
127 |
registration_interface = gr.Interface(
|
128 |
fn=register_patient,
|
|
|
183 |
outputs="text",
|
184 |
)
|
185 |
|
186 |
+
doctor_consult_interface = gr.Interface(
|
187 |
+
fn=doctor_consult,
|
188 |
+
inputs=gr.Textbox(label="Enter your query for the doctor"),
|
189 |
+
outputs="text",
|
190 |
+
)
|
191 |
+
|
192 |
# Gradio App Layout
|
193 |
with gr.Blocks() as app:
|
194 |
gr.Markdown("# Medico GPT")
|
195 |
+
|
196 |
with gr.Tab("Patient Registration"):
|
197 |
registration_interface.render()
|
198 |
+
|
199 |
with gr.Tab("Analyze Medical Report"):
|
200 |
report_analysis_interface.render()
|
201 |
+
|
202 |
with gr.Tab("Extract PDF Report"):
|
203 |
pdf_extraction_interface.render()
|
204 |
+
|
205 |
with gr.Tab("Ophthalmologist Space"):
|
206 |
eye_disease_interface.render()
|
207 |
+
|
208 |
with gr.Tab("Doctor Space"):
|
209 |
doctor_space_interface.render()
|
210 |
+
|
211 |
with gr.Tab("Pharmacist Space"):
|
212 |
pharmacist_space_interface.render()
|
213 |
+
|
214 |
with gr.Tab("Patient Dashboard"):
|
215 |
patient_dashboard_interface.render()
|
216 |
+
|
217 |
with gr.Tab("Doctor Dashboard"):
|
218 |
doctor_dashboard_interface.render()
|
219 |
|
220 |
+
with gr.Tab("Doctor Consult"):
|
221 |
+
doctor_consult_interface.render()
|
222 |
+
|
223 |
+
app.launch(share=True)
|