File size: 1,546 Bytes
8138129
 
 
 
 
 
3228ab0
 
 
 
 
 
 
 
8138129
 
3228ab0
8138129
 
 
 
3228ab0
 
8138129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from huggingface_hub import HfApi, create_repo
import os
import sys

def create_and_push_space():
    try:
        # Get Hugging Face token from environment
        hf_token = os.environ.get("HF_TOKEN")
        if not hf_token:
            print("Error: HF_TOKEN environment variable not set")
            print("Please set your Hugging Face token as an environment variable:")
            print("export HF_TOKEN=your_token_here")
            sys.exit(1)
            
        print("Creating Space...")
        # Create the space
        api = HfApi(token=hf_token)
        repo_url = create_repo(
            repo_id="xingqiang/radar-analysis",
            repo_type="space",
            space_sdk="gradio",
            private=False,
            token=hf_token
        )
        print(f"Space created successfully at: {repo_url}")
        
        print("\nInitializing git repository...")
        commands = [
            "git init",
            "git add .",
            'git commit -m "Initial commit"',
            f"git remote add space {repo_url}",
            "git push --force space main"
        ]
        
        for cmd in commands:
            print(f"\nExecuting: {cmd}")
            result = os.system(cmd)
            if result != 0:
                print(f"Error executing command: {cmd}")
                sys.exit(1)
        
        print("\nSpace setup completed successfully!")
        
    except Exception as e:
        print(f"Error: {str(e)}")
        sys.exit(1)

if __name__ == "__main__":
    create_and_push_space()