File size: 1,164 Bytes
3106870
 
f8ab9a2
 
3106870
f8ab9a2
3106870
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
import datasets
import torch
import gradio as gr

from transformers import AutoFeatureExtractor, AutoModelForImageClassification

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


Instruction = "Submit leaf images"
title="Bean leaf disease classification demo"
description = "classification of leaves by uploading an image"


interface = gr.Interface(
    classify,
    interpretation="default",
    inputs='image',
    outputs='label',
    instructuction = Instruction,
    title = title,
    description = description,
    examples=["image1.png",
              "image2.png",
              "image3.png"]
    )

interface.launch(debug=True)