Diabetic / app.py
Krish30's picture
Create app.py
a7c2cae verified
raw
history blame
No virus
1.12 kB
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('/content/drive/MyDrive/Diabetic /RestNet_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()