Spaces:
Runtime error
Runtime error
| import datasets | |
| import torch | |
| from transformers import AutoFeatureExtractor, AutoModelForImageClassification | |
| description = 'Upload a picture of your bean plant to determine if they are healthy or diseased' | |
| title = 'Bean Plant Disease Classifier' | |
| examples = ['images/bean_1.png', 'images/bean_2.png', 'images/bean_3.jpg' ] | |
| dataset = datasets.load_dataset('beans') | |
| feature_extractor = AutoFeatureExtractor.from_pretrained('saved_model_files') | |
| model = AutoModelForImageClassification.from_pretrained('saved_model_files') | |
| 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 | |
| import gradio as gr | |
| interface = gr.Interface( | |
| classify, | |
| inputs='image', | |
| outputs='label', | |
| title=title, | |
| description=description, | |
| examples=examples | |
| ) | |
| interface.launch(debug=True) | |