Spaces:
Sleeping
Sleeping
| 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() |