const api = (() => { async function request(method, url, body = null) { const options = { method, credentials: "include" }; if (body instanceof FormData) { options.body = body; } else if (body !== null) { options.headers = { "Content-Type": "application/json" }; options.body = JSON.stringify(body); } const res = await fetch(url, options); if (!res.ok) { const err = await res.json().catch(() => ({ detail: res.statusText })); throw new Error(err.detail || res.statusText); } return res.status === 204 ? null : res.json(); } return { // GET /api/models listModels() { return request("GET", "/api/models"); }, // POST /api/models (file: File, title: str, description?: str) createModel(file, title, description = null) { const form = new FormData(); form.append("file", file); form.append("title", title); if (description !== null) form.append("description", description); return request("POST", "/api/models", form); }, // GET /api/models/active getActiveModel() { return request("GET", "/api/models/active"); }, // GET /api/models/{model_id} getModel(modelId) { return request("GET", `/api/models/${modelId}`); }, // PATCH /api/models/{model_id} (active: bool) updateModel(modelId, active) { return request("PATCH", `/api/models/${modelId}`, { active }); }, // DELETE /api/models/{model_id} deleteModel(modelId) { return request("DELETE", `/api/models/${modelId}`); }, // POST /api/models/{model_id}/predict (treatment1: str, treatment2: str, thick_hair: bool|null) predict(modelId, body) { return request("POST", `/api/models/${modelId}/predict`, body); }, }; })();