Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
30 |
-
|
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 |
-
|
40 |
-
|
41 |
-
|
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"**
|
48 |
|
49 |
-
|
50 |
-
|
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(
|