File size: 1,101 Bytes
bd21bb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio
from fastai.vision.all import *

MODELS_PATH = Path('./models')
EXAMPLES_PATH = Path('./examples')

learn = load_learner(MODELS_PATH/'model.pkl')
labels = learn.dls.vocab

def gradio_predict(img):
    img = PILImage.create(img)
    _pred, _pred_idx, probs = learn.predict(img)
    labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
    return labels_probs

with open('gradio_article.md') as f:
    article = f.read()

interface_options = {
    "title": "Paddy Doctor: Paddy Disease Classification",
    "description": "Identify the type of disease present in paddy leaf images",
    "article": article,
    "examples" : [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()],
    "layout": "horizontal",
    "theme": "default",
}

demo = gradio.Interface(fn=gradio_predict,
                      inputs=gradio.inputs.Image(shape=(512, 512)),
                      outputs=gradio.outputs.Label(num_top_classes=5),
                      **interface_options)

launch_options = {
    "enable_queue": True,
    "share": False, 
}

demo.launch(**launch_options)