Spaces:
Runtime error
Runtime error
FaustWarrior
commited on
Commit
•
e9e8361
1
Parent(s):
28de10f
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['plt', 'learn', 'interface_options', 'demo', 'label_func', 'predict']
|
5 |
+
|
6 |
+
# %% ../app.ipynb 2
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio
|
9 |
+
#import pathlib
|
10 |
+
#temp = pathlib.PosixPath
|
11 |
+
#pathlib.PosixPath = pathlib.WindowsPath
|
12 |
+
import pathlib
|
13 |
+
plt = platform.system()
|
14 |
+
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath
|
15 |
+
|
16 |
+
def label_func(filepath):
|
17 |
+
return filepath.parent.name
|
18 |
+
|
19 |
+
# %% ../app.ipynb 3
|
20 |
+
learn = load_learner('model.pkl')
|
21 |
+
|
22 |
+
# %% ../app.ipynb 5
|
23 |
+
def predict(image):
|
24 |
+
img = PILImage.create(img)
|
25 |
+
_pred, _pred_w_idx, probs = learn.predict(img)
|
26 |
+
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
|
27 |
+
return labels_probs
|
28 |
+
|
29 |
+
# %% ../app.ipynb 6
|
30 |
+
interface_options = {
|
31 |
+
"title": "KhetAi",
|
32 |
+
"description": "An web app that predicts the disease based on Image",
|
33 |
+
"interpretation": "default",
|
34 |
+
"layout": "horizontal",
|
35 |
+
"allow_flagging": "never",
|
36 |
+
"enable_queue": True
|
37 |
+
}
|
38 |
+
|
39 |
+
"""demo = gradio.Interface(fn=predict,
|
40 |
+
inputs=gradio.inputs.Image(shape=(512, 512)),
|
41 |
+
outputs=gradio.outputs.Label(num_top_classes=5),
|
42 |
+
**interface_options)"""
|
43 |
+
|
44 |
+
demo = gradio.Interface(fn=predict,
|
45 |
+
inputs="image",
|
46 |
+
outputs="label")
|
47 |
+
|
48 |
+
# demo_options = {
|
49 |
+
# "inline": True,
|
50 |
+
# "inbrowser": True,
|
51 |
+
# "share": True,
|
52 |
+
# "show_error": True,
|
53 |
+
# "server_name": "0.0.0.0",
|
54 |
+
# "server_port": 5000,
|
55 |
+
# "enable_queue": True,
|
56 |
+
# }
|
57 |
+
|
58 |
+
#demo.launch(**demo_options)
|
59 |
+
demo.launch(share=True)
|