File size: 1,096 Bytes
8226b0b 31f08fe 8226b0b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import os
import sys
import zipfile
from huggingface_hub import hf_hub_download
# ---- Your private code vault (dataset repo) ----
CODE_REPO = "ThisIsAnAnonymousUser/minmax-code-private"
CODE_ZIP = "private_app.zip"
def load_private_app():
token = os.getenv("HF_TOKEN")
if not token:
raise RuntimeError("HF_TOKEN secret missing. Add it in Space Settings → Secrets.")
zip_path = hf_hub_download(
repo_id=CODE_REPO,
filename=CODE_ZIP,
repo_type="dataset",
token=token,
)
extract_dir = "/tmp/private_app"
os.makedirs(extract_dir, exist_ok=True)
with zipfile.ZipFile(zip_path, "r") as z:
z.extractall(extract_dir)
sys.path.insert(0, extract_dir)
import private_app # this comes from private_app.py inside the zip
return private_app
private_app = load_private_app()
# Launch the real app (kept private in the zip)
if __name__ == "__main__":
private_app.demo.queue()
port = int(os.environ.get("PORT", "7860"))
private_app.demo.launch(server_name="0.0.0.0", server_port=port, ssr_mode=False) |