VideoTimeTravel / app.py
aabiro's picture
Upload 4 files
c7dd3e8 verified
Raw History Blame Contribute Delete
1.29 kB
"""Thin public loader for this Space.
The real application code for this Space is not public. It lives in a
private Hugging Face repo and is downloaded at startup using this
Space's HF_TOKEN secret. Only this loader file is public.
"""
import os
import sys
import zipfile
from pathlib import Path
PAYLOAD_REPO = "aabiro/space-payloads"
PAYLOAD_FILE = "video-time-travel.zip"
TARGET = Path("/tmp/space-app/video-time-travel")
def _fetch_payload() -> None:
if (TARGET / "app.py").is_file():
return
token = os.environ.get("HF_TOKEN")
if not token:
raise RuntimeError(
"HF_TOKEN secret is not set on this Space, so the private "
"application code cannot be downloaded."
)
from huggingface_hub import hf_hub_download
zip_path = hf_hub_download(
repo_id=PAYLOAD_REPO,
repo_type="model",
filename=PAYLOAD_FILE,
token=token,
)
TARGET.mkdir(parents=True, exist_ok=True)
with zipfile.ZipFile(zip_path) as zf:
zf.extractall(TARGET)
_fetch_payload()
sys.path.insert(0, str(TARGET))
os.chdir(TARGET)
_app_file = TARGET / "app.py"
exec(
compile(_app_file.read_text(encoding="utf-8"), str(_app_file), "exec"),
{"__name__": "__main__", "__file__": str(_app_file)},
)