Download deploy_new_space.py from cefrefdwe/warp-proxy-test-1769392021: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/cefrefdwe/warp-proxy-test-1769392021/resolve/main/deploy_new_space.py
- Command line
-
hf download hf://spaces/cefrefdwe/warp-proxy-test-1769392021/deploy_new_space.py
-
curl -L -o deploy_new_space.py https://huggingface.co/spaces/cefrefdwe/warp-proxy-test-1769392021/resolve/main/deploy_new_space.py
1.56 kB
| from huggingface_hub import HfApi | |
| import os | |
| import time | |
| api = HfApi() | |
| timestamp = int(time.time()) | |
| new_repo_id = f"cefrefdwe/warp-proxy-test-{timestamp}" | |
| token = os.environ.get('HF_TOKEN') | |
| print(f"Creating new space: {new_repo_id}") | |
| try: | |
| api.create_repo( | |
| repo_id=new_repo_id, | |
| repo_type="space", | |
| space_sdk="docker", | |
| private=False, | |
| token=token | |
| ) | |
| print(f"β Space created: {new_repo_id}") | |
| except Exception as e: | |
| print(f"β Creation failed: {e}") | |
| # If it fails, maybe it already exists, try to continue | |
| files = [ | |
| 'Dockerfile', | |
| 'warp_manager.py', | |
| 'supervisord.conf', | |
| 'worker.py', | |
| 'server.py', | |
| 'check_logs.py', | |
| 'monitor_status.py', | |
| 'requirements.txt', | |
| 'README.md', | |
| 'ip_pool.json' | |
| ] | |
| print(f"Uploading files to {new_repo_id}...") | |
| for file in files: | |
| try: | |
| path = os.path.join(os.getcwd(), file) | |
| api.upload_file( | |
| path_or_fileobj=path, | |
| path_in_repo=file, | |
| repo_id=new_repo_id, | |
| repo_type='space', | |
| token=token | |
| ) | |
| print(f"β Uploaded {file}") | |
| except Exception as e: | |
| print(f"β Failed to upload {file}: {e}") | |
| # Update monitor script with new repo ID | |
| monitor_script = "monitor_status.py" | |
| with open(monitor_script, "r") as f: | |
| content = f.read() | |
| import re | |
| new_content = re.sub(r'REPO_ID = ".*"', f'REPO_ID = "{new_repo_id}"', content) | |
| with open(monitor_script, "w") as f: | |
| f.write(new_content) | |
| print(f"β Updated {monitor_script} with new REPO_ID") | |