Spaces:
Build error
Build error
Upload 8 files
Browse files- .gitattributes +4 -0
- 1.jpg +0 -0
- Mild.png +3 -0
- Moderate.png +3 -0
- No_DR.png +3 -0
- Proliferate_DR (1).png +3 -0
- app.py +69 -0
- diabetic_retinopathy_model.h5 +3 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Mild.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
Moderate.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
No_DR.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
Proliferate_DR[[:space:]](1).png filter=lfs diff=lfs merge=lfs -text
|
1.jpg
ADDED
|
Mild.png
ADDED
|
Git LFS Details
|
Moderate.png
ADDED
|
Git LFS Details
|
No_DR.png
ADDED
|
Git LFS Details
|
Proliferate_DR (1).png
ADDED
|
Git LFS Details
|
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from keras.models import load_model
|
| 2 |
+
from keras.preprocessing import image
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
import gradio as gr
|
| 6 |
+
loaded_model = load_model('diabetic_retinopathy_model.h5')
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import numpy as np
|
| 9 |
+
from tensorflow.keras.preprocessing import image
|
| 10 |
+
|
| 11 |
+
# Class mapping
|
| 12 |
+
class_mapping = {
|
| 13 |
+
0: 'No DR',
|
| 14 |
+
1: 'Mild',
|
| 15 |
+
2: 'Moderate',
|
| 16 |
+
3: 'Severe',
|
| 17 |
+
4: 'Proliferative DR'
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# URL of the fixed example image to display
|
| 21 |
+
example_image_url = "1.jpg" # Replace with the actual URL
|
| 22 |
+
|
| 23 |
+
def predict_diabetic_retinopathy(test_image, loaded_model, height=512, width=512):
|
| 24 |
+
# Always return the example image
|
| 25 |
+
try:
|
| 26 |
+
if test_image is None:
|
| 27 |
+
return "No image uploaded. Please upload an image.", example_image_url
|
| 28 |
+
|
| 29 |
+
# Ensure the image is in the correct format
|
| 30 |
+
img = image.img_to_array(test_image)
|
| 31 |
+
|
| 32 |
+
# Resize the image while maintaining the aspect ratio
|
| 33 |
+
img = np.array(image.smart_resize(img, (height, width)))
|
| 34 |
+
|
| 35 |
+
img_array = np.expand_dims(img, axis=0)
|
| 36 |
+
img_array /= 255.0 # Normalize the image array
|
| 37 |
+
|
| 38 |
+
# Make predictions
|
| 39 |
+
predictions = loaded_model.predict(img_array)
|
| 40 |
+
|
| 41 |
+
# Convert predictions to the corresponding class
|
| 42 |
+
predicted_class = np.argmax(predictions)
|
| 43 |
+
|
| 44 |
+
# Return the predicted class and the example image URL
|
| 45 |
+
return f"**Predicted Diabetic Retinopathy Stage:** {class_mapping[predicted_class]}", example_image_url
|
| 46 |
+
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"An error occurred: {str(e)}", example_image_url
|
| 49 |
+
|
| 50 |
+
# Create the Gradio interface with fixed example images
|
| 51 |
+
example_images = [
|
| 52 |
+
"No_DR.png",
|
| 53 |
+
"Mild.png",
|
| 54 |
+
"Moderate.png",
|
| 55 |
+
"Proliferate_DR.png"
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
iface = gr.Interface(
|
| 59 |
+
fn=lambda img: predict_diabetic_retinopathy(img, loaded_model),
|
| 60 |
+
inputs=gr.Image(type="numpy", label="Upload Retina Image"),
|
| 61 |
+
outputs=[gr.Markdown(label="Prediction Result"), gr.Image(value=example_image_url, label="Example Image")],
|
| 62 |
+
title="Diabetic Retinopathy Prediction",
|
| 63 |
+
description="Upload an image of the retina to predict the stage of diabetic retinopathy.",
|
| 64 |
+
theme="default",
|
| 65 |
+
examples=example_images
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
# Launch the interface
|
| 69 |
+
iface.launch()
|
diabetic_retinopathy_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d11483d5063500d6c41919d43c65044c038b3fbb3b2cd05abb2dd664d2cd7bf
|
| 3 |
+
size 333766768
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow==2.17.0
|
| 3 |
+
numpy==1.24.3
|
| 4 |
+
opencv-python
|