How to set a Secret File or set such file inaccessable to others
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.
2024-09-26T22:06:09Z
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 lineCreate a new secret in your space, (see how to do it herehttps://huggingface.co/docs/hub/spaces-overview#managing-secrets) and put the 1 line JSON into the secret’s valueUse the env variable in your code usingconf = os.getenv('GOOGLE_SHEET_CREDENTIALS')Call ServiceAccountCredentials like thatdict = 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 sheetHere, we convert thestrenv variable to a dictionary. Make sure to importjsonlib
2024-09-26T22:19:54Z
Make all your JSON file into 1 lineI 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.
2024-09-27T06:43:04Z
The recommended way is to use secrets in Spaces:Spaces Overview