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