import importlib.util import os import sys from pathlib import Path ROOT = Path(__file__).resolve().parent BACKEND_DIR = ROOT / "Backend" BACKEND_APP = BACKEND_DIR / "app.py" if str(BACKEND_DIR) not in sys.path: sys.path.insert(0, str(BACKEND_DIR)) spec = importlib.util.spec_from_file_location("backend_app", BACKEND_APP) if spec is None or spec.loader is None: raise RuntimeError(f"Unable to load backend app from {BACKEND_APP}") backend_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(backend_module) app = backend_module.app if __name__ == "__main__": port = int(os.environ.get("PORT", 7860)) app.run(host="0.0.0.0", port=port, debug=True)