Spaces:
Paused
Paused
| import os | |
| from pathlib import Path | |
| def main(): | |
| """ | |
| Deploy this folder to a Hugging Face Space. | |
| Usage: | |
| HF_TOKEN=... python scripts/deploy_hf_space.py <space_id> | |
| Example: | |
| HF_TOKEN=... python scripts/deploy_hf_space.py ghostof0days/finagents-demo | |
| """ | |
| try: | |
| from huggingface_hub import HfApi, upload_folder | |
| except Exception as e: | |
| raise SystemExit( | |
| "Missing dependency: huggingface-hub. Install it first (pip install huggingface-hub)." | |
| ) from e | |
| token = os.getenv("HF_TOKEN") | |
| if not token: | |
| raise SystemExit("Missing HF_TOKEN env var (do not hardcode it).") | |
| import sys | |
| if len(sys.argv) != 2: | |
| raise SystemExit("Usage: HF_TOKEN=... python scripts/deploy_hf_space.py <space_id>") | |
| space_id = sys.argv[1].strip() | |
| if "/" not in space_id: | |
| raise SystemExit("space_id must look like '<org-or-user>/<space-name>'") | |
| root = Path(__file__).resolve().parents[1] | |
| api = HfApi(token=token) | |
| # Create space if missing (gradio sdk). | |
| try: | |
| api.space_info(space_id) | |
| except Exception: | |
| api.create_repo( | |
| repo_id=space_id, | |
| repo_type="space", | |
| space_sdk="gradio", | |
| private=False, | |
| exist_ok=True, | |
| ) | |
| ignore = [ | |
| ".env", | |
| "__pycache__", | |
| ".venv", | |
| "venv", | |
| ".git", | |
| ".pytest_cache", | |
| "node_modules", | |
| ] | |
| upload_folder( | |
| repo_id=space_id, | |
| repo_type="space", | |
| folder_path=str(root), | |
| ignore_patterns=ignore, | |
| commit_message="Deploy FinAgents demo", | |
| token=token, | |
| ) | |
| print(f"Deployed to https://huggingface.co/spaces/{space_id}") | |
| if __name__ == "__main__": | |
| main() | |