Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import pdfplumber
|
|
8 |
from PIL import Image
|
9 |
import timm
|
10 |
import torch
|
11 |
-
from hashlib import sha256
|
12 |
|
13 |
# Load pre-trained zero-shot model for text classification
|
14 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
@@ -20,9 +19,6 @@ image_model.eval()
|
|
20 |
# Load saved TensorFlow eye disease detection model
|
21 |
eye_model = tf.keras.models.load_model('model.h5')
|
22 |
|
23 |
-
# Password Protection
|
24 |
-
DOCTOR_PASSWORD_HASH = sha256("doctor123".encode()).hexdigest()
|
25 |
-
|
26 |
# Patient database
|
27 |
patients_db = []
|
28 |
|
@@ -70,22 +66,18 @@ disease_details = {
|
|
70 |
}
|
71 |
}
|
72 |
|
73 |
-
# Helper Functions
|
74 |
-
def hash_password(password):
|
75 |
-
return sha256(password.encode()).hexdigest()
|
76 |
-
|
77 |
# Functions
|
78 |
-
def register_patient(name, age, gender
|
79 |
patient_id = len(patients_db) + 1
|
80 |
patients_db.append({
|
81 |
"ID": patient_id,
|
82 |
"Name": name,
|
83 |
"Age": age,
|
84 |
"Gender": gender,
|
85 |
-
"Password": hash_password(password),
|
86 |
"Diagnosis": "",
|
87 |
"Medications": "",
|
88 |
-
"Precautions": ""
|
|
|
89 |
})
|
90 |
return f"β
Patient {name} registered successfully. Patient ID: {patient_id}"
|
91 |
|
@@ -97,10 +89,10 @@ def analyze_report(patient_id, report_text):
|
|
97 |
# Update patient's record
|
98 |
medication = disease_details[diagnosis]['medication']
|
99 |
precaution = disease_details[diagnosis]['precaution']
|
|
|
100 |
for patient in patients_db:
|
101 |
if patient['ID'] == patient_id:
|
102 |
-
patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution)
|
103 |
-
break
|
104 |
return f"π Diagnosis: {diagnosis}"
|
105 |
|
106 |
def extract_pdf_report(pdf):
|
@@ -120,47 +112,45 @@ def predict_eye_disease(input_image):
|
|
120 |
return f"Congrats! No disease detected. Confidence: {confidence_scores['Normal']}%"
|
121 |
return "\n".join([f"{label}: {confidence}%" for label, confidence in confidence_scores.items()])
|
122 |
|
123 |
-
def
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
125 |
for patient in patients_db:
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
# Gradio Interfaces
|
136 |
-
registration_interface = gr.Interface(fn=register_patient, inputs=[
|
137 |
-
|
138 |
-
gr.Number(label="Age"),
|
139 |
-
gr.Radio(label="Gender", choices=["Male", "Female", "Other"]),
|
140 |
-
gr.Textbox(label="Password", type="password")
|
141 |
-
], outputs="text")
|
142 |
-
|
143 |
-
report_analysis_interface = gr.Interface(fn=analyze_report, inputs=[
|
144 |
-
gr.Number(label="Patient ID"),
|
145 |
-
gr.Textbox(label="Report Text")
|
146 |
-
], outputs="text")
|
147 |
-
|
148 |
pdf_report_extraction_interface = gr.Interface(fn=extract_pdf_report, inputs=gr.File(label="Upload PDF Report"), outputs="text")
|
149 |
-
|
150 |
eye_disease_interface = gr.Interface(fn=predict_eye_disease, inputs=gr.Image(label="Upload an Eye Image", type="numpy"), outputs="text")
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
gr.Textbox(label="Password", type="password")
|
155 |
-
], outputs="dataframe")
|
156 |
-
|
157 |
-
doctor_dashboard_interface = gr.Interface(fn=view_all_patients, inputs=[
|
158 |
-
gr.Textbox(label="Doctor Password", type="password")
|
159 |
-
], outputs="dataframe")
|
160 |
|
161 |
# Gradio App Layout
|
162 |
with gr.Blocks() as app:
|
163 |
-
gr.Markdown("# Medical Analyzer and
|
164 |
with gr.Tab("Patient Registration"):
|
165 |
registration_interface.render()
|
166 |
with gr.Tab("Analyze Medical Report"):
|
@@ -169,9 +159,11 @@ with gr.Blocks() as app:
|
|
169 |
pdf_report_extraction_interface.render()
|
170 |
with gr.Tab("Detect Eye Disease"):
|
171 |
eye_disease_interface.render()
|
172 |
-
with gr.Tab("Patient Dashboard"):
|
173 |
-
patient_dashboard_interface.render()
|
174 |
with gr.Tab("Doctor Dashboard"):
|
175 |
doctor_dashboard_interface.render()
|
|
|
|
|
|
|
|
|
176 |
|
177 |
app.launch(share=True)
|
|
|
8 |
from PIL import Image
|
9 |
import timm
|
10 |
import torch
|
|
|
11 |
|
12 |
# Load pre-trained zero-shot model for text classification
|
13 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
|
|
19 |
# Load saved TensorFlow eye disease detection model
|
20 |
eye_model = tf.keras.models.load_model('model.h5')
|
21 |
|
|
|
|
|
|
|
22 |
# Patient database
|
23 |
patients_db = []
|
24 |
|
|
|
66 |
}
|
67 |
}
|
68 |
|
|
|
|
|
|
|
|
|
69 |
# Functions
|
70 |
+
def register_patient(name, age, gender):
|
71 |
patient_id = len(patients_db) + 1
|
72 |
patients_db.append({
|
73 |
"ID": patient_id,
|
74 |
"Name": name,
|
75 |
"Age": age,
|
76 |
"Gender": gender,
|
|
|
77 |
"Diagnosis": "",
|
78 |
"Medications": "",
|
79 |
+
"Precautions": "",
|
80 |
+
"Doctor": ""
|
81 |
})
|
82 |
return f"β
Patient {name} registered successfully. Patient ID: {patient_id}"
|
83 |
|
|
|
89 |
# Update patient's record
|
90 |
medication = disease_details[diagnosis]['medication']
|
91 |
precaution = disease_details[diagnosis]['precaution']
|
92 |
+
doctor = disease_details[diagnosis]['doctor']
|
93 |
for patient in patients_db:
|
94 |
if patient['ID'] == patient_id:
|
95 |
+
patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution, Doctor=doctor)
|
|
|
96 |
return f"π Diagnosis: {diagnosis}"
|
97 |
|
98 |
def extract_pdf_report(pdf):
|
|
|
112 |
return f"Congrats! No disease detected. Confidence: {confidence_scores['Normal']}%"
|
113 |
return "\n".join([f"{label}: {confidence}%" for label, confidence in confidence_scores.items()])
|
114 |
|
115 |
+
def doctor_dashboard(password):
|
116 |
+
doctor_password = "doctor123"
|
117 |
+
if password != doctor_password:
|
118 |
+
return "β Access Denied: Incorrect Password"
|
119 |
+
if not patients_db:
|
120 |
+
return "No patient records available."
|
121 |
+
details = []
|
122 |
for patient in patients_db:
|
123 |
+
details.append(f"π©Ί Patient Name: {patient['Name']}\n"
|
124 |
+
f"π Diagnosis: {patient['Diagnosis']}\n"
|
125 |
+
f"π Medications: {patient['Medications']}\n"
|
126 |
+
f"β οΈ Precautions: {patient['Precautions']}\n"
|
127 |
+
f"π©ββοΈ Recommended Doctor: {patient['Doctor']}")
|
128 |
+
return "\n\n".join(details)
|
129 |
+
|
130 |
+
def pharmacist_space(password):
|
131 |
+
pharmacist_password = "pharmacist123"
|
132 |
+
if password != pharmacist_password:
|
133 |
+
return "β Access Denied: Incorrect Password"
|
134 |
+
if not patients_db:
|
135 |
+
return "No patient records available."
|
136 |
+
details = []
|
137 |
+
for patient in patients_db:
|
138 |
+
details.append(f"π Patient Name: {patient['Name']}\n"
|
139 |
+
f"π Prescribed Medications: {patient['Medications']}")
|
140 |
+
return "\n\n".join(details)
|
141 |
|
142 |
# Gradio Interfaces
|
143 |
+
registration_interface = gr.Interface(fn=register_patient, inputs=[gr.Textbox(label="Patient Name"), gr.Number(label="Age"), gr.Radio(label="Gender", choices=["Male", "Female", "Other"])], outputs="text")
|
144 |
+
report_analysis_interface = gr.Interface(fn=analyze_report, inputs=[gr.Number(label="Patient ID"), gr.Textbox(label="Report Text")], outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
pdf_report_extraction_interface = gr.Interface(fn=extract_pdf_report, inputs=gr.File(label="Upload PDF Report"), outputs="text")
|
|
|
146 |
eye_disease_interface = gr.Interface(fn=predict_eye_disease, inputs=gr.Image(label="Upload an Eye Image", type="numpy"), outputs="text")
|
147 |
+
patient_dashboard_interface = gr.Interface(fn=lambda: pd.DataFrame(patients_db), inputs=None, outputs="dataframe")
|
148 |
+
doctor_dashboard_interface = gr.Interface(fn=doctor_dashboard, inputs=gr.Textbox(label="Doctor Password", type="password"), outputs="text")
|
149 |
+
pharmacist_interface = gr.Interface(fn=pharmacist_space, inputs=gr.Textbox(label="Pharmacist Password", type="password"), outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
# Gradio App Layout
|
152 |
with gr.Blocks() as app:
|
153 |
+
gr.Markdown("# Medical Analyzer and Eye Disease Detection")
|
154 |
with gr.Tab("Patient Registration"):
|
155 |
registration_interface.render()
|
156 |
with gr.Tab("Analyze Medical Report"):
|
|
|
159 |
pdf_report_extraction_interface.render()
|
160 |
with gr.Tab("Detect Eye Disease"):
|
161 |
eye_disease_interface.render()
|
|
|
|
|
162 |
with gr.Tab("Doctor Dashboard"):
|
163 |
doctor_dashboard_interface.render()
|
164 |
+
with gr.Tab("Pharmacist Space"):
|
165 |
+
pharmacist_interface.render()
|
166 |
+
with gr.Tab("Patient Dashboard"):
|
167 |
+
patient_dashboard_interface.render()
|
168 |
|
169 |
app.launch(share=True)
|