Unable to push pkl file to Hugging Face spaces repo & missing module errors

I’m trying to deploy my working model into an online application in the Hugging Face spaces. I have a git repo with my export.pkl, 2 image files for testing (one jpg and one avif) and the app.py which contains the following code:

AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).

#all_ = [‘is_cat’, ‘learn’, ‘classify_image’, ‘categories’, ‘image’, ‘label’, ‘examples’, ‘intf’] ← unapplicable

Cell

import fastbook
from fastbook import *
from fastai.vision.all import *
import gradio as gr

#def is_cat(x): return x[0].isupper() ← unapplicable

Cell

learn = load_learner(‘export.pkl’)

Cell

categories = (‘cup filled with water’, ‘cup filled with coffee’) # ← changed
def classify_image(img):
pred,idx,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))

Cell

image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
examples = [‘cup_with_water.avif’, ‘cup_with_coffee.jpg’] # ← changed

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)

This code has been taken directly from Jeremy’s app.py from lesson 2’s lecture video, except that ive commented out lines that techincally wouldnt apply to my model (im not using a dog vs cats classifier) whihc ive also written with “<-- unapplicable” at the end, and also tweaked other lines to match my environment (line which ive ended with “<-- changed”). the rest has stayed exactly the same, and i get 2 issues when i try to git push these 4 files onto HF:

(1) when i git push after comitting the pkl file, im told im pushing too many bytes, my file size is too large and the push is canceled.

(2) when i git push without the pkl file (so only push the 2 test images & app.py, im given the error: "No module named ‘fastbook’ "). I added the fastbook import also as a consequence of an earlier error, when i only had 2 imports at the top (so the fastai.vision.all & gradio imports) which gave me an exactly equal error except this time not recognizing the fastai import.

Can anyone help me fix this issue? Thanks a lot.

did you get an answer?

In case you are still dealing with this issue:

(1) try to use git lfs, an example of which can be found in this blog post

(2) is fastbook in your requirements.txt file? If not, you will want to add it there so that the HF spaces environment installs it. Looking at the code you have provided, I think you can remove the fastbook imports without losing functionality.