| |
|
| | """
|
| | Fresh deployment script - creates a new HF Space from scratch
|
| | """
|
| |
|
| | import os
|
| | import subprocess
|
| | from pathlib import Path
|
| |
|
| | def run_command(cmd):
|
| | """Run a command and return the result"""
|
| | try:
|
| | result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
| | if result.returncode != 0:
|
| | print(f"Error: {result.stderr}")
|
| | return False
|
| | print(result.stdout)
|
| | return True
|
| | except Exception as e:
|
| | print(f"Exception: {e}")
|
| | return False
|
| |
|
| | def deploy_fresh():
|
| | """Deploy to a fresh HF Space"""
|
| | hf_token = os.getenv('HF_TOKEN')
|
| | if not hf_token:
|
| | print("HF_TOKEN not set. Please run:")
|
| | print("set HF_TOKEN=your_huggingface_token_here")
|
| | return False
|
| |
|
| | print("Creating fresh HF Space deployment...")
|
| |
|
| |
|
| | deploy_script = f'''
|
| | from huggingface_hub import HfApi
|
| |
|
| | api = HfApi(token="{hf_token}")
|
| |
|
| | # Get username first
|
| | try:
|
| | user_info = api.whoami()
|
| | username = user_info["name"]
|
| | print(f"Username: {{username}}")
|
| | except Exception as e:
|
| | print(f"Could not get username: {{e}}")
|
| | username = "gsstec" # fallback
|
| |
|
| | repo_id = f"{{username}}/tec-app"
|
| | print(f"Creating space: {{repo_id}}")
|
| |
|
| | try:
|
| | # Create the space
|
| | api.create_repo(
|
| | repo_id=repo_id,
|
| | repo_type="space",
|
| | space_sdk="docker",
|
| | exist_ok=True,
|
| | private=False
|
| | )
|
| |
|
| | print("Space created successfully!")
|
| | print("Uploading files...")
|
| |
|
| | # Upload files
|
| | api.upload_folder(
|
| | folder_path=".",
|
| | repo_id=repo_id,
|
| | repo_type="space",
|
| | ignore_patterns=[".git", "__pycache__", "*.pyc", "temp_deploy.py", "deploy_fresh.py", "redeploy.py"]
|
| | )
|
| |
|
| | print(f"Successfully deployed to https://huggingface.co/spaces/{{repo_id}}")
|
| | print("Your app will be available in a few minutes!")
|
| | print("The Docker container will build and start automatically.")
|
| |
|
| | except Exception as e:
|
| | print(f"Deployment failed: {{e}}")
|
| | import traceback
|
| | traceback.print_exc()
|
| | '''
|
| |
|
| | with open('temp_deploy.py', 'w') as f:
|
| | f.write(deploy_script)
|
| |
|
| | success = run_command("python temp_deploy.py")
|
| |
|
| |
|
| | if Path('temp_deploy.py').exists():
|
| | Path('temp_deploy.py').unlink()
|
| |
|
| | return success
|
| |
|
| | if __name__ == "__main__":
|
| | print("Fresh HF Space Deployment")
|
| | print("=" * 25)
|
| |
|
| | if deploy_fresh():
|
| | print("Deployment completed!")
|
| | else:
|
| | print("Deployment failed!") |