My space include use of a Google API json file. Because it contains the Google credentials, of course it is not good to make a visible like other files like the app.py.
So, how do I make this file inaccessable to others? Or, is there any place on Huggingface where I can set this Secret File and load it in my app codes?
Thanks for all.
Bests.
Hello,
I know it’s an old question, but I hope my answer will help someone.
Actually, I had the same issue, and here how to solve it :
- Make all your JSON file into 1 line
- Create a new secret in your space, (see how to do it here
https://huggingface.co/docs/hub/spaces-overview#managing-secrets
) and put the 1 line JSON into the secret’s value - Use the env variable in your code using
conf = os.getenv('GOOGLE_SHEET_CREDENTIALS')
- Call ServiceAccountCredentials like that
dict = json.loads(conf)
creds = ServiceAccountCredentials._from_parsed_json_keyfile(dict, scope)
client = gspread.authorize(creds)
# then use your code as before to do whatever with your google sheet
Here, we convert the str
env variable to a dictionary. Make sure to import json
lib
1 Like
Make all your JSON file into 1 line
I think it is an excellent method.
Using Secrets in Spaces is a reliable way to use credentials in HF, but it is quite unusual to have a single string of files streamed into it.
Even if you were to convert it back to a JSON file, it would be difficult for users to access if the file was generated after Spaces was launched.
The recommended way is to use secrets in Spaces: Spaces Overview