File size: 633 Bytes
295cafb 7fe0013 6d9ffdf 7fe0013 c819b89 8c1392a 166e611 8c1392a 2f3d61d 8c1392a 2f3d61d 3ddd113 166e611 2f3d61d 166e611 2f3d61d |
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 |
import timm
import gradio as gr
from fastai.vision.all import *
learn = load_learner('cat.pkl')
labels = learn.dls.vocab
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))}
images = gr.inputs.Image(shape=(300, 300))
outputs = gr.outputs.Label(num_top_classes=3)
examples = ['british-shorthair.jpg',
'maine-coon.jpg', 'european-shorthair.jpg']
interface = gr.Interface(fn=classify_image, inputs=images,
outputs=outputs, examples=examples)
interface.launch(inline=False)
|