Pin Applio 3.6.5 and verified basis assets, migrate private voice provenance, and coordinate conversion/live/training with Deck GPU leases. Prepare an inactive voice profile and a restricted studio container. Move CUDA and Torch caches out of the small temporary filesystem to prevent OmniVoice reference failures. Package app updates from the explicit allowlist in one Docker layer.
125 lines
4.5 KiB
JavaScript
125 lines
4.5 KiB
JavaScript
/**
|
||
* API-Client für die Mikes-Applio-UI-REST-API.
|
||
* Alle Anfragen laufen gegen die eigene stabile API – nie direkt gegen Gradio.
|
||
*/
|
||
|
||
const BASE = "/api";
|
||
|
||
function readableErrorDetail(detail, fallback) {
|
||
if (typeof detail === "string" && detail.trim()) return detail;
|
||
if (Array.isArray(detail)) {
|
||
const messages = detail.map((item) => {
|
||
if (typeof item === "string") return item;
|
||
if (!item || typeof item !== "object") return String(item);
|
||
const field = Array.isArray(item.loc)
|
||
? item.loc.filter((part) => part !== "body").join(" → ")
|
||
: "";
|
||
const message = String(item.msg || item.message || JSON.stringify(item))
|
||
.replace(/^Value error,\s*/i, "");
|
||
return field ? `${field}: ${message}` : message;
|
||
}).filter(Boolean);
|
||
if (messages.length) return messages.join("; ");
|
||
}
|
||
if (detail && typeof detail === "object") {
|
||
return detail.message || JSON.stringify(detail);
|
||
}
|
||
return fallback;
|
||
}
|
||
|
||
async function request(path, options = {}) {
|
||
const res = await fetch(BASE + path, {
|
||
headers: {
|
||
...(options.body instanceof FormData ? {} : { "Content-Type": "application/json" }),
|
||
"X-Applio-UI": "1",
|
||
...(options.headers || {}),
|
||
},
|
||
...options,
|
||
});
|
||
|
||
if (!res.ok) {
|
||
let detail = `HTTP ${res.status}`;
|
||
try {
|
||
const data = await res.json();
|
||
detail = readableErrorDetail(data.detail ?? data, detail);
|
||
} catch { /* ignore */ }
|
||
const err = new Error(detail);
|
||
err.status = res.status;
|
||
throw err;
|
||
}
|
||
|
||
if (res.status === 204) return null;
|
||
return res.json();
|
||
}
|
||
|
||
export const api = {
|
||
// Health & System
|
||
health: () => request("/health"),
|
||
system: () => request("/system"),
|
||
diagnostics: () => request("/diagnostics"),
|
||
|
||
// Modelle – returns { models: [...], count: N }
|
||
models: () => request("/models"),
|
||
model: (id) => request(`/models/${encodeURIComponent(id)}`),
|
||
renameModel: (id, newName) =>
|
||
request(`/models/${encodeURIComponent(id)}`, {
|
||
method: "PATCH",
|
||
body: JSON.stringify({ new_name: newName }),
|
||
}),
|
||
finalizeModel: (payload) =>
|
||
request("/models/finalize", { method: "POST", body: JSON.stringify(payload) }),
|
||
saveModelConversionPreset: (id, parameters) =>
|
||
request(`/models/${encodeURIComponent(id)}/conversion-preset`, {
|
||
method: "PUT",
|
||
body: JSON.stringify(parameters),
|
||
}),
|
||
deleteModelConversionPreset: (id) =>
|
||
request(`/models/${encodeURIComponent(id)}/conversion-preset`, { method: "DELETE" }),
|
||
|
||
// Presets
|
||
presets: () => request("/presets"),
|
||
preset: (id) => request(`/presets/${encodeURIComponent(id)}`),
|
||
|
||
// Uploads
|
||
upload: (file) => {
|
||
const fd = new FormData();
|
||
fd.append("file", file);
|
||
return request("/uploads", { method: "POST", body: fd });
|
||
},
|
||
createDataset: (datasetName, files) => {
|
||
const fd = new FormData();
|
||
fd.append("dataset_name", datasetName);
|
||
for (const file of files) fd.append("files", file);
|
||
return request("/datasets", { method: "POST", body: fd });
|
||
},
|
||
dataset: (datasetName) => request(`/datasets/${encodeURIComponent(datasetName)}`),
|
||
|
||
// Jobs – returns { jobs: [...], count: N, total: N }
|
||
jobs: (params = {}) => {
|
||
const qs = new URLSearchParams(params).toString();
|
||
return request(`/jobs${qs ? "?" + qs : ""}`);
|
||
},
|
||
job: (id) => request(`/jobs/${encodeURIComponent(id)}`),
|
||
jobLog: (id) => request(`/jobs/${encodeURIComponent(id)}/log`),
|
||
cancelJob: (id) => request(`/jobs/${id}/cancel`, { method: "POST" }),
|
||
retryJob: (id) => request(`/jobs/${id}/retry`, { method: "POST" }),
|
||
deleteJob: (id) => request(`/jobs/${encodeURIComponent(id)}`, { method: "DELETE" }),
|
||
clearFinishedJobs: () => request("/jobs", { method: "DELETE" }),
|
||
jobDownload: (id, fileIndex = 0) => {
|
||
return `${BASE}/jobs/${id}/download?file_index=${fileIndex}`;
|
||
},
|
||
|
||
// Job-Erstellung – expects specific Pydantic models
|
||
createConvertJob: (payload) =>
|
||
request("/jobs/convert", { method: "POST", body: JSON.stringify(payload) }),
|
||
createTtsJob: (payload) =>
|
||
request("/jobs/tts-convert", { method: "POST", body: JSON.stringify(payload) }),
|
||
createPreprocessJob: (payload) =>
|
||
request("/jobs/preprocess", { method: "POST", body: JSON.stringify(payload) }),
|
||
createExtractJob: (payload) =>
|
||
request("/jobs/extract", { method: "POST", body: JSON.stringify(payload) }),
|
||
createTrainJob: (payload) =>
|
||
request("/jobs/train", { method: "POST", body: JSON.stringify(payload) }),
|
||
createIndexJob: (payload) =>
|
||
request("/jobs/index", { method: "POST", body: JSON.stringify(payload) }),
|
||
};
|