Dharma20's picture
Upload 11 files
3240e8b verified
raw
history blame contribute delete
931 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../hugging-space-model-app.ipynb.
# %% auto 0
__all__ = ['learn', 'labels', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
# %% ../hugging-space-model-app.ipynb 4
from fastai.vision.all import *
import gradio as gr
# %% ../hugging-space-model-app.ipynb 5
def is_cat(x): return x[0].isupper()
# %% ../hugging-space-model-app.ipynb 7
learn = load_learner('model.pkl')
# %% ../hugging-space-model-app.ipynb 9
labels = ['Dog','Cat']
def classify_image(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# %% ../hugging-space-model-app.ipynb 11
image = gr.components.Image()
label = gr.components.Label(show_label=True)
examples = ['dog.jpg','cat.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)