Spaces:
Paused
Paused
Download scripts/publish.py from Mike0021/qwen-image: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/Mike0021/qwen-image/resolve/main/scripts/publish.py
- Command line
-
hf download hf://spaces/Mike0021/qwen-image/scripts/publish.py
-
curl -L -o publish.py https://huggingface.co/spaces/Mike0021/qwen-image/resolve/main/scripts/publish.py
1.84 kB
| #!/usr/bin/env python3 | |
| """Publish a committed revision only to the private ZeroGPU Space created here.""" | |
| import json | |
| from fnmatch import fnmatchcase | |
| from pathlib import Path | |
| import subprocess | |
| from huggingface_hub import HfApi, get_token | |
| from deploy import ALLOWLIST | |
| ROOT = Path(__file__).resolve().parents[1] | |
| state = json.loads((ROOT / "deployment.json").read_text()) | |
| repo = state["repo_id"] | |
| token = get_token() | |
| if not token: | |
| raise SystemExit("Existing authentication required") | |
| if subprocess.check_output(["git", "status", "--porcelain"], cwd=ROOT, text=True).strip(): | |
| raise SystemExit("Commit the source before publishing") | |
| api = HfApi(token=token) | |
| info = api.space_info(repo) | |
| hardware = info.runtime.hardware or info.runtime.requested_hardware | |
| if not info.private or str(hardware) != "zero-a10g": | |
| raise SystemExit("Expected the existing private ZeroGPU deployment") | |
| source = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True).strip() | |
| commit = api.upload_folder(repo_id=repo, repo_type="space", folder_path=str(ROOT), | |
| allow_patterns=ALLOWLIST, parent_commit=info.sha, | |
| commit_message=f"Publish Qwen 2.1 Image source {source[:12]}") | |
| state.update(hub_commit=commit.oid, latest_source_commit=source) | |
| (ROOT / "deployment.json").write_text(json.dumps(state, indent=2)+"\n") | |
| expected = {p.relative_to(ROOT).as_posix() for p in ROOT.rglob("*") if p.is_file() | |
| and any(fnmatchcase(p.relative_to(ROOT).as_posix(), pattern) for pattern in ALLOWLIST)} | |
| remote = set(api.list_repo_files(repo, repo_type="space", revision=commit.oid)) | |
| if expected - remote: | |
| raise SystemExit("Hub omitted allowlisted files; inspect .gitignore before continuing: " | |
| + ", ".join(sorted(expected - remote))) | |
| print(json.dumps({"space": repo, "hub_commit": commit.oid, "source_commit": source})) | |