Download config.py from kberasneva/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/spaces/kberasneva/Final_Assignment_Template/resolve/main/config.py
- Command line
-
hf download hf://spaces/kberasneva/Final_Assignment_Template/config.py
-
curl -L -o config.py https://huggingface.co/spaces/kberasneva/Final_Assignment_Template/resolve/main/config.py
1.98 kB
| import os | |
| import dotenv | |
| from typing import Optional | |
| # Load environment variables from .env file if it exists | |
| dotenv.load_dotenv() | |
| def get_required_env(key: str, error_message: Optional[str] = None) -> str: | |
| """Get a required environment variable or raise a helpful error.""" | |
| value = os.getenv(key) | |
| if not value: | |
| api_instructions = { | |
| "GOOGLE_API_KEY": "1. Go to https://makersuite.google.com/app/apikey\n2. Create a new API key", | |
| "TAVILY_API_KEY": "1. Go to https://tavily.com/#pricing\n2. Sign up for an account\n3. Get your API key from the dashboard", | |
| "OAUTH_CLIENT_ID": "Enable OAuth in your Space by setting `hf_oauth: true` in the README.md Space metadata", | |
| "OAUTH_CLIENT_SECRET": "Enable OAuth in your Space by setting `hf_oauth: true` in the README.md Space metadata" | |
| } | |
| instructions = api_instructions.get(key, "Please obtain an API key from the service provider") | |
| default_message = ( | |
| f"{key} environment variable is not set.\n" | |
| f"Please create a .env file in the project root with:\n" | |
| f"{key}=your_{key.lower()}_here\n\n" | |
| f"If you don't have the credentials:\n" | |
| f"{instructions}\n" | |
| f"4. Add it to your .env file" | |
| ) | |
| raise ValueError(error_message or default_message) | |
| return value | |
| def is_running_in_space() -> bool: | |
| """Check if we're running in a Hugging Face Space.""" | |
| return bool(os.getenv("SPACE_ID")) | |
| # Required environment variables | |
| GOOGLE_API_KEY = get_required_env("GOOGLE_API_KEY") | |
| TAVILY_API_KEY = get_required_env("TAVILY_API_KEY") | |
| # OAuth is only required when running in a Space | |
| if is_running_in_space(): | |
| OAUTH_CLIENT_ID = get_required_env("OAUTH_CLIENT_ID") | |
| OAUTH_CLIENT_SECRET = get_required_env("OAUTH_CLIENT_SECRET") | |
| # Optional environment variables with defaults | |
| AGENT_MODEL_NAME = os.getenv("AGENT_MODEL_NAME", "gemini-2.0-flash") |