from __future__ import annotations import argparse from huggingface_hub import HfApi, SpaceHardware def main() -> None: parser = argparse.ArgumentParser(description="Create/update the Kimodo ZeroGPU Space.") parser.add_argument("repo_id", help="Space repo id, for example: username/kimodo-zerogpu") parser.add_argument("--public", action="store_true", help="Create the Space as public instead of private.") parser.add_argument( "--message", default="Deploy Kimodo ZeroGPU updates", help="Commit message to use for the Space upload.", ) args = parser.parse_args() api = HfApi() api.create_repo( repo_id=args.repo_id, repo_type="space", space_sdk="gradio", space_hardware=SpaceHardware.ZERO_A10G, private=not args.public, exist_ok=True, ) commit = api.upload_folder( repo_id=args.repo_id, repo_type="space", folder_path=".", commit_message=args.message, ignore_patterns=[ "*.log", "__pycache__/**", ".git/**", ".gradio/**", ".cache/**", "*.npz", # Local dev artifacts (offline viewer smoke test + local store). "make_preview_test.py", "preview_test.html", ".kimodo-animations/**", # Local headless probes / checks (never part of the Space). "_*.py", ], ) runtime = api.request_space_hardware(repo_id=args.repo_id, hardware=SpaceHardware.ZERO_A10G) print(f"Uploaded: {commit.commit_url}") print(f"Hardware: {runtime.hardware}") # Every deploy also refreshes the local Gradio dev server so it reflects this # code. The helper is local-only (not uploaded), so this is a no-op on a Space. try: import _restart_local_gradio _restart_local_gradio.restart() except Exception as exc: print(f"local gradio restart skipped: {type(exc).__name__}: {exc}") if __name__ == "__main__": main()