File size: 1,385 Bytes
e6404d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Cache HF token and push to HuggingFace Space.
Run:  python scripts\\hf_push.py
It will prompt for your token (input is hidden).
"""
import subprocess
import sys
import getpass

REPO_URL = "https://huggingface.co/spaces/ArtShumov/Whyx-PROmpTea"
WORKDIR = r"D:\Stable Diffusion\Development\Whyx-PROptimizer"


def main():
    token = getpass.getpass("HF Token (input hidden): ").strip()
    if not token:
        print("No token entered, aborting.")
        sys.exit(1)

    # Set remote URL with embedded token for auth
    auth_url = f"https://{token}@huggingface.co/spaces/ArtShumov/Whyx-PROmpTea"
    subprocess.run(["git", "remote", "set-url", "origin", auth_url], cwd=WORKDIR, check=True)
    print("Remote URL updated with token.")

    # Push
    result = subprocess.run(
        ["git", "push", "-u", "origin", "main"],
        capture_output=True, text=True, cwd=WORKDIR,
    )
    print(result.stdout)
    if result.returncode != 0:
        print("STDERR:", result.stderr)
        # Restore clean URL even on failure
        subprocess.run(["git", "remote", "set-url", "origin", REPO_URL], cwd=WORKDIR)
        sys.exit(result.returncode)

    # Restore clean URL (no token in remote)
    subprocess.run(["git", "remote", "set-url", "origin", REPO_URL], cwd=WORKDIR)
    print("Push succeeded! Remote URL restored (token removed).")


if __name__ == "__main__":
    main()