What's the best way to let a Hugging Face Space pull a private Python library?
Say you have a Hugging Face Space that depends on a Python library that you host on GitHub in a private repository. Normally, you’d simply addgit+https://github.com/umarbutler/mylibrary.gitto yourrequirements.txtand then Hugging Face would automatically install the library on startup.If the repository is private, however, you need to authenticate to be able to pull the repository. So then you could dogit+https://${GIT_TOKEN}@github.com/umarbutler/mylibrary.gitand then addGIT_TOKENas a secret in your space, GIT_TOKEN being a personal access token. The problem is when you are trying to do this for an organisation and there is no guarantee that the employee who used their personal access token will always be there. What do you do in that case?
2024-11-24T11:56:25Z
It turns out what I suggested doesn’t even work unless you actually hardcode the tokenwhich is fine for a private space but really, it should be possible to this without hardcoding.
2024-11-24T12:44:38Z
Can’t we do something using the Secrets of Spaces?# last resort
import os
import subprocess
GIT_TOKEN = os.environ.get("GIT_TOKEN")
subprocess.run(f"pip install git+https://${GIT_TOKEN}@github.com/umarbutler/mylibrary.git", shell=True)
2024-11-24T13:06:44Z
Hmm… You’re right. It’s hacky, but at least it isn’t hard coding a token. Cheers.
2024-11-24T13:13:11Z
Sure. I’ve had a long break, and I don’t know any virtual environments other than HF… I’ve only recently started using Colab a little.So I don’t know if it’s strange or not.If there are functions that should naturally be there in other companies’ virtual environments that are not in HF’s VM, it would be helpful if you could request them. I can at least like your comments.huggingface.co@victor on Hugging Face: "🙋 Calling all Hugging Face users! We want to hear...We’re on a journey to advance and democratize artificial intelligence through open source and open science.
2024-11-28T06:34:40Z
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.