bears / app.py
jaimetorre's picture
Load model directly from hugging face.
6ec03a7
raw
history blame contribute delete
718 Bytes
from fastai.vision.all import *
import gradio as gr
from fastai.learner import load_learner
from huggingface_hub import from_pretrained_fastai
import warnings
warnings.filterwarnings("ignore", category=UserWarning, module="fastai.learner")
learn = from_pretrained_fastai("jaimetorre/bears")
categories = ('Black', 'Grizzly', 'Teddy')
def classify_bear(image):
pred, pred_idx, probs = learn.predict(image)
return dict(zip(categories, map(float, probs)))
image = gr.Image(height=192, width=192)
label = gr.Label(num_top_classes=3)
examples = ['bear1.jpeg', 'bear2.jpeg', 'bear3.jpeg']
demo = gr.Interface(fn=classify_bear, inputs=image,
outputs=label, examples=examples)
demo.launch()