import os import sys import shutil import zipfile import importlib from huggingface_hub import hf_hub_download # ---- Your private code vault (dataset repo) ---- CODE_REPO = "ThisIsAnAnonymousUser/minmax-code-private" CODE_ZIP = "private_app_ordinal.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" # IMPORTANT: wipe old extracted contents so you don't import stale code if os.path.exists(extract_dir): shutil.rmtree(extract_dir) os.makedirs(extract_dir, exist_ok=True) with zipfile.ZipFile(zip_path, "r") as z: z.extractall(extract_dir) # Make sure the extracted folder is importable if extract_dir not in sys.path: sys.path.insert(0, extract_dir) # Import module from the zip contents import private_app # In case of caching across rebuilds (rare but happens), reload it importlib.reload(private_app) 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)