"""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()