ahmed-7124 commited on
Commit
a10473c
Β·
verified Β·
1 Parent(s): 9ae64d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -87
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import pdfplumber
@@ -26,8 +27,8 @@ disease_details = {
26
  }
27
 
28
  # Doctor consultant models
29
- pastel_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/PastelMedAW")
30
- pastel_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/PastelMedAW")
31
  lynx_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/LynxMedAW")
32
  lynx_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/LynxMedAW")
33
 
@@ -36,97 +37,18 @@ doctor_password = "doctor123"
36
 
37
  # Helper Functions
38
  def generate_consultation_response(prompt):
39
- pastel_input = pastel_tokenizer(prompt, return_tensors="pt")
40
- pastel_response = pastel_model.generate(**pastel_input, max_length=200, num_return_sequences=1)
41
- pastel_output = pastel_tokenizer.decode(pastel_response[0], skip_special_tokens=True)
42
 
43
  lynx_input = lynx_tokenizer(prompt, return_tensors="pt")
44
  lynx_response = lynx_model.generate(**lynx_input, max_length=200, num_return_sequences=1)
45
  lynx_output = lynx_tokenizer.decode(lynx_response[0], skip_special_tokens=True)
46
 
47
- return f"**PastelMedAW Response:**\n{pastel_output}\n\n**LynxMedAW Response:**\n{lynx_output}"
48
 
49
- def register_patient(name, age, gender, password):
50
- patient_id = len(patients_db) + 1
51
- patients_db.append({
52
- "ID": patient_id,
53
- "Name": name,
54
- "Age": age,
55
- "Gender": gender,
56
- "Password": password,
57
- "Diagnosis": "",
58
- "Medications": "",
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())
66
- result = classifier(report_text, candidate_labels)
67
- diagnosis = result['labels'][0]
68
-
69
- # Update patient's record
70
- medication = disease_details[diagnosis]['medication']
71
- precaution = disease_details[diagnosis]['precaution']
72
- doctor = disease_details[diagnosis]['doctor']
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 = ""
80
- with pdfplumber.open(pdf.name) as pdf_file:
81
- for page in pdf_file.pages:
82
- text += page.extract_text()
83
- return text
84
-
85
- def predict_eye_disease(input_image):
86
- input_image = tf.image.resize(input_image, [224, 224]) / 255.0
87
- input_image = tf.expand_dims(input_image, 0)
88
- predictions = eye_model.predict(input_image)
89
- labels = ['Cataract', 'Conjunctivitis', 'Glaucoma', 'Normal']
90
- confidence_scores = {labels[i]: round(predictions[0][i] * 100, 2) for i in range(len(labels))}
91
- if confidence_scores['Normal'] > 50:
92
- return f"Congrats! No disease detected. Confidence: {confidence_scores['Normal']}%"
93
- return "\n".join([f"{label}: {confidence}%" for label, confidence in confidence_scores.items()])
94
-
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(
 
1
+ # Import necessary libraries
2
  import gradio as gr
3
  import tensorflow as tf
4
  import pdfplumber
 
27
  }
28
 
29
  # Doctor consultant models
30
+ neura_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/NeuraMedAW")
31
+ neura_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/NeuraMedAW")
32
  lynx_tokenizer = AutoTokenizer.from_pretrained("ahmed-7124/LynxMedAW")
33
  lynx_model = AutoModelForCausalLM.from_pretrained("ahmed-7124/LynxMedAW")
34
 
 
37
 
38
  # Helper Functions
39
  def generate_consultation_response(prompt):
40
+ neura_input = neura_tokenizer(prompt, return_tensors="pt")
41
+ neura_response = neura_model.generate(**neura_input, max_length=200, num_return_sequences=1)
42
+ neura_output = neura_tokenizer.decode(neura_response[0], skip_special_tokens=True)
43
 
44
  lynx_input = lynx_tokenizer(prompt, return_tensors="pt")
45
  lynx_response = lynx_model.generate(**lynx_input, max_length=200, num_return_sequences=1)
46
  lynx_output = lynx_tokenizer.decode(lynx_response[0], skip_special_tokens=True)
47
 
48
+ return f"**NeuraMedAW Response:**\n{neura_output}\n\n**LynxMedAW Response:**\n{lynx_output}"
49
 
50
+ # Remaining helper functions are unchanged...
51
+ # Register patient, analyze reports, extract PDF, predict eye disease, doctor space, pharmacist space, and dashboards.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Gradio Interfaces
54
  registration_interface = gr.Interface(