jdelgado2002's picture
fix upload problem
70af086 verified
raw
history blame
1.11 kB
import gradio as gr
from fastai.vision.all import *
import os
# Load model
learn = load_learner('model.pkl')
labels = learn.dls.vocab
# Define label descriptions
label_descriptions = {
0: "No DR",
1: "Mild",
2: "Moderate",
3: "Severe",
4: "Proliferative DR"
}
# Prediction function
def predict(img):
img = PILImage.create(img)
pred, pred_idx, probs = learn.predict(img)
return {label_descriptions[labels[i]]: float(probs[i]) for i in range(len(labels))}
# Gradio Interface
title = "Diabetic Retinopathy Detection"
description = """Detects severity of diabetic retinopathy from a given retina image."""
article = "<p style='text-align: center'>Example article or instructions here</p>"
# Prepare examples if available
test_folder = "test"
image_paths = [os.path.join(test_folder, img) for img in os.listdir(test_folder) if img.endswith(('.png', '.jpg', '.jpeg'))]
gr.Interface(
fn=predict,
inputs=gr.Image(type="filepath"),
outputs=gr.Label(num_top_classes=5),
examples=image_paths,
article=article,
title=title,
description=description,
).launch()