MogensR commited on
Commit
783cf8c
·
1 Parent(s): d51bd78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -9
app.py CHANGED
@@ -5,6 +5,57 @@
5
  Imports and runs the main application from core/app.py
6
  """
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Import the main application from core
9
  from core.app import (
10
  VideoProcessor,
@@ -14,20 +65,21 @@
14
  get_model_status,
15
  get_cache_status,
16
  PROCESS_CANCELLED,
17
- main
18
  )
19
 
20
  # Re-export for backward compatibility
21
  __all__ = [
22
- 'VideoProcessor',
23
- 'processor',
24
- 'load_models_with_validation',
25
- 'process_video_fixed',
26
- 'get_model_status',
27
- 'get_cache_status',
28
- 'PROCESS_CANCELLED'
 
29
  ]
30
 
31
  # Entry point for Hugging Face Spaces
32
  if __name__ == "__main__":
33
- main()
 
5
  Imports and runs the main application from core/app.py
6
  """
7
 
8
+ # --- BEGIN ABSOLUTE-IMPORT & ENV HOTFIX (Hugging Face) ---
9
+ import os, re, io, sys
10
+
11
+ PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) # /home/user/app
12
+
13
+ # Ensure top-level packages are importable (utils, core, models, processing)
14
+ if PROJECT_ROOT not in sys.path:
15
+ sys.path.insert(0, PROJECT_ROOT)
16
+
17
+ # Quiet invalid OMP_NUM_THREADS warnings (libgomp)
18
+ val = os.environ.get("OMP_NUM_THREADS")
19
+ if val is not None and not str(val).strip().isdigit():
20
+ # Either unset or set to a safe default; we set to 1
21
+ os.environ["OMP_NUM_THREADS"] = "1"
22
+
23
+ def _patch_relative_imports(project_root: str):
24
+ """
25
+ Rewrite 'from ..X.y' -> 'from X.y' for top-level packages.
26
+ Runs once at startup; safe/no-op if already fixed.
27
+ """
28
+ skip_dirs = {"venv", ".git", "__pycache__"}
29
+ rx_from = re.compile(r"(?m)^from\s+\.+(utils|core|models|processing)\.")
30
+ touched = []
31
+
32
+ for root, dirs, files in os.walk(project_root):
33
+ # prune
34
+ dirs[:] = [d for d in dirs if d not in skip_dirs]
35
+ for fn in files:
36
+ if not fn.endswith(".py"):
37
+ continue
38
+ path = os.path.join(root, fn)
39
+ try:
40
+ with io.open(path, "r", encoding="utf-8") as f:
41
+ src = f.read()
42
+ new = rx_from.sub(r"from \1.", src)
43
+ if new != src:
44
+ with io.open(path, "w", encoding="utf-8") as f:
45
+ f.write(new)
46
+ touched.append(os.path.relpath(path, project_root))
47
+ except Exception:
48
+ # Don't block startup if a file can't be read/written
49
+ pass
50
+
51
+ if touched:
52
+ print(f"✅ Fixed relative imports in {len(touched)} file(s):")
53
+ for p in touched:
54
+ print(" -", p)
55
+
56
+ _patch_relative_imports(PROJECT_ROOT)
57
+ # --- END ABSOLUTE-IMPORT & ENV HOTFIX ---
58
+
59
  # Import the main application from core
60
  from core.app import (
61
  VideoProcessor,
 
65
  get_model_status,
66
  get_cache_status,
67
  PROCESS_CANCELLED,
68
+ main,
69
  )
70
 
71
  # Re-export for backward compatibility
72
  __all__ = [
73
+ "VideoProcessor",
74
+ "processor",
75
+ "load_models_with_validation",
76
+ "process_video_fixed",
77
+ "get_model_status",
78
+ "get_cache_status",
79
+ "PROCESS_CANCELLED",
80
+ "main",
81
  ]
82
 
83
  # Entry point for Hugging Face Spaces
84
  if __name__ == "__main__":
85
+ main()