llm-fishing / scripts /deploy_space.py
reuzed
Faster fishing flow, fish-specific FLUX prompts, concise LLM text, and audio hooks.
0364c0b
Raw
History Blame Contribute Delete
2.06 kB
#!/usr/bin/env python3
"""Push LLM Fishing to build-small-hackathon/llm-fishing on Hugging Face.
Usage:
python scripts/deploy_space.py # reads HF_TOKEN from .env
"""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
from dotenv import load_dotenv
ROOT = Path(__file__).resolve().parent.parent
load_dotenv(ROOT / ".env")
SPACE = os.getenv("HF_SPACE", "build-small-hackathon/llm-fishing")
def run(cmd: list[str], **kwargs) -> None:
print("+", " ".join(cmd))
subprocess.run(cmd, check=True, cwd=ROOT, **kwargs)
def main() -> None:
token = os.getenv("HF_TOKEN") or os.getenv("HUGGING_FACE_HUB_TOKEN")
if not token:
print("Set HF_TOKEN in .env then re-run.", file=sys.stderr)
sys.exit(1)
run(["hf", "auth", "login", "--token", token, "--add-to-git-credential"])
try:
run(
[
"hf",
"repo",
"create",
SPACE,
"--type",
"space",
"--space-sdk",
"gradio",
"--no-private",
"--exist-ok",
]
)
except subprocess.CalledProcessError:
pass
remote = f"https://huggingface.co/spaces/{SPACE}"
if not (ROOT / ".git").exists():
run(["git", "init"])
run(["git", "branch", "-M", "main"])
run(["git", "add", "-A"])
try:
run(["git", "commit", "-m", "Deploy LLM Fishing hackathon Space"])
except subprocess.CalledProcessError:
pass
try:
run(["git", "remote", "add", "origin", remote])
except subprocess.CalledProcessError:
run(["git", "remote", "set-url", "origin", remote])
run(["git", "push", "-u", "origin", "main", "--force"])
print(f"\nLive at: https://huggingface.co/spaces/{SPACE}")
print("\nAdd Space secrets (Settings → Variables and secrets):")
print(" MODAL_TOKEN_ID, MODAL_TOKEN_SECRET, LLM_MODE=modal, IMAGE_MODE=modal")
if __name__ == "__main__":
main()