File size: 2,655 Bytes
77e34fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
"""

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...")
    
    # Create deployment script
    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")
    
    # Cleanup
    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!")