File size: 874 Bytes
3aac214
47d9766
3aac214
 
47d9766
3aac214
47d9766
11ba4f9
3aac214
11ba4f9
3aac214
 
 
 
 
 
 
 
 
 
 
 
 
47d9766
 
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
import datasets
import gradio as gr
import torch
from transformers import AutoFeatureExtractor, AutoModelForImageClassification

dataset = datasets.load_dataset('beans')

extractor = AutoFeatureExtractor.from_pretrained("tadeyina/BeanLeaf")

model = AutoModelForImageClassification.from_pretrained("tadeyina/BeanLeaf")

labels = dataset['train'].features['labels'].names

def classify(im):
  features = 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 using images of leaves')

interface.launch()