leaf-classifier / app.py
Kavindu99's picture
Add application
2b9eeb6
raw
history blame
847 Bytes
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
import gradio as gr
dataset = datasets.load_dataset("beans")
extractor = AutoFeatureExtractor.from_pretrained("Kavindu99/leaf-classifier")
model = AutoModelForImageClassification.from_pretrained("Kavindu99/leaf-classifier")
labels = dataset['train'].features['labels'].names
def classify(im):
features = feature_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', examples=['sample-img.png'],title="Leaf Classifier")
interface.launch(debug=True)