mipbkhn's picture
Publish
bd21bb6
raw
history blame contribute delete
No virus
1.1 kB
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)