Spaces:
Running
Running
Download caption-worker.js from SimonHWu2026/Topic5APIC: direct link, hf CLI and curl.
- Browser
- Download file 549 Bytes
-
https://huggingface.co/spaces/SimonHWu2026/Topic5APIC/resolve/main/caption-worker.js
- Command line
-
hf download hf://spaces/SimonHWu2026/Topic5APIC/caption-worker.js
-
curl -L -o caption-worker.js https://huggingface.co/spaces/SimonHWu2026/Topic5APIC/resolve/main/caption-worker.js
549 Bytes
| import { captionImage } from './captioner.js'; | |
| let busy = false; | |
| self.onmessage = async ({ data }) => { | |
| if (busy || data.type !== 'caption') return; | |
| busy = true; | |
| const { id, image, options } = data; | |
| try { | |
| const result = await captionImage(image, options, progress => self.postMessage({ type: 'progress', id, progress })); | |
| self.postMessage({ type: 'result', id, result }); | |
| } catch (error) { | |
| self.postMessage({ type: 'error', id, message: String(error?.message ?? error).slice(0, 500) }); | |
| } finally { | |
| busy = false; | |
| } | |
| }; | |