Krish30 commited on
Commit
a7c2cae
·
verified ·
1 Parent(s): 55e0779

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+
5
+ IMAGE_SIZE = 256
6
+
7
+ # Load the saved model
8
+ model = tf.keras.models.load_model('/content/drive/MyDrive/Diabetic /RestNet_model/my_model.h5')
9
+
10
+ # Define class labels (adjust this according to your specific classes)
11
+ class_labels = ['Mild', 'Moderate', 'No_DR', 'Proliferate_DR', 'Severe']
12
+
13
+ def predict(image):
14
+ # Preprocess the image to the required size and scale
15
+ image = tf.image.resize(image, (IMAGE_SIZE, IMAGE_SIZE))
16
+ image = np.expand_dims(image, axis=0) # Add batch dimension
17
+
18
+ # Make prediction
19
+ predictions = model.predict(image)
20
+ confidence = np.max(predictions)
21
+ predicted_class = class_labels[np.argmax(predictions)]
22
+
23
+ return predicted_class, float(confidence)
24
+
25
+ # Create the Gradio interface
26
+ interface = gr.Interface(
27
+ fn=predict,
28
+ inputs=gr.Image(type="pil"),
29
+ outputs=[gr.Label(num_top_classes=1), gr.Number(label="Confidence")],
30
+ title="Early Diabetic Retinopathy Detection",
31
+ description="Upload an image and get the predicted class along with confidence score."
32
+ )
33
+
34
+ # Launch the interface
35
+ interface.launch()