Spaces:
Runtime error
Runtime error
File size: 1,089 Bytes
fe31411 5dd3b71 fe31411 5dd3b71 fe31411 5dd3b71 fe31411 5dd3b71 fe31411 5dd3b71 fe31411 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# AUTOGENERATED! DO NOT EDIT! File to edit: 02_spider_deploy.ipynb.
# %% auto 0
__all__ = ['repo_id', 'learn', 'path', 'categories', 'image', 'output', 'examples', 'intf', 'second', 'classify_image']
# %% 02_spider_deploy.ipynb 1
from huggingface_hub import from_pretrained_fastai
import gradio as gr
# %% 02_spider_deploy.ipynb 2
repo_id = "xt0r3/spider-classifier"
learn = from_pretrained_fastai(repo_id)
# %% 02_spider_deploy.ipynb 3
categories = learn.dls.vocab
# %% 02_spider_deploy.ipynb 4
def second(x):
a, b = x
return b
def classify_image(img):
image = Image.fromarray(img)
image.thumbnail(size=(224,224))
img = np.asarray(img)
ans,idx,preds = learn.predict(img)
results = zip(categories, map(float, preds))
results = sorted(results, key=second, reverse=True)
return dict(results[:10])
# %% 02_spider_deploy.ipynb 6
image = gr.inputs.Image()
output = gr.outputs.Label()
examples = ["data/spider1.jpg", "data/spider2.jpg"]
intf = gr.Interface(fn=classify_image, inputs=image, outputs=output, examples=examples)
intf.launch(inline=False)
|