Spaces:
Runtime error
Runtime error
import gradio as gr | |
from fastai.vision.all import * | |
import skimage | |
import timm | |
# quick function to strip the leading ###. off the parent label name | |
def strip_parent_num(o): | |
#return parent_label(o).split('.')[1] | |
try: | |
r = parent_label(o).split('.')[1] | |
except IndexError: | |
r = parent_label(o) | |
return r | |
# load the model | |
learn = load_learner('birds-convnext_small_in22k.pkl') | |
#function to run the image through the model and get the prediction | |
labels = learn.dls.vocab | |
def predict(img): | |
img = PILImage.create(img) | |
pred,pred_idx,probs = learn.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
# Gradio customizations | |
title = 'Bird Identifier' | |
description = 'This model will predict the type of bird from an image.\n\nThe convnext_tiny_in22k model was refined using the CUB_200_2011 bird dataset.' | |
examples = ['cardinal1.jpg', 'crow.jpg'] | |
interpretation = 'default' | |
enable_queue = True | |
article = '''<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Learning from -> Gradio + HuggingFace Spaces: A Tutorial</a></p>''' | |
# Deploy gradio | |
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch() | |