|
import os |
|
from huggingface_hub import HfApi |
|
from tempfile import TemporaryDirectory |
|
import importlib.util |
|
import sys |
|
|
|
|
|
|
|
def load_private_code(): |
|
api = HfApi(token=os.environ["HF_TOKEN"]) |
|
|
|
with TemporaryDirectory() as tmp_dir: |
|
api.snapshot_download( |
|
repo_id=os.environ["PRIVATE_REPOSITORY_NAME"], |
|
repo_type="space", |
|
local_dir=tmp_dir |
|
) |
|
|
|
spec = importlib.util.spec_from_file_location( |
|
"private_app", |
|
os.path.join(tmp_dir, "app.py") |
|
) |
|
private_module = importlib.util.module_from_spec(spec) |
|
sys.modules["private_app"] = private_module |
|
spec.loader.exec_module(private_module) |
|
|
|
return private_module |
|
|
|
|
|
|
|
private_app = load_private_code() |
|
app = private_app.app |