Spaces:
Sleeping
Sleeping
Fix the bug that convertor.py could not be loaded
Browse files
app.py
CHANGED
|
@@ -3,8 +3,9 @@ import os
|
|
| 3 |
# 0. Immediately set the HF token from the secret
|
| 4 |
os.environ["HUGGINGFACE_TOKEN"] = os.getenv("HF_TOKEN")
|
| 5 |
|
| 6 |
-
from huggingface_hub import snapshot_download
|
| 7 |
import importlib.util
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
|
| 10 |
# 1. Download a snapshot of the private Space’s repo into a local cache directory
|
|
@@ -16,7 +17,10 @@ downloaded_dir = snapshot_download(
|
|
| 16 |
cache_dir=str(cache_dir),
|
| 17 |
) # downloaded_dir is something like "private_space_cache/bobfu/WordDocxFormatConvertor"
|
| 18 |
|
| 19 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
| 20 |
app_path = Path(downloaded_dir) / "app.py"
|
| 21 |
spec = importlib.util.spec_from_file_location("private_app", str(app_path))
|
| 22 |
private_app = importlib.util.module_from_spec(spec)
|
|
|
|
| 3 |
# 0. Immediately set the HF token from the secret
|
| 4 |
os.environ["HUGGINGFACE_TOKEN"] = os.getenv("HF_TOKEN")
|
| 5 |
|
| 6 |
+
from huggingface_hub import snapshot_download
|
| 7 |
import importlib.util
|
| 8 |
+
import sys
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
# 1. Download a snapshot of the private Space’s repo into a local cache directory
|
|
|
|
| 17 |
cache_dir=str(cache_dir),
|
| 18 |
) # downloaded_dir is something like "private_space_cache/bobfu/WordDocxFormatConvertor"
|
| 19 |
|
| 20 |
+
# 2. Insert the private folder into sys.path so imports resolve correctly
|
| 21 |
+
**sys.path.insert(0, str(downloaded_dir)) # Allow Python to import convertor from the same directory**
|
| 22 |
+
|
| 23 |
+
# 3. Load the main app script from the private repo
|
| 24 |
app_path = Path(downloaded_dir) / "app.py"
|
| 25 |
spec = importlib.util.spec_from_file_location("private_app", str(app_path))
|
| 26 |
private_app = importlib.util.module_from_spec(spec)
|