catacomb-oracle / redeploy.py
josephrw's picture
Upload folder using huggingface_hub
8a4b81d verified
Raw
History Blame Contribute Delete
1.95 kB
#!/usr/bin/env python3
"""Redeploy fixed docs to HF Space josephrw/catacomb-oracle-v7."""
import os
import shutil
import subprocess
import sys
import tempfile
SPACE = "josephrw/catacomb-oracle-v7"
REPO_URL = f"https://huggingface.co/spaces/{SPACE}"
SOURCE = "/Users/alep/Downloads/02_AI_Agents/collateral-launcher/hf-space"
def run(cmd, cwd=None):
print(f">>> {cmd}")
r = subprocess.run(cmd, shell=True, cwd=cwd, capture_output=True, text=True)
if r.stdout:
print(r.stdout)
if r.stderr:
print(r.stderr, file=sys.stderr)
if r.returncode != 0:
print(f"EXIT {r.returncode}", file=sys.stderr)
return r.returncode
def main():
with tempfile.TemporaryDirectory() as tmp:
repo = os.path.join(tmp, "repo")
print(f"Cloning {REPO_URL} ...")
if run(f"git clone {REPO_URL} {repo}") != 0:
print("Clone failed.")
return 1
# Copy updated files
for item in os.listdir(SOURCE):
if item.startswith(".") or item in ("venv", "__pycache__", "deploy.sh", "deploy_manual.py", "redeploy.py"):
continue
src = os.path.join(SOURCE, item)
dst = os.path.join(repo, item)
if os.path.isdir(src):
if os.path.exists(dst):
shutil.rmtree(dst)
shutil.copytree(src, dst)
else:
shutil.copy2(src, dst)
# Commit and push
run("git add -A", cwd=repo)
run('git commit -m "Fix swagger domain: replace placeholders with actual HF Space URL"', cwd=repo)
ret = run("git push origin main", cwd=repo)
if ret == 0:
print(f"\nDeployed to https://huggingface.co/spaces/{SPACE}")
else:
print("\nPush failed. You may need to authenticate with Hugging Face.")
print("Run: hf auth login")
return ret
if __name__ == "__main__":
sys.exit(main())