nextgpt-v0-source / src /scripts /deploy_space.py
caizz's picture
Publish verified code archive and live demo links
2ad74e3 verified
Raw History Blame Contribute Delete
1.96 kB
"""Publish this folder to a free Hugging Face ZeroGPU Gradio Space."""
from __future__ import annotations
import argparse
import getpass
import os
from pathlib import Path
from huggingface_hub import HfApi
from huggingface_hub.utils import HfHubHTTPError, RepositoryNotFoundError
ROOT = Path(__file__).resolve().parents[1]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("repo_id", help="e.g. username/nextgpt-7b-v0-reproduction")
args = parser.parse_args()
token = os.environ.get("HF_TOKEN") or getpass.getpass("Hugging Face token: ")
if not token:
raise SystemExit("A write token is required")
api = HfApi(token=token)
try:
existing = api.space_info(args.repo_id)
except RepositoryNotFoundError:
existing = None
if existing is None:
try:
api.create_repo(
repo_id=args.repo_id, repo_type="space", space_sdk="gradio",
space_hardware="zero-a10g", exist_ok=True,
)
except HfHubHTTPError as exc:
if exc.response is not None and exc.response.status_code == 402:
raise SystemExit(
"Hugging Face refused free ZeroGPU hosting for this account. "
"No paid hardware was requested."
) from exc
raise
elif existing.card_data.get("sdk") != "gradio" or api.get_space_runtime(args.repo_id).hardware != "zero-a10g":
raise SystemExit("The existing Space must already be a free Gradio ZeroGPU Space")
api.upload_folder(
repo_id=args.repo_id, repo_type="space", folder_path=str(ROOT),
ignore_patterns=["**/__pycache__/**", "**/*.pyc", ".venv/**",
"models/**", "outputs/**", ".cache/**"],
commit_message="Deploy official NExT-GPT 7b_tiva_v0 on free ZeroGPU",
)
print(f"https://huggingface.co/spaces/{args.repo_id}")
if __name__ == "__main__":
main()