Spaces:
Runtime error
Runtime error
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) |