Spaces:
Running
Running
Changed loading scripts in app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,31 @@
|
|
| 1 |
# app.py - Main entry point for Hugging Face Spaces
|
| 2 |
import os
|
|
|
|
| 3 |
import importlib.util
|
| 4 |
|
| 5 |
# Load the FastAPI app from code/app.py via importlib to avoid
|
| 6 |
# conflicts with the standard-library module named `code`.
|
| 7 |
HERE = os.path.dirname(__file__)
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
spec = importlib.util.spec_from_file_location("antique_auth_code_app", app_path)
|
| 10 |
module = importlib.util.module_from_spec(spec)
|
| 11 |
spec.loader.exec_module(module)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# The FastAPI `app` object expected inside code/app.py
|
| 14 |
app = getattr(module, "app")
|
| 15 |
|
|
|
|
| 1 |
# app.py - Main entry point for Hugging Face Spaces
|
| 2 |
import os
|
| 3 |
+
import sys
|
| 4 |
import importlib.util
|
| 5 |
|
| 6 |
# Load the FastAPI app from code/app.py via importlib to avoid
|
| 7 |
# conflicts with the standard-library module named `code`.
|
| 8 |
HERE = os.path.dirname(__file__)
|
| 9 |
+
CODE_DIR = os.path.join(HERE, "code")
|
| 10 |
+
app_path = os.path.join(CODE_DIR, "app.py")
|
| 11 |
+
|
| 12 |
+
# Ensure the `code/` directory is on sys.path so relative imports like
|
| 13 |
+
# `from model import ...` inside `code/app.py` resolve correctly.
|
| 14 |
+
if CODE_DIR not in sys.path:
|
| 15 |
+
sys.path.insert(0, CODE_DIR)
|
| 16 |
+
|
| 17 |
spec = importlib.util.spec_from_file_location("antique_auth_code_app", app_path)
|
| 18 |
module = importlib.util.module_from_spec(spec)
|
| 19 |
spec.loader.exec_module(module)
|
| 20 |
|
| 21 |
+
# Optionally: remove CODE_DIR from sys.path after loading to avoid side effects
|
| 22 |
+
try:
|
| 23 |
+
# remove the first occurrence we added
|
| 24 |
+
if sys.path[0] == CODE_DIR:
|
| 25 |
+
sys.path.pop(0)
|
| 26 |
+
except Exception:
|
| 27 |
+
pass
|
| 28 |
+
|
| 29 |
# The FastAPI `app` object expected inside code/app.py
|
| 30 |
app = getattr(module, "app")
|
| 31 |
|