asmaa1 commited on
Commit
6ebf57f
·
verified ·
1 Parent(s): 6a845d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -4,8 +4,6 @@ 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
@@ -17,19 +15,19 @@ class_mapping = {
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)
@@ -41,13 +39,13 @@ def predict_diabetic_retinopathy(test_image, loaded_model, height=512, width=512
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",
 
4
  import os
5
  import gradio as gr
6
  loaded_model = load_model('diabetic_retinopathy_model.h5')
 
 
7
  from tensorflow.keras.preprocessing import image
8
 
9
  # Class mapping
 
15
  4: 'Proliferative DR'
16
  }
17
 
18
+ # fixed image
19
+ example_image_url = "1.jpg"
20
 
21
  def predict_diabetic_retinopathy(test_image, loaded_model, height=512, width=512):
22
+ # Always return the image
23
  try:
24
  if test_image is None:
25
  return "No image uploaded. Please upload an image.", example_image_url
26
 
27
+
28
  img = image.img_to_array(test_image)
29
 
30
+ # Resize the image
31
  img = np.array(image.smart_resize(img, (height, width)))
32
 
33
  img_array = np.expand_dims(img, axis=0)
 
39
  # Convert predictions to the corresponding class
40
  predicted_class = np.argmax(predictions)
41
 
42
+ # Return the predicted class and the image
43
  return f"**Predicted Diabetic Retinopathy Stage:** {class_mapping[predicted_class]}", example_image_url
44
 
45
  except Exception as e:
46
  return f"An error occurred: {str(e)}", example_image_url
47
 
48
+ # Create the Gradio interface
49
  example_images = [
50
  "No_DR.png",
51
  "Mild.png",