| import gradio as gr |
| import tensorflow as tf |
| import numpy as np |
|
|
| IMAGE_SIZE = 256 |
|
|
| |
| model = tf.keras.models.load_model('my_model.h5') |
|
|
| |
| class_labels = ['Mild', 'Moderate', 'No_DR', 'Proliferate_DR', 'Severe'] |
|
|
| def predict(image): |
| |
| image = tf.image.resize(image, (IMAGE_SIZE, IMAGE_SIZE)) |
| image = np.expand_dims(image, axis=0) |
|
|
| |
| predictions = model.predict(image) |
| confidence = np.max(predictions) |
| predicted_class = class_labels[np.argmax(predictions)] |
|
|
| return predicted_class, float(confidence) |
|
|
| |
| 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." |
| ) |
|
|
| |
| interface.launch() |
|
|