Spaces:
Sleeping
Sleeping
Upload 15 files
Browse files- app.py +60 -0
- densenet_model.h5 +3 -0
- effnet_model.h5 +3 -0
- flagged/img/0.jpg +0 -0
- flagged/log.csv +5 -0
- meta_model.pkl +3 -0
- requirements.txt +0 -0
- test/cataract.jpg +0 -0
- test/cataract1.jpg +0 -0
- test/diabetic_left.jpeg +0 -0
- test/diabetic_right.jpeg +0 -0
- test/glucoma_left.jpg +0 -0
- test/glucoma_right.jpg +0 -0
- test/normal_left.jpg +0 -0
- test/normal_right.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
import joblib
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
from PIL import Image
|
7 |
+
import os
|
8 |
+
path = 'test/'
|
9 |
+
|
10 |
+
trained_meta_model = joblib.load('meta_model.pkl')
|
11 |
+
densenet_model = load_model('densenet_model.h5')
|
12 |
+
effnet_model = load_model('effnet_model.h5')
|
13 |
+
base_models = [densenet_model, effnet_model]
|
14 |
+
|
15 |
+
class_names = ['Cataract', 'DR', 'Glaucoma', 'Normal']
|
16 |
+
|
17 |
+
def preprocess_image(img):
|
18 |
+
if isinstance(img, np.ndarray):
|
19 |
+
img = Image.fromarray(img) # Convert NumPy array to PIL Image
|
20 |
+
img = img.resize((224, 224)) # Resize the image to the required size
|
21 |
+
img_array = image.img_to_array(img) # Convert image to array
|
22 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
23 |
+
img_array = img_array / 255.0 # Normalize the image if needed
|
24 |
+
return img_array
|
25 |
+
|
26 |
+
def get_single_image_meta_features(models, img_array):
|
27 |
+
meta_features = []
|
28 |
+
for model in models:
|
29 |
+
preds = model.predict(img_array)
|
30 |
+
meta_features.append(np.argmax(preds, axis=1))
|
31 |
+
return np.array(meta_features).T
|
32 |
+
|
33 |
+
def classify_image(img, patient_name, patient_age, patient_gender):
|
34 |
+
img_array = preprocess_image(img)
|
35 |
+
single_image_meta_features = get_single_image_meta_features(base_models, img_array)
|
36 |
+
final_prediction = trained_meta_model.predict(single_image_meta_features)
|
37 |
+
p = int(final_prediction[0])
|
38 |
+
result = f"Patient Name: {patient_name}\nPatient Age: {patient_age}\nPatient Gender: {patient_gender}\nPredicted Class: {class_names[p]}"
|
39 |
+
return result
|
40 |
+
|
41 |
+
# Dummy prediction to warm up the models
|
42 |
+
dummy_img = np.zeros((224, 224, 3), dtype=np.uint8)
|
43 |
+
classify_image(dummy_img, "Dummy", 0, "None")
|
44 |
+
|
45 |
+
# Define the inputs
|
46 |
+
image_input = gr.inputs.Image(shape=(224, 224), image_mode='RGB')
|
47 |
+
name_input = gr.inputs.Textbox(label="Patient Name")
|
48 |
+
age_input = gr.inputs.Number(label="Patient Age")
|
49 |
+
gender_input = gr.inputs.Radio(choices=["Male", "Female", "Other"], label="Patient Gender")
|
50 |
+
|
51 |
+
# Define the output
|
52 |
+
output_text = gr.outputs.Textbox(label="Result")
|
53 |
+
|
54 |
+
iface = gr.Interface(fn=classify_image,
|
55 |
+
inputs=[image_input, name_input, age_input, gender_input],
|
56 |
+
outputs=output_text,
|
57 |
+
title="Eye Disease Classification",
|
58 |
+
description="Upload eye images, provide patient information, and get the predicted disease class.") # Update with actual example paths if needed
|
59 |
+
|
60 |
+
iface.launch(share=True)
|
densenet_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bd2fbc97abc596b32315dea9f692500c1eb465e841f55ccde69e11608d7a9af1
|
3 |
+
size 72787216
|
effnet_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7a2ff10d8db181341faf53be20acf87c9e5c12962440d266338fc0905b535efd
|
3 |
+
size 148835264
|
flagged/img/0.jpg
ADDED
flagged/log.csv
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'img','Patient Name','Patient Age','Patient Gender','Result','flag','username','timestamp'
|
2 |
+
'img/0.jpg','Hmal',20,'Male','Patient Name: Hmal
|
3 |
+
Patient Age: 20.0
|
4 |
+
Patient Gender: Male
|
5 |
+
Predicted Class: DR','','','2024-06-24 17:51:42.587173'
|
meta_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7027b0ec9ce16d50f1870004f11da0ebeee7d1e504789dd8fd8d5cc59a1b9e5d
|
3 |
+
size 224505
|
requirements.txt
ADDED
Binary file (186 Bytes). View file
|
|
test/cataract.jpg
ADDED
test/cataract1.jpg
ADDED
test/diabetic_left.jpeg
ADDED
test/diabetic_right.jpeg
ADDED
test/glucoma_left.jpg
ADDED
test/glucoma_right.jpg
ADDED
test/normal_left.jpg
ADDED
test/normal_right.jpg
ADDED