File size: 556 Bytes
e0fbd62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
from fastai.vision.all import *
import timm.models.convnext
import pathlib

temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath

learn = load_learner('Dog-Classification/pets_model.pkl')

def classify_image(img):
    categories = learn.dls.vocab
    pred, idx, prob = learn.predict(tensor(img))
    d = [(v, k) for k, v in dict(zip(categories, map(float, prob))).items()]
    return f'{max(d)[1]}: {max(d)[0]:.04f}'

iface = gr.Interface(fn=classify_image, inputs=gr.inputs.Image(type="pil"), outputs="text")
iface.launch()