Lesson 2 Hugging Face spaces giving Fasttransform error

Error Description:

When running my app.py in my Hugging Face Space, I get the following runtime error:

===== Application Startup at 2025-10-22 17:41:38 =====
Traceback (most recent call last):
  File "/home/user/app/app.py", line 10, in <module>
    learn = load_learner('final_model.pkl')
  File "/usr/local/lib/python3.10/site-packages/fastai/learner.py", line 446, in load_learner
    try: res = torch.load(fname, map_location=map_loc, pickle_module=pickle_module)
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1025, in load
    return _load(opened_zipfile,
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1446, in _load
    result = unpickler.load()
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1439, in find_class
    return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'fasttransform'

What I’ve Tried So Far:

  1. Used the model .pkl exported from Google ColabColab notebook link – this failed with the same ModuleNotFoundError.

  2. Used my personal PC version of the .pkl file – same error persists.

  3. Retrained and exported a new model directly in WSL (Linux environment), ensuring compatibility – still got the same fasttransform error when loading the model in the HF Space.

  4. Checked dependencies and confirmed that fasttransform is not explicitly part of my code.

  5. Removed older .pkl files and tried using only the new one.

Additional Info:

  • The same Gradio interface works correctly when run in Jupyter Notebook locally.

  • The issue only occurs when running in Hugging Face Spaces.

Current Status:

The Space fails to load the model due to a missing fasttransform dependency during load_learner. This dependency is not present in my code, but the .pkl file seems to reference internal fastai transforms or legacy objects that were part of the original training environment, which aren’t available in the HF Space environment.