File size: 1,370 Bytes
8cd7bab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
#!/usr/bin/env python
# coding: utf-8
#%reload_ext autoreload
#%autoreload 2
#%matplotlib inline
#!pip install fastai --upgrade 
#!pip install voila
#!jupyter serverextension enable --sys-prefix voila
#!pip install gradio

from fastai import *
from fastai.vision import *
from fastai.vision.all import *
from fastai.metrics import error_rate, accuracy
from fastai.imports import *
import gdown
import gradio as gr
from gradio.themes.base import Base

## Export the trained ResNet classifer model 
path = Path()
learn_inf = load_learner(path/'export.pkl')
learn_inf.dls.vocab
image = gr.Image(shape=(180,180))

## Define predicting action
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn_inf.predict(img)
    return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'

## Define title, description and emoji
note_text = '\U00002728' + 'This plant disease detector targets on diagnosing the leaves disease of fruit and vegetables. Upload the leaf picture here! ' + '\U0001FA84'

## Set Gradio interface 
gr_interface = gr.Interface(fn=predict, inputs=gr.Image(shape=(180, 180)),outputs=gr.Label(num_top_classes=len(learn_inf.dls.vocab)), interpretation="default",title = '\U0001F31D'+'Plant Disease Detector'+'\U0001FAB4',description = note_text, theme='gradio/seafoam')

## Use interface launch
gr_interface.launch(share=True)