Spaces:
Sleeping
Sleeping
File size: 1,176 Bytes
2237841 7f45d1d 14f132a 5d11050 14f132a 5d11050 7f45d1d b7a8131 7f45d1d b7a8131 7f45d1d 14f132a 9036163 14f132a b7a8131 7f45d1d |
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 |
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()
|