asmaa1 commited on
Commit
c302b39
·
verified ·
1 Parent(s): 511be78

Upload 8 files

Browse files
.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

  • SHA256: ef0bda2c21f3dbe839b4e5168fa7e52afe61e6923a56fd625bba0ddc1665d1d8
  • Pointer size: 132 Bytes
  • Size of remote file: 1.88 MB
Moderate.png ADDED

Git LFS Details

  • SHA256: 3f34b577a7102dddea20d2aaed76028bcf724ddb82e923b5699474d3272510f9
  • Pointer size: 132 Bytes
  • Size of remote file: 3.22 MB
No_DR.png ADDED

Git LFS Details

  • SHA256: c18a236541ae3d3ddbf8cf3eae991b4ff28446c5313b3dc2afa2506fa4cb60c1
  • Pointer size: 131 Bytes
  • Size of remote file: 975 kB
Proliferate_DR (1).png ADDED

Git LFS Details

  • SHA256: 0987b2b0c388752223d11d21632a3b301b37fc364c3c1acd2b514f443ab072b9
  • Pointer size: 132 Bytes
  • Size of remote file: 5.33 MB
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