Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from fastbook import * | |
| from fastai.vision.widgets import * | |
| from IPython.display import display | |
| # learn_inf = load_learner('export.pkl') | |
| # lbl_pred = widgets.Label() | |
| # # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}' | |
| # out_pl = widgets.Output() | |
| # btn_upload = widgets.FileUpload() | |
| # # VBox([widgets.Label('Select your bear!'), | |
| # # btn_upload, btn_run, out_pl, lbl_pred]) | |
| # # def greet(name): | |
| # # return "Hello " + name + "!!" | |
| # def on_click_classify(picture): | |
| # out_pl = widgets.Output() | |
| # img = PILImage.create(picture) | |
| # out_pl.clear_output() | |
| # with out_pl: display(img.to_thumb(128,128)) | |
| # pred,pred_idx,probs = learn_inf.predict(img) | |
| # print('pred,pred_idx,probs', pred,pred_idx,probs) | |
| # lbl_pred.value = f'Prediction: {pred};\n Probability: {probs[pred_idx]:.04f}' | |
| # return lbl_pred.value | |
| learn = load_learner('export.pkl') | |
| categories = ('Hot Dog','No Hot Dog') | |
| def on_click_classify(img): | |
| pred,pred_idx,probs = learn.predict(img) | |
| return dict(zip(categories, map(float,probs))) | |
| image = gr.Image() | |
| label = gr.Label() | |
| examples = ['hot_dog.jpg', 'no_hot_dog.jpg', 'jian_yang.jpg'] | |
| iface = gr.Interface(fn=on_click_classify, inputs=image, outputs=label, examples=examples) | |
| iface.launch() | |