Spaces:
Runtime error
Runtime error
#!/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) | |