| from __future__ import annotations | |
| import argparse | |
| import os | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent / "acea" | |
| if not ROOT.exists(): | |
| raise FileNotFoundError(f"Cannot find ACEA project directory at {ROOT}") | |
| sys.path.insert(0, str(ROOT)) | |
| os.chdir(ROOT) | |
| def run_backend(host: str = "0.0.0.0", port: int = 7860, reload: bool = False) -> None: | |
| """Run the ACEA FastAPI backend.""" | |
| import uvicorn | |
| uvicorn.run("backend.main:app", host=host, port=port, reload=reload) | |
| def run_inference(groq_key: str | None = None) -> None: | |
| """Run the ACEA inference script.""" | |
| if groq_key: | |
| os.environ["GROQ_API_KEY"] = groq_key | |
| import inference | |
| if not hasattr(inference, "main"): | |
| raise RuntimeError("inference.py is missing a main() function") | |
| inference.main() | |
| def parse_args() -> argparse.Namespace: | |
| parser = argparse.ArgumentParser(description="Launch the ACEA app services.") | |
| parser.add_argument( | |
| "command", | |
| nargs="?", | |
| choices=["backend", "inference"], | |
| default="backend", | |
| help="Which service to run: backend or inference.", | |
| ) | |
| parser.add_argument("--host", default="0.0.0.0", help="Backend host address.") | |
| parser.add_argument("--port", type=int, default=7860, help="Backend port.") | |
| parser.add_argument("--reload", action="store_true", help="Enable backend reload mode.") | |
| parser.add_argument("--groq-key", help="Optional Groq API key for inference.") | |
| return parser.parse_args() | |
| if __name__ == "__main__": | |
| args = parse_args() | |
| if args.command == "backend": | |
| run_backend(host=args.host, port=args.port, reload=args.reload) | |
| elif args.command == "inference": | |
| run_inference(groq_key=args.groq_key) | |