Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """Deploy CLIProxyAPI to Hugging Face Spaces""" | |
| from huggingface_hub import HfApi, create_repo, upload_folder, login | |
| import os | |
| # Login with token | |
| HF_TOKEN = os.environ.get("HF_TOKEN", "") | |
| if HF_TOKEN: | |
| login(token=HF_TOKEN) | |
| # Initialize API | |
| api = HfApi(token=HF_TOKEN if HF_TOKEN else None) | |
| # Get current user info | |
| try: | |
| user_info = api.whoami() | |
| username = user_info["name"] | |
| print(f"Logged in as: {username}") | |
| except Exception as e: | |
| print(f"Error: Not logged in to Hugging Face. Please run: huggingface-cli login") | |
| print(f"Details: {e}") | |
| exit(1) | |
| # Create the Space | |
| repo_id = f"{username}/CLIProxyAPI" | |
| print(f"Creating Space: {repo_id}") | |
| try: | |
| create_repo( | |
| repo_id=repo_id, | |
| repo_type="space", | |
| space_sdk="docker", | |
| exist_ok=True, | |
| private=False | |
| ) | |
| print(f"Space created/exists: https://huggingface.co/spaces/{repo_id}") | |
| except Exception as e: | |
| print(f"Error creating Space: {e}") | |
| exit(1) | |
| # Upload files | |
| print("Uploading files...") | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| try: | |
| api.upload_folder( | |
| folder_path=current_dir, | |
| repo_id=repo_id, | |
| repo_type="space", | |
| ignore_patterns=["*.py", ".git/*", "DEPLOY_GUIDE.md"] | |
| ) | |
| print(f"Files uploaded successfully!") | |
| print(f"\nYour Space URL: https://huggingface.co/spaces/{repo_id}") | |
| print(f"Direct access: https://{username}-cliproxyapi.hf.space") | |
| except Exception as e: | |
| print(f"Error uploading files: {e}") | |
| exit(1) | |