srishti-hf1110's picture
Update app.py
6cb0ee4
raw
history blame
1.12 kB
# -*- coding: utf-8 -*-
"""app
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1XX8pCT291obpzL4fc1vu5L_HTG027lle
"""
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
dataset = 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 = 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
interface = gr.Interface(classify, inputs='image', outputs='label', title='Bean plant disease classifier', description='Detect diseases in beans leaves using their images.')
interface.launch(debug=False)