Huggingface spaces not updating packages from requirements.txt

I created the following Space (Authorship Obfuscation - a Hugging Face Space by hallisky; files here hallisky/authorship-obfuscation at main) using gradio. It was working well, and I decided to expand the app and tried to add from transformers import AutoTokenizer to my app.py. I also added a requirements.txt in the root folder which has transformers==4.41.0 in it.

However, when I factory rebuild this app, I get the following error

===== Application Startup at 2024-06-18 23:55:09 =====

Traceback (most recent call last):
  File "/home/user/app/app.py", line 1, in <module>
    from transformers import AutoTokenizer
ModuleNotFoundError: No module named 'transformers'
=== Application stopped (exit code: 1) at 2024-06-18 23:55:17.611578322 UTC ===

I’m not sure why this is happening. I tried deleting and remaking the file but still have the same issue. Could anyone point me to where I might have a mistake? Thanks for the help!

Hi @hallisky , did you find a solution for that issue? I’m facing the same problem. Factory rebuild doesn’t install the requirements.txt file.

I installed it manually in the vscode terminal with pip install -r requirements.txt and it works. But the same issue happens again when the server goes to sleep mode and then tries to restart.

1 Like

Hi @Yersel, I did not find a solution myself for this issue. I ended up going back-and-forth over email with the huggingface support trying to explain my solution. After a long thread, it started working again - but they never told me what the issue was. I assume they were able to correct something manually behind the scenes.

I recommend emailing them so they can try to fix it manually. Please let me know if you find out what the underlying issue is as well!

1 Like

Hi @hallisky , thanks for your reply. I tried to find support from HF, but as I read, this in only from Enterprise accounts. For now, the temporary solution I found is to add this code at the beginning of the app.py:

import os
import subprocess

def install(package):
    subprocess.check_call([os.sys.executable, "-m", "pip", "install", package])

install("transformers")

With that, I forced the code to check the installation of the transformer, and if it isn’t installed, it should install it before running the rest of the code. Hopefully later, we can find an official response from HF of what is the root cause of this issue.

2 Likes