workspace / app (1).py
FaustWarrior's picture
Upload 2 files
28de10f
raw
history blame contribute delete
No virus
1.6 kB
# 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)