BeanLeafApp / app.py
RKoops's picture
Update used model name
3140f1a
raw
history blame
924 Bytes
import datasets
import gradio as gr
import torch
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
dataset = datasets.load_dataset("beans")
labels = dataset["train"].features["labels"].names
extractor = AutoFeatureExtractor.from_pretrained("RKoops/BeanLeafClassifier")
model = AutoModelForImageClassification.from_pretrained("RKoops/BeanLeafClassifier")
def classify(im):
features = extractor(im, return_tensors="pt")
logits = model(features["pixel_values"])[-1]
probability = torch.nn.functional.softmax(logits, dim=-1)
probs = probability[0].detach().numpy()
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
return confidences
interface = gr.Interface(
classify,
inputs="image",
outputs="label",
title="Bean plant disease classifier",
description="Detect diseases in beans using images of leaves",
)
interface.launch()