image-tool / frontend /src /api /objectRemovalClient.ts
JunyoungK7's picture
Claude Sonnet 4.6
Deploy to HF Spaces: Docker setup, CPU inference, env-gated config
a3953cb
Raw History Blame Contribute Delete
2.39 kB
import type { StepSummary } from "./client";
export const OBJ_API_BASE = import.meta.env.VITE_API_BASE ?? "http://localhost:8000";
// ---------------------------------------------------------------------------
// Upload
// ---------------------------------------------------------------------------
export async function uploadForObjectRemoval(
file: File,
): Promise<{ job_id: string; width: number; height: number }> {
const formData = new FormData();
formData.append("file", file);
const response = await fetch(`${OBJ_API_BASE}/object-removal/upload`, {
method: "POST",
body: formData,
});
if (!response.ok) {
let detail = `HTTP ${response.status}`;
try { const j = await response.json(); if (j?.detail) detail = j.detail; } catch { /* ignore */ }
throw new Error(detail);
}
return response.json();
}
// ---------------------------------------------------------------------------
// Generate
// ---------------------------------------------------------------------------
export async function generateObjectRemoval(
jobId: string,
maskJson: object,
): Promise<{ job_id: string; step_number: number; status: string }> {
const response = await fetch(`${OBJ_API_BASE}/object-removal/generate`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ job_id: jobId, mask_json: maskJson }),
});
if (!response.ok) {
let detail = `HTTP ${response.status}`;
try { const j = await response.json(); if (j?.detail) detail = j.detail; } catch { /* ignore */ }
throw new Error(detail);
}
return response.json();
}
// ---------------------------------------------------------------------------
// Result polling — same response shape as getJobResult in client.ts
// ---------------------------------------------------------------------------
export async function getObjectRemovalResult(jobId: string): Promise<{
job_id: string;
current_step: number;
status: "pending" | "processing" | "completed" | "failed";
result_image_url: string | null;
original_image_url: string | null;
error_message: string | null;
steps: StepSummary[];
}> {
const response = await fetch(`${OBJ_API_BASE}/object-removal/result/${jobId}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json();
}