Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""Hugging Face Spaces entry point -
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
import importlib.util
|
|
@@ -7,13 +7,41 @@ from pathlib import Path
|
|
| 7 |
|
| 8 |
app_dir = Path("/app")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
spec = importlib.util.spec_from_file_location("ui_app", str(ui_app_path))
|
| 15 |
ui_app_module = importlib.util.module_from_spec(spec)
|
| 16 |
sys.modules["ui_app"] = ui_app_module
|
|
|
|
|
|
|
| 17 |
spec.loader.exec_module(ui_app_module)
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
|
@@ -24,8 +52,8 @@ if ui_app_path.exists():
|
|
| 24 |
show_error=True
|
| 25 |
)
|
| 26 |
else:
|
| 27 |
-
print(f"ERROR: ui/app.py
|
| 28 |
-
print(f"
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""Hugging Face Spaces entry point - handles backslash filenames"""
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
import importlib.util
|
|
|
|
| 7 |
|
| 8 |
app_dir = Path("/app")
|
| 9 |
|
| 10 |
+
# Find ui\app.py (with backslash in the filename on Linux)
|
| 11 |
+
ui_app_files = list(app_dir.glob("**/app.py"))
|
| 12 |
+
ui_app_path = None
|
| 13 |
|
| 14 |
+
for f in ui_app_files:
|
| 15 |
+
# Look for ui/app.py or ui\app.py
|
| 16 |
+
if "ui" in str(f) and f.name == "app.py":
|
| 17 |
+
# Skip /app/app.py (the entry point itself)
|
| 18 |
+
if f.parent.name == "ui" or "ui" in f.parent.name:
|
| 19 |
+
ui_app_path = f
|
| 20 |
+
break
|
| 21 |
+
|
| 22 |
+
if not ui_app_path:
|
| 23 |
+
# Last resort - manually check common locations
|
| 24 |
+
possible_paths = [
|
| 25 |
+
app_dir / "ui" / "app.py",
|
| 26 |
+
app_dir / "ui\\app.py", # With backslash
|
| 27 |
+
]
|
| 28 |
+
for p in possible_paths:
|
| 29 |
+
if p.exists():
|
| 30 |
+
ui_app_path = p
|
| 31 |
+
break
|
| 32 |
+
|
| 33 |
+
if ui_app_path and ui_app_path.exists():
|
| 34 |
+
print(f"Found ui/app.py at: {ui_app_path}")
|
| 35 |
+
|
| 36 |
+
# Add app_dir to sys.path so imports work
|
| 37 |
+
sys.path.insert(0, str(app_dir))
|
| 38 |
+
|
| 39 |
+
# Load the module
|
| 40 |
spec = importlib.util.spec_from_file_location("ui_app", str(ui_app_path))
|
| 41 |
ui_app_module = importlib.util.module_from_spec(spec)
|
| 42 |
sys.modules["ui_app"] = ui_app_module
|
| 43 |
+
|
| 44 |
+
# Execute the module
|
| 45 |
spec.loader.exec_module(ui_app_module)
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
|
|
|
| 52 |
show_error=True
|
| 53 |
)
|
| 54 |
else:
|
| 55 |
+
print(f"ERROR: Could not find ui/app.py")
|
| 56 |
+
print(f"App directory: {app_dir}")
|
| 57 |
+
print(f"Files found:")
|
| 58 |
+
for f in sorted(app_dir.glob("**/*.py")):
|
| 59 |
+
print(f" {f}")
|