File size: 1,600 Bytes
e9e8361
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.

# %% auto 0
__all__ = ['plt', 'learn', 'interface_options', 'demo', 'label_func', 'predict']

# %% ../app.ipynb 2
from fastai.vision.all import *
import gradio 
#import pathlib
#temp = pathlib.PosixPath
#pathlib.PosixPath = pathlib.WindowsPath
import pathlib
plt = platform.system()
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath

def label_func(filepath):
    return filepath.parent.name

# %% ../app.ipynb 3
learn = load_learner('model.pkl')

# %% ../app.ipynb 5
def predict(image):
    img = PILImage.create(img)
    _pred, _pred_w_idx, probs = learn.predict(img)
    labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
    return labels_probs

# %% ../app.ipynb 6
interface_options = {
    "title": "KhetAi",
    "description": "An web app that predicts the disease based on Image",
    "interpretation": "default",
    "layout": "horizontal",
    "allow_flagging": "never",
    "enable_queue": True 
}

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

demo = gradio.Interface(fn=predict,
                      inputs="image",
                      outputs="label")

# demo_options = {
#     "inline": True,
#     "inbrowser": True,
#     "share": True,
#     "show_error": True,
#     "server_name": "0.0.0.0",
#     "server_port": 5000,
#     "enable_queue": True,
# }

#demo.launch(**demo_options)
demo.launch(share=True)