Spaces:
Sleeping
Sleeping
| import os | |
| # 0. Immediately set the HF token from the secret | |
| os.environ["HUGGINGFACE_TOKEN"] = os.getenv("HF_TOKEN") | |
| from huggingface_hub import snapshot_download | |
| import importlib.util | |
| import sys | |
| from pathlib import Path | |
| # 1. Download a snapshot of the private Space’s repo into a local cache directory | |
| cache_dir = Path("private_space_cache") | |
| cache_dir.mkdir(exist_ok=True) | |
| downloaded_dir = snapshot_download( | |
| repo_id="bobfu/WordDocxFormatConvertor", | |
| repo_type="space", | |
| cache_dir=str(cache_dir), | |
| ) # downloaded_dir is something like "private_space_cache/bobfu/WordDocxFormatConvertor" | |
| # 2. Insert the private folder into sys.path so imports resolve correctly | |
| sys.path.insert(0, str(downloaded_dir)) # Allow Python to import convertor from the same directory | |
| # 3. Load the main app script from the private repo | |
| app_path = Path(downloaded_dir) / "app.py" | |
| spec = importlib.util.spec_from_file_location("private_app", str(app_path)) | |
| private_app = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(private_app) | |
| # 3. Call the Gradio interface defined in the private app | |
| demo = private_app.create_demo() # Example function you defined | |
| demo.launch() | |