Alireza Aminzadeh
Upload folder using huggingface_hub
7a0a17c verified
Raw
History Blame Contribute Delete
952 Bytes
"""
FastAPI app for the scheduling optimizer.
"""
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional
from solver import solve_single_machine
app = FastAPI(title="Scheduling Optimizer API", version="0.1.0")
class Task(BaseModel):
id: str
duration: int = 1
class ScheduleRequest(BaseModel):
tasks: List[Task]
horizon: Optional[int] = 10000
@app.get("/health")
def health():
return {"status": "ok"}
@app.post("/schedule")
def schedule(req: ScheduleRequest):
tasks = [{"id": t.id, "duration": t.duration} for t in req.tasks]
if not tasks:
raise HTTPException(status_code=400, detail="tasks must not be empty")
result = solve_single_machine(tasks, horizon=req.horizon or 10000)
if "error" in result:
raise HTTPException(status_code=422, detail=result.get("error", "Solver failed"))
return result