File size: 3,443 Bytes
5a72b92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import subprocess
import sys
from pathlib import Path

try:
    from huggingface_hub import HfApi
except ImportError:
    print("ERROR: huggingface_hub not installed. Run: pip install huggingface_hub")
    sys.exit(1)


REPO_ROOT = Path(__file__).parent.resolve()
GITHUB_REPO = "https://github.com/yummyfiles/Project-Bob.git"
HF_REPO_ID = "yummyfiles/Bob"
COMMIT_MSG = "feat: deploy high-contrast stark UI"


def run_cmd(cmd: str, cwd: Path = None) -> subprocess.CompletedProcess:
    print(f"> {cmd}")
    result = subprocess.run(cmd, shell=True, cwd=cwd or REPO_ROOT, capture_output=True, text=True)
    if result.stdout:
        print(result.stdout.strip())
    if result.stderr:
        print(result.stderr.strip(), file=sys.stderr)
    if result.returncode != 0:
        raise subprocess.CalledProcessError(result.returncode, cmd, result.stdout, result.stderr)
    return result


def deploy_github():
    print("\n=== GITHUB DEPLOYMENT ===")
    if not (REPO_ROOT / ".git").exists():
        run_cmd("git init")
    run_cmd("git checkout -B main")
    run_cmd('git config user.email "project-bob@local"')
    run_cmd('git config user.name "Project Bob"')
    result = subprocess.run("git remote get-url origin", shell=True, cwd=REPO_ROOT, capture_output=True, text=True)
    if result.returncode != 0 or not result.stdout.strip():
        run_cmd(f"git remote add origin {GITHUB_REPO}")
    else:
        run_cmd(f"git remote set-url origin {GITHUB_REPO}")
    run_cmd("git add index.html app.js dataset.jsonl colab_training_notebook.py push_assets.py")
    commit_result = subprocess.run(f'git commit -m "{COMMIT_MSG}"', shell=True, cwd=REPO_ROOT, capture_output=True, text=True)
    if commit_result.returncode != 0:
        if "nothing to commit" in commit_result.stdout:
            print("No changes to commit.")
        else:
            print(commit_result.stderr.strip(), file=sys.stderr)
            raise subprocess.CalledProcessError(commit_result.returncode, f'git commit -m "{COMMIT_MSG}"', commit_result.stdout, commit_result.stderr)
    else:
        print(commit_result.stdout.strip())
    try:
        run_cmd("git push --force origin main")
        print("GitHub deployment complete.")
    except subprocess.CalledProcessError as e:
        if "Repository not found" in str(e.stderr):
            print("\nERROR: GitHub repository 'yummyfiles/Project-Bob' not found.")
            print("Create it first at: https://github.com/new")
            print("Repository name: Project-Bob")
            print("Owner: yummyfiles")
        raise


def upload_huggingface():
    print("\n=== HUGGING FACE UPLOAD ===")
    try:
        api = HfApi()
        api.upload_folder(
            folder_path=str(REPO_ROOT),
            repo_id=HF_REPO_ID,
            repo_type="model",
            ignore_patterns=[".git", "__pycache__", "*.pyc"],
        )
        print(f"Uploaded to https://huggingface.co/{HF_REPO_ID}")
    except Exception as e:
        if "401" in str(e) or "unauthorized" in str(e).lower() or "token" in str(e).lower():
            print("ERROR: Please run 'huggingface-cli login' in your terminal and paste your Hugging Face write-access token before running this script again.")
        else:
            print(f"Upload failed: {e}")
        sys.exit(1)


def main():
    deploy_github()
    upload_huggingface()
    print("\nAll assets deployed successfully.")


if __name__ == "__main__":
    main()