import gradio as gr
from fastai.vision.all import *
import skimage
learn = load_learner('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 trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
examples = ['cat.jpg']
interpretation='default'
enable_queue=True
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
It seems that you have an issue with your Learner so you need to check your model.pkl, can you post the code used to create that? It seems that you have an issue with the is_cat function.
I’ve tried creating a new space with a new model but I get this error message each time and I’m unable to push my repo onto huggingfaces. Any idea why I’m getting this error message? I’ve spent several hours but still haven’t been able to resolve this
Uploading LFS objects: 100% (1/1), 47 MB | 2.2 MB/s, done.
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 2.69 MiB | 960.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
remote: e[31m-------------------------------------------------------------------------e[0m
remote: e[31mYour push was rejected because it contains binary files.e[0m
remote: e[31mPlease use https://git-lfs.github.com/ to store binary files.e[0m
remote: e[31mSee also: https://hf.co/docs/hub/repositories-getting-started#terminale[0m
remote: e[31me[0m
remote: e[31mOffending files:e[0m
remote: e[31m - siamese.jpg (ref: refs/heads/main)e[0m
remote: e[31m-------------------------------------------------------------------------e[0m
To https://huggingface.co/spaces/hamzautd7/abc
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://huggingface.co/spaces/hamzautd7/abc'
you need to install git-lfs git lfs install or just upload your file through the website (not with the command line).
It’s better to create a new space again and do every step from the beginning.
Also you must include a file named requirements.txt containing the imports you need for example:
I already initialised git lfs with github desktop and included a requirements file but I get this error. I have tried creating a new space and doing everything from the start but I get this error
Update: changing the app.py to this worked but I had to upload the files via the website. git LFS would not work no matter what I did even though it was working yesterday. Can’t understand what changed. Followed every tutorial lol. Even deleted my huggingface account
There seems to be a bug with git lfs, that’s why I told you to repeat every step from scratch and upload only via the website. Glad you solved your problem!
For labelling you’re using is_cat function. When you export your model, you don’t export the functions used by the model, so you need to add an is_cat function to app.py
Is anyone able to get the Jupyter notebooks to work locally on Mac? I have fastbook already installed on my machine and I cannot seem to import it. After watching the lesson I got worried about the different python environments for Mac/Unix systems. If the setup script got installed correctly will I not have to worry about the notebooks using the system default python?
If fastbook is indeed installed, it’s probably installed in a different environment from which you are running jupyter lab.
The easiest way to manage environments on a local machine is to use something like conda or mamba. You need to make sure that you run jupyter from the same environment as where you installed fastai, fastbook or any other dependency you want to use in your notebooks.
Hi guys , I am able to deploy my app using Hugging face spaces but when I click the “Use via API” option a blank screen appears. It would be great if someone can let me know if they have encountered the same issue , Thanks.