Spaces:
Paused
Paused
| from fastai.vision.all import * | |
| from fastai.learner import load_learner | |
| from huggingface_hub import from_pretrained_fastai, hf_hub_download | |
| import gradio as gr | |
| import skimage | |
| learn = load_learner('PetNet50.pkl') | |
| # learn = from_pretrained_fastai("kurianbenoy/course_v5_lesson2_pets_convnext_base_in22k") | |
| #learn = load_learner( | |
| # hf_hub_download("kurianbenoy/course_v5_lesson2_pets_convnext_base_in22k", "model.pkl") | |
| #) | |
| 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))} | |
| title = "Pet Breed Classifier" | |
| description = """ | |
| 🐶🐱 | |
| 🇬🇧 = A pet breed classifier (Dogs and Cats) trained on the Oxford Pets dataset using fastai. Created as a demo from the course by Jeremy Howard. | |
| For best results use photos of your pets. | |
| 🇪🇸 = Un clasificador de razas de mascotas (perros y gatos) entrenado en el dataset Oxford Pets. | |
| Usa fotos de tus mascotas para obtener la raza. | |
| 👨👨👧👦 CZDJ ❤️ | |
| """ | |
| article="<p style='text-align: center'><a href='https://course.fast.ai/' target='_blank'>Go to course!</a></p>" | |
| examples = ['siamese.jpg','pug.jpg'] | |
| gr.Interface(fn=predict, | |
| inputs=gr.Image(), | |
| outputs=gr.Label(num_top_classes=3), | |
| title=title, | |
| description=description, | |
| article=article, | |
| examples=examples).launch() | |