File size: 1,539 Bytes
622794b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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)