Download src/api.ts from Sebastiankay/image-workspace-frontend: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Sebastiankay/image-workspace-frontend/resolve/main/src/api.ts
- Command line
-
hf download hf://spaces/Sebastiankay/image-workspace-frontend/src/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/Sebastiankay/image-workspace-frontend/resolve/main/src/api.ts
1.05 kB
| import type { NanoBananaRequest, NanoBananaResponse } from '@/types'; | |
| const NANO_BANANA_ENDPOINT = 'http://localhost:7879/v1/images/generations'; | |
| export async function generateImages( | |
| req: NanoBananaRequest, | |
| ): Promise<NanoBananaResponse> { | |
| const response = await fetch(NANO_BANANA_ENDPOINT, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ | |
| model: 'nano-banana', | |
| n: 1, | |
| response_format: 'b64_json', | |
| ...req, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| const text = await response.text().catch(() => ''); | |
| throw new Error(`Generation failed (${response.status}): ${text}`); | |
| } | |
| const data = (await response.json()) as NanoBananaResponse; | |
| if (!data.data || data.data.length === 0) { | |
| throw new Error('No images returned'); | |
| } | |
| return data; | |
| } | |
| export function b64ToDataUrl(b64: string, format: string = 'png'): string { | |
| const mime = format === 'jpeg' ? 'image/jpeg' : format === 'webp' ? 'image/webp' : 'image/png'; | |
| return `data:${mime};base64,${b64}`; | |
| } | |