Spaces:
Sleeping
Sleeping
Download frontend/src/api/objectRemovalClient.ts from junyoung137/image-tool: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/spaces/junyoung137/image-tool/resolve/main/frontend/src/api/objectRemovalClient.ts
- Command line
-
hf download hf://spaces/junyoung137/image-tool/frontend/src/api/objectRemovalClient.ts
-
curl -L -o objectRemovalClient.ts https://huggingface.co/spaces/junyoung137/image-tool/resolve/main/frontend/src/api/objectRemovalClient.ts
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(); | |
| } | |