Spaces:
Runtime error
Runtime error
File size: 1,529 Bytes
018defe a852b94 a546e71 49c4209 018defe 7d29fab 018defe 167eb46 018defe 43c2f3b 714f6cb 43c2f3b 349dc93 714f6cb |
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 |
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
import gradio as gr
import torch
feature_extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
dataset = datasets.load_dataset("beans")
extractor = AutoFeatureExtractor.from_pretrained("capofwesh20/bean_leaf_classifier")
model = AutoModelForImageClassification.from_pretrained("capofwesh20/bean_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
sample_images=[['https://s3.amazonaws.com/moonup/production/uploads/1663933284359-611f9702593efbee33a4f7c9.png'],
['https://s3.amazonaws.com/moonup/production/uploads/1663933284374-611f9702593efbee33a4f7c9.png'],
['https://s3.amazonaws.com/moonup/production/uploads/1663933284412-611f9702593efbee33a4f7c9.png']]
title = 'Bean Leaf Classifier'
description = 'This model is trained for beans leaf classification but might give a false result on other leaves'
interface = gr.Interface(fn = classify, inputs = gr.Image(shape=(200, 200)), outputs= 'label',
title = title,
description = description,
examples=sample_images)
interface.launch()
|