File size: 1,137 Bytes
035cdb1 437a6de 035cdb1 437a6de 035cdb1 1f88afb 035cdb1 437a6de 035cdb1 1f88afb 035cdb1 1f88afb 035cdb1 437a6de 035cdb1 437a6de 035cdb1 |
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 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import torch
import torchvision.transforms as transforms
from medmnist import INFO
from model import load_model
from PIL import Image
info = INFO["dermamnist"]
class_names = list(info["label"].values())
model = load_model()
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])
def predict(image):
if image is None:
return {"Error": 1.0}
image = image.convert("RGB")
input_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
outputs = model(input_tensor)
probs = torch.softmax(outputs, dim=1).squeeze().numpy()
return {class_names[i]: float(probs[i]) for i in range(len(class_names))}
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="Skin Disease Classifier",
description="Upload a skin image and our model will predict potential skin cancer(melanoma), tumor or moles using EfficientNet-B2 fine-tuned on DermMNIST."
)
if __name__ == "__main__":
demo.launch()
|