File size: 1,069 Bytes
26eff3f
dfb2824
26eff3f
59d7497
26eff3f
4c7915f
26eff3f
59d7497
26eff3f
17ee78f
8c0d50a
17ee78f
 
8c0d50a
b65718e
26eff3f
3933122
26eff3f
 
ee94a17
3933122
 
26eff3f
 
 
 
 
b491c26
fb9dffa
26eff3f
 
4306b36
26eff3f
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
import gradio as gr
import torch
from huggingface_hub import from_pretrained_fastai
from pathlib import Path

examples = ["image_1.png", "image_2.png", "image_3.png", "image_4.png", "image_5.png"]
repo_id = "hugginglearners/grapevine_leaves_classification"
path = Path("./")

def get_y(r):
    return r["label"]
    
def get_x(r):
    return path/r["fname"]
    
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab

def inference(image):
    label_predict,_,probs = learner.predict(image)
    labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
    return labels_probs

gr.Interface(
    fn=inference,
    title="Grapevine leave image classification",
    description = "Predict which type of grapevine leave belong to Ak, Ala_Idris, Buzgulu, Dimnit, Nazli",
    inputs="image",
    outputs=gr.outputs.Label(num_top_classes=5, label='Prediction'),
    examples=examples,
    cache_examples=False,
    article = "Author: <a href=\"https://www.linkedin.com/in/vumichien/\">Vu Minh Chien</a>",
).launch(debug=True, enable_queue=True)