from __future__ import annotations import os import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] SRC = ROOT / "src" ROOT_ENV = ROOT / ".env" LOCAL_ENV = ROOT / "data" / "local.env" if str(SRC) not in sys.path: sys.path.insert(0, str(SRC)) def main() -> int: _load_local_env(ROOT_ENV, override=True) _load_local_env(LOCAL_ENV, override=True) os.environ.setdefault("TIME_MACHINE_ADAPTER_PROFILE", "modal") from time_machine.application.container import create_container from time_machine.ui.gradio_app import create_app container = create_container() demo = create_app(container) server_name = os.getenv("GRADIO_SERVER_NAME", "0.0.0.0") server_port = int(os.getenv("GRADIO_SERVER_PORT", "7862")) demo.launch( server_name=server_name, server_port=server_port, prevent_thread_lock=True, ) print(f"AI Time Machine running on http://127.0.0.1:{server_port}", flush=True) demo.block_thread() return 0 def _load_local_env(path: Path, *, override: bool = False) -> None: if not path.exists(): return for raw_line in path.read_text(encoding="utf-8").splitlines(): line = raw_line.strip() if not line or line.startswith("#") or "=" not in line: continue key, value = line.split("=", 1) key = key.strip() value = value.strip().strip('"').strip("'") if key and (override or key not in os.environ): os.environ[key] = value if __name__ == "__main__": raise SystemExit(main())