Spaces:
Runtime error
Runtime error
File size: 1,019 Bytes
8adccd0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import datasets
import gradio as gr
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
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
dataset = datasets.load_dataset('beans', 'full_size')
extractor = AutoFeatureExtractor.from_pretrained('saved_model_files')
model = AutoModelForImageClassification.from_pretrained('saved_model_files')
labels = dataset['train'].features['labels'].names
interface = gr.Interface(fn=classify, inputs=gr.Image(shape=(200, 200)), outputs=gr.outputs.Label(num_top_classes=3),
examples=['leaf1.png', 'leaf2.png'], title='Leaf Classification App', description='Check if the leaves of your plant are healthy!', flagging_dir='flagged_examples/')
interface.launch(debug=True) |