If it works in Colab, then you’re probably just failing to pass the token. In that case, set the HF_TOKEN environment variable or write login() in the Python code to be sure. Don’t forget to install the library beforehand.
HF_TOKEN
login()
pip install -U huggingface_hub