ahmed-7124 commited on
Commit
1d09b2b
Β·
verified Β·
1 Parent(s): 0f8851c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -40
app.py CHANGED
@@ -16,10 +16,6 @@ image_model.eval()
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
 
@@ -34,6 +30,21 @@ disease_details = {
34
  # Passwords
35
  doctor_password = "doctor123"
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # Functions
38
  def register_patient(name, age, gender, password):
39
  patient_id = len(patients_db) + 1
@@ -48,7 +59,7 @@ def register_patient(name, age, gender, password):
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,7 +73,7 @@ def analyze_report(patient_id, report_text):
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,45 +95,39 @@ def predict_eye_disease(input_image):
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,41 +188,41 @@ doctor_dashboard_interface = gr.Interface(
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)
 
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
 
 
30
  # Passwords
31
  doctor_password = "doctor123"
32
 
33
+ # Load doctor consultation model and tokenizer
34
+ try:
35
+ doctor_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/dgptAW")
36
+ except Exception as e:
37
+ print(f"Fast tokenizer failed: {e}. Falling back to slow tokenizer.")
38
+ doctor_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/dgptAW", use_fast=False)
39
+
40
+ doctor_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/dgptAW")
41
+
42
+ def consult_doctor(prompt):
43
+ inputs = doctor_tokenizer(prompt, return_tensors="pt")
44
+ outputs = doctor_model.generate(**inputs, max_new_tokens=100)
45
+ response = doctor_tokenizer.decode(outputs[0], skip_special_tokens=True)
46
+ return response
47
+
48
  # Functions
49
  def register_patient(name, age, gender, password):
50
  patient_id = len(patients_db) + 1
 
59
  "Precautions": "",
60
  "Doctor": ""
61
  })
62
+ return f"βœ… Patient {name} registered successfully. Patient ID: {patient_id}"
63
 
64
  def analyze_report(patient_id, report_text):
65
  candidate_labels = list(disease_details.keys())
 
73
  for patient in patients_db:
74
  if patient['ID'] == patient_id:
75
  patient.update(Diagnosis=diagnosis, Medications=medication, Precautions=precaution, Doctor=doctor)
76
+ return f"πŸ” Diagnosis: {diagnosis}"
77
 
78
  def extract_pdf_report(pdf):
79
  text = ""
 
95
  def doctor_space(patient_id):
96
  for patient in patients_db:
97
  if patient["ID"] == patient_id:
98
+ return f"⚠ Precautions: {patient['Precautions']}\nπŸ‘©β€βš• Recommended Doctor: {patient['Doctor']}"
99
+ return "❌ Patient not found. Please check the ID."
100
 
101
  def pharmacist_space(patient_id):
102
  for patient in patients_db:
103
  if patient["ID"] == patient_id:
104
+ return f"πŸ’Š Medications: {patient['Medications']}"
105
+ return "❌ Patient not found. Please check the ID."
106
 
107
  def patient_dashboard(patient_id, password):
108
  for patient in patients_db:
109
  if patient["ID"] == patient_id and patient["Password"] == password:
110
+ return (f"🩺 Name: {patient['Name']}\n"
111
+ f"πŸ“‹ Diagnosis: {patient['Diagnosis']}\n"
112
+ f"πŸ’Š Medications: {patient['Medications']}\n"
113
+ f"⚠ Precautions: {patient['Precautions']}\n"
114
+ f"πŸ‘©β€βš• Recommended Doctor: {patient['Doctor']}")
115
+ return "❌ Access Denied: Invalid ID or Password."
116
 
117
  def doctor_dashboard(password):
118
  if password != doctor_password:
119
+ return "❌ Access Denied: Incorrect Password"
120
  if not patients_db:
121
  return "No patient records available."
122
  details = []
123
  for patient in patients_db:
124
+ details.append(f"🩺 Name: {patient['Name']}\n"
125
+ f"πŸ“‹ Diagnosis: {patient['Diagnosis']}\n"
126
+ f"πŸ’Š Medications: {patient['Medications']}\n"
127
+ f"⚠ Precautions: {patient['Precautions']}\n"
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,
 
188
  outputs="text",
189
  )
190
 
191
+ consult_doctor_interface = gr.Interface(
192
+ fn=consult_doctor,
193
+ inputs=gr.Textbox(label="Enter Your Query for the Doctor"),
194
  outputs="text",
195
  )
196
 
197
  # Gradio App Layout
198
  with gr.Blocks() as app:
199
  gr.Markdown("# Medico GPT")
200
+
201
  with gr.Tab("Patient Registration"):
202
  registration_interface.render()
203
+
204
  with gr.Tab("Analyze Medical Report"):
205
  report_analysis_interface.render()
206
+
207
  with gr.Tab("Extract PDF Report"):
208
  pdf_extraction_interface.render()
209
+
210
  with gr.Tab("Ophthalmologist Space"):
211
  eye_disease_interface.render()
212
+
213
  with gr.Tab("Doctor Space"):
214
  doctor_space_interface.render()
215
+
216
  with gr.Tab("Pharmacist Space"):
217
  pharmacist_space_interface.render()
218
+
219
  with gr.Tab("Patient Dashboard"):
220
  patient_dashboard_interface.render()
221
+
222
  with gr.Tab("Doctor Dashboard"):
223
  doctor_dashboard_interface.render()
224
 
225
  with gr.Tab("Doctor Consult"):
226
+ consult_doctor_interface.render()
227
 
228
  app.launch(share=True)