ahmed-7124 commited on
Commit
afd3d9f
Β·
verified Β·
1 Parent(s): f2b1e48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -4
app.py CHANGED
@@ -1,11 +1,21 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
- import pandas as pd
4
  from transformers import pipeline
 
 
 
5
 
6
  # Load pre-trained zero-shot model for text classification
7
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
8
 
 
 
 
 
 
 
 
9
  # Patient database
10
  patients_db = []
11
 
@@ -50,6 +60,23 @@ def analyze_report(patient_id, report_text):
50
  patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution, Doctor=doctor)
51
  return f"πŸ” Diagnosis: {diagnosis}"
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  def doctor_space(patient_id):
54
  for patient in patients_db:
55
  if patient["ID"] == patient_id:
@@ -104,6 +131,18 @@ report_analysis_interface = gr.Interface(
104
  outputs="text",
105
  )
106
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  doctor_space_interface = gr.Interface(
108
  fn=doctor_space,
109
  inputs=gr.Number(label="Patient ID"),
@@ -133,11 +172,15 @@ doctor_dashboard_interface = gr.Interface(
133
 
134
  # Gradio App Layout
135
  with gr.Blocks() as app:
136
- gr.Markdown("# Medical System")
137
- with gr.Tab("Register Patient"):
138
  registration_interface.render()
139
- with gr.Tab("Analyze Report"):
140
  report_analysis_interface.render()
 
 
 
 
141
  with gr.Tab("Doctor Space"):
142
  doctor_space_interface.render()
143
  with gr.Tab("Pharmacist Space"):
 
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
8
 
9
  # Load pre-trained zero-shot model for text classification
10
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
11
 
12
+ # Pre-trained ResNet50 model for X-ray or image analysis
13
+ image_model = timm.create_model('resnet50', pretrained=True)
14
+ image_model.eval()
15
+
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
 
 
60
  patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution, Doctor=doctor)
61
  return f"πŸ” Diagnosis: {diagnosis}"
62
 
63
+ def extract_pdf_report(pdf):
64
+ text = ""
65
+ with pdfplumber.open(pdf.name) as pdf_file:
66
+ for page in pdf_file.pages:
67
+ text += page.extract_text()
68
+ return text
69
+
70
+ def predict_eye_disease(input_image):
71
+ input_image = tf.image.resize(input_image, [224, 224]) / 255.0
72
+ input_image = tf.expand_dims(input_image, 0)
73
+ predictions = eye_model.predict(input_image)
74
+ labels = ['Cataract', 'Conjunctivitis', 'Glaucoma', 'Normal']
75
+ confidence_scores = {labels[i]: round(predictions[0][i] * 100, 2) for i in range(len(labels))}
76
+ if confidence_scores['Normal'] > 50:
77
+ return f"Congrats! No disease detected. Confidence: {confidence_scores['Normal']}%"
78
+ return "\n".join([f"{label}: {confidence}%" for label, confidence in confidence_scores.items()])
79
+
80
  def doctor_space(patient_id):
81
  for patient in patients_db:
82
  if patient["ID"] == patient_id:
 
131
  outputs="text",
132
  )
133
 
134
+ pdf_extraction_interface = gr.Interface(
135
+ fn=extract_pdf_report,
136
+ inputs=gr.File(label="Upload PDF Report"),
137
+ outputs="text",
138
+ )
139
+
140
+ eye_disease_interface = gr.Interface(
141
+ fn=predict_eye_disease,
142
+ inputs=gr.Image(label="Upload an Eye Image", type="numpy"),
143
+ outputs="text",
144
+ )
145
+
146
  doctor_space_interface = gr.Interface(
147
  fn=doctor_space,
148
  inputs=gr.Number(label="Patient ID"),
 
172
 
173
  # Gradio App Layout
174
  with gr.Blocks() as app:
175
+ gr.Markdown("# Medical Analyzer and Eye Disease Detection")
176
+ with gr.Tab("Patient Registration"):
177
  registration_interface.render()
178
+ with gr.Tab("Analyze Medical Report"):
179
  report_analysis_interface.render()
180
+ with gr.Tab("Extract PDF Report"):
181
+ pdf_extraction_interface.render()
182
+ with gr.Tab("Detect Eye Disease"):
183
+ eye_disease_interface.render()
184
  with gr.Tab("Doctor Space"):
185
  doctor_space_interface.render()
186
  with gr.Tab("Pharmacist Space"):