Spaces:
Sleeping
Sleeping
File size: 1,248 Bytes
32fcae2 af0251b c67444b 9140899 6cb0ee4 787a489 6cb0ee4 9e49044 50ba0a4 af0251b 9e49044 32fcae2 4ccfdd0 32fcae2 |
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 |
# -*- coding: utf-8 -*-
"""app
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1XX8pCT291obpzL4fc1vu5L_HTG027lle
"""
import gradio as gr
import torch
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
dataset = datasets.load_dataset("beans") # This should be the same as the first line of Python code in this Colab notebook
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
labels = dataset['train'].features['labels'].names
def classify(im):
features = extractor(im, return_tensors='pt')
with torch.no_grad():
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', title='Bean plant disease classifier', description='Detect diseases in beans leaves using their images.', examples=['bean-plant-example.jpeg', 'non-bean-leaf-example.jpeg'])
interface.launch(debug=False) |