Spaces:
Sleeping
Sleeping
Download backend/main.py from NUSExecEd/agentic-workflow-node-lab: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/spaces/NUSExecEd/agentic-workflow-node-lab/resolve/main/backend/main.py
- Command line
-
hf download hf://spaces/NUSExecEd/agentic-workflow-node-lab/backend/main.py
-
curl -L -o main.py https://huggingface.co/spaces/NUSExecEd/agentic-workflow-node-lab/resolve/main/backend/main.py
1.82 kB
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from .engine import WorkflowEngine | |
| from .models import ResumeRequest, RunResponse, StartRequest, Workflow | |
| load_dotenv() | |
| app = FastAPI(title="Agentic Workflow Lab", version="1.0.0") | |
| app.add_middleware(CORSMiddleware, allow_origins=["http://localhost:5173"], allow_methods=["*"], allow_headers=["*"]) | |
| engine = WorkflowEngine() | |
| def health() -> dict[str, str]: | |
| return {"status": "ok"} | |
| def run(request: StartRequest) -> RunResponse: | |
| try: | |
| return engine.start(request) | |
| except Exception as exc: | |
| raise HTTPException(status_code=400, detail=str(exc)) from exc | |
| def resume(request: ResumeRequest) -> RunResponse: | |
| try: | |
| return engine.resume(request.run_id, request.response) | |
| except Exception as exc: | |
| raise HTTPException(status_code=400, detail=str(exc)) from exc | |
| def validate_workflow(workflow: Workflow) -> Workflow: | |
| try: | |
| engine._validate(workflow) | |
| return workflow | |
| except Exception as exc: | |
| raise HTTPException(status_code=400, detail=str(exc)) from exc | |
| dist = Path(__file__).resolve().parents[1] / "frontend" / "dist" | |
| if dist.exists(): | |
| app.mount("/assets", StaticFiles(directory=dist / "assets"), name="assets") | |
| def spa(path: str) -> FileResponse: | |
| requested = dist / path | |
| return FileResponse(requested if requested.is_file() else dist / "index.html") | |