Spaces:
Build error
Build error
File size: 1,826 Bytes
c8189b0 0ae09f5 c8189b0 5d2db50 c8189b0 bf0d6f7 c8189b0 b243489 38d1864 b243489 c8189b0 |
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 33 34 35 36 |
import datasets
import gradio as gr
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
import torch
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
example_imgs = ["example_0.jpg", "example_1.jpg","example_2.jpg"]
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(fn = classify,
inputs="image",
outputs = "label",
title = "Plant Leaf Disease Classifier",
description = """Below is a simple app to detect Angular Leaf Spot and Bean Rust diseases on leaves.
Data was annotated by experts from the National Crops Resources Research Institute (NaCRRI)
in Uganda and collected by the Makerere AI research lab.
The model being used is a fine-tuned Vision Transformer, specifically beginning with [google/vit-base-patch16-224]
(https://huggingface.co/google/vit-base-patch16-224) and trained using the [beans](https://huggingface.co/datasets/beans) dataset.
This app was created in Abubakar Abid's 'Building End-to-End Vision Applications' course through CoRise.
""",
examples = example_imgs)
interface.launch(debug=True)
|