Spaces:
Sleeping
Sleeping
Download backend/test-api.js from monumkp89/pixelcraft: direct link, hf CLI and curl.
- Browser
- Download file 714 Bytes
-
https://huggingface.co/spaces/monumkp89/pixelcraft/resolve/main/backend/test-api.js
- Command line
-
hf download hf://spaces/monumkp89/pixelcraft/backend/test-api.js
-
curl -L -o test-api.js https://huggingface.co/spaces/monumkp89/pixelcraft/resolve/main/backend/test-api.js
714 Bytes
| const axios = require('axios'); | |
| const token = process.env.HUGGING_FACE_API_KEY; | |
| if (!token) { | |
| console.error('Set HUGGING_FACE_API_KEY before running this script.'); | |
| process.exit(1); | |
| } | |
| axios.post( | |
| 'https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1', | |
| { inputs: 'test cat' }, | |
| { | |
| headers: { Authorization: `Bearer ${token}` }, | |
| responseType: 'arraybuffer', | |
| timeout: 30000 | |
| } | |
| ).then(r => { | |
| console.log('✅ Hugging Face API works! Image generated, size:', r.data.length, 'bytes'); | |
| }).catch(e => { | |
| console.log('❌ Error:', e.response?.status, e.message); | |
| if (e.response?.data) { | |
| console.log('Response:', e.response.data.toString()); | |
| } | |
| }); | |