|
|
|
|
|
""" |
|
|
Hugging Face Spaces Entry Point |
|
|
This file must remain in root for HF Spaces compatibility |
|
|
Imports and runs the main application from core/app.py |
|
|
""" |
|
|
|
|
|
|
|
|
import os, re, io, sys |
|
|
|
|
|
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) |
|
|
|
|
|
|
|
|
if PROJECT_ROOT not in sys.path: |
|
|
sys.path.insert(0, PROJECT_ROOT) |
|
|
|
|
|
|
|
|
val = os.environ.get("OMP_NUM_THREADS") |
|
|
if val is not None and not str(val).strip().isdigit(): |
|
|
|
|
|
os.environ["OMP_NUM_THREADS"] = "1" |
|
|
|
|
|
def _patch_relative_imports(project_root: str): |
|
|
""" |
|
|
Rewrite 'from ..X.y' -> 'from X.y' for top-level packages. |
|
|
Runs once at startup; safe/no-op if already fixed. |
|
|
""" |
|
|
skip_dirs = {"venv", ".git", "__pycache__"} |
|
|
rx_from = re.compile(r"(?m)^from\s+\.+(utils|core|models|processing)\.") |
|
|
touched = [] |
|
|
|
|
|
for root, dirs, files in os.walk(project_root): |
|
|
|
|
|
dirs[:] = [d for d in dirs if d not in skip_dirs] |
|
|
for fn in files: |
|
|
if not fn.endswith(".py"): |
|
|
continue |
|
|
path = os.path.join(root, fn) |
|
|
try: |
|
|
with io.open(path, "r", encoding="utf-8") as f: |
|
|
src = f.read() |
|
|
new = rx_from.sub(r"from \1.", src) |
|
|
if new != src: |
|
|
with io.open(path, "w", encoding="utf-8") as f: |
|
|
f.write(new) |
|
|
touched.append(os.path.relpath(path, project_root)) |
|
|
except Exception: |
|
|
|
|
|
pass |
|
|
|
|
|
if touched: |
|
|
print(f"β
Fixed relative imports in {len(touched)} file(s):") |
|
|
for p in touched: |
|
|
print(" -", p) |
|
|
|
|
|
_patch_relative_imports(PROJECT_ROOT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import importlib |
|
|
import importlib.util |
|
|
from types import ModuleType |
|
|
|
|
|
def _ensure_utilities_alias(project_root: str): |
|
|
|
|
|
if "utilities" in sys.modules and getattr(sys.modules["utilities"], "__name__", "").startswith("utils"): |
|
|
return |
|
|
|
|
|
|
|
|
try: |
|
|
_utils = importlib.import_module("utils") |
|
|
sys.modules["utilities"] = _utils |
|
|
return |
|
|
except Exception: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
utils_init = os.path.join(project_root, "utils", "__init__.py") |
|
|
if not os.path.exists(utils_init): |
|
|
|
|
|
return |
|
|
|
|
|
spec = importlib.util.spec_from_file_location("utils", utils_init) |
|
|
if spec is None or spec.loader is None: |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
utils_mod = importlib.util.module_from_spec(spec) |
|
|
sys.modules["utils"] = utils_mod |
|
|
|
|
|
sys.modules["utilities"] = utils_mod |
|
|
|
|
|
|
|
|
try: |
|
|
spec.loader.exec_module(utils_mod) |
|
|
except Exception: |
|
|
|
|
|
sys.modules.pop("utils", None) |
|
|
sys.modules.pop("utilities", None) |
|
|
raise |
|
|
|
|
|
|
|
|
_ensure_utilities_alias(PROJECT_ROOT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from core.app import ( |
|
|
VideoProcessor, |
|
|
processor, |
|
|
load_models_with_validation, |
|
|
process_video_fixed, |
|
|
get_model_status, |
|
|
get_cache_status, |
|
|
PROCESS_CANCELLED, |
|
|
main, |
|
|
) |
|
|
|
|
|
|
|
|
__all__ = [ |
|
|
"VideoProcessor", |
|
|
"processor", |
|
|
"load_models_with_validation", |
|
|
"process_video_fixed", |
|
|
"get_model_status", |
|
|
"get_cache_status", |
|
|
"PROCESS_CANCELLED", |
|
|
"main", |
|
|
] |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|