ahmed-7124 commited on
Commit
05d848d
Β·
verified Β·
1 Parent(s): 0b6b50a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -41
app.py CHANGED
@@ -3,7 +3,6 @@ import tensorflow as tf
3
  import pdfplumber
4
  from transformers import pipeline
5
  import timm
6
- import torch
7
 
8
  # Load pre-trained zero-shot model for text classification
9
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
@@ -26,9 +25,6 @@ disease_details = {
26
  "diabetes": {"medication": "Metformin or insulin", "precaution": "Monitor sugar levels", "doctor": "Endocrinologist"},
27
  }
28
 
29
- # Password for doctor dashboard
30
- doctor_password = "doctor123"
31
-
32
  # Functions
33
  def register_patient(name, age, gender, password):
34
  patient_id = len(patients_db) + 1
@@ -66,45 +62,13 @@ def extract_pdf_report(pdf):
66
  text += page.extract_text()
67
  return text
68
 
69
- def predict_eye_disease(input_image):
70
- input_image = tf.image.resize(input_image, [224, 224]) / 255.0
71
- input_image = tf.expand_dims(input_image, 0)
72
- predictions = eye_model.predict(input_image)
73
- labels = ['Cataract', 'Conjunctivitis', 'Glaucoma', 'Normal']
74
- confidence_scores = {labels[i]: round(predictions[0][i] * 100, 2) for i in range(len(labels))}
75
- if confidence_scores['Normal'] > 50:
76
- return f"Congrats! No disease detected. Confidence: {confidence_scores['Normal']}%"
77
- return "\n".join([f"{label}: {confidence}%" for label, confidence in confidence_scores.items()])
78
-
79
- def doctor_space(patient_id):
80
- for patient in patients_db:
81
- if patient["ID"] == patient_id:
82
- return f"⚠️ Precautions: {patient['Precautions']}\nπŸ‘©β€βš•οΈ Recommended Doctor: {patient['Doctor']}"
83
- return "❌ Patient not found. Please check the ID."
84
-
85
- def pharmacist_space(patient_id):
86
- for patient in patients_db:
87
- if patient["ID"] == patient_id:
88
- return f"πŸ’Š Medications: {patient['Medications']}"
89
- return "❌ Patient not found. Please check the ID."
90
-
91
- def patient_dashboard(patient_id, password):
92
- for patient in patients_db:
93
- if patient["ID"] == patient_id and patient["Password"] == password:
94
- return (f"🩺 Name: {patient['Name']}\n"
95
- f"πŸ“‹ Diagnosis: {patient['Diagnosis']}\n"
96
- f"πŸ’Š Medications: {patient['Medications']}\n"
97
- f"⚠️ Precautions: {patient['Precautions']}\n"
98
- f"πŸ‘©β€βš•οΈ Recommended Doctor: {patient['Doctor']}")
99
- return "❌ Access Denied: Invalid ID or Password."
100
-
101
  # Gradio App Layout
102
  with gr.Blocks() as app:
103
  gr.Markdown("# Medico GPT")
104
 
105
  # Shared state for extracted text
106
  extracted_text_state = gr.State("")
107
-
108
  with gr.Tab("Patient Registration"):
109
  name = gr.Textbox(label="Patient Name")
110
  age = gr.Number(label="Age")
@@ -144,10 +108,9 @@ with gr.Blocks() as app:
144
 
145
  # Autofill extracted text into Analyze Medical Report tab
146
  extract_button.click(
147
- fn=None,
148
- inputs=None,
149
- outputs=[report_text],
150
- _js="(x) => x"
151
  )
152
 
153
  app.launch(share=True)
 
3
  import pdfplumber
4
  from transformers import 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
  # Functions
29
  def register_patient(name, age, gender, password):
30
  patient_id = len(patients_db) + 1
 
62
  text += page.extract_text()
63
  return text
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  # Gradio App Layout
66
  with gr.Blocks() as app:
67
  gr.Markdown("# Medico GPT")
68
 
69
  # Shared state for extracted text
70
  extracted_text_state = gr.State("")
71
+
72
  with gr.Tab("Patient Registration"):
73
  name = gr.Textbox(label="Patient Name")
74
  age = gr.Number(label="Age")
 
108
 
109
  # Autofill extracted text into Analyze Medical Report tab
110
  extract_button.click(
111
+ fn=lambda extracted_text: extracted_text,
112
+ inputs=extracted_text_state,
113
+ outputs=report_text
 
114
  )
115
 
116
  app.launch(share=True)