You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Tweaks to env vars in Spaces
I think this is clearer, and it will also prevent Python noobs like me from having to google how to read an env var!
* Update docs/hub/spaces-overview.md
* Apply suggestions from code review
Co-authored-by: Omar Sanseviero <[email protected]>
---------
Co-authored-by: Omar Sanseviero <[email protected]>
Variables are publicly accessible and viewable and will be automatically added to Spaces duplicated from your repository. They are exposed to your app as environment variables.
71
+
***Variables** if you need to store non-sensitive configuration values. They are publicly accessible and viewable and will be automatically added to Spaces duplicated from yours.
72
+
***Secrets** to store access tokens, API keys, or any sensitive values or credentials. They are private and their value cannot be read from the Space's settings page once set. They won't be added to Spaces duplicated from your repository.
71
73
72
-
For Static Spaces, they are available through client-side JavaScript in `window.huggingface.variables`.
73
74
74
-
For Docker Spaces, check out [environment management with Docker](./spaces-sdks-docker#secrets-and-variables-management).
75
+
Accessing secrets and variables is different depending on your Space SDK:
75
76
76
-
Secrets are private and their value cannot be retrieved once set. They won't be added to Spaces duplicated from your repository. The secrets will be exposed to your app with [Streamlit Secrets Management](https://blog.streamlit.io/secrets-in-sharing-apps/) if you use Streamlit, and as environment variables in other cases. For Docker Spaces, please check out [environment management with Docker](./spaces-sdks-docker#secrets-and-variables-management). Users are warned when our `Spaces Secrets Scanner`[finds hard-coded secrets](./security-secrets).
77
+
- For Static Spaces, both are available through client-side JavaScript in `window.huggingface.variables`
78
+
- For Docker Spaces, check out [environment management with Docker](./spaces-sdks-docker#secrets-and-variables-management)
79
+
- For Streamlit Spaces, secrets are exposed to your app through [Streamlit Secrets Management](https://blog.streamlit.io/secrets-in-sharing-apps/), and public variables are directly available as environment variables
80
+
81
+
For other Spaces, both are exposed to your app as environment variables. Here is a very simple example of accessing the previously declared `MODEL_REPO_ID` variable in Python (it would be the same for secrets):
82
+
```py
83
+
import os
84
+
print(os.getenv['MODEL_REPO_ID'])
85
+
```
86
+
87
+
Spaces owners are warned when our `Spaces Secrets Scanner`[finds hard-coded secrets](./security-secrets).
0 commit comments