Download server.js from LokeshEka/chart: direct link, hf CLI and curl.
- Browser
- Download file 578 Bytes
-
https://huggingface.co/spaces/LokeshEka/chart/resolve/main/server.js
- Command line
-
hf download hf://spaces/LokeshEka/chart/server.js
-
curl -L -o server.js https://huggingface.co/spaces/LokeshEka/chart/resolve/main/server.js
578 Bytes
| import express from 'express'; | |
| import { render } from '@antv/gpt-vis-ssr'; | |
| const app = express(); | |
| app.use(express.json()); | |
| app.post('/api/chart', async (req, res) => { | |
| try { | |
| const options = req.body; // chart options (type, data, etc.) | |
| const vis = await render(options); | |
| const buffer = vis.toBuffer(); | |
| res.setHeader('Content-Type', 'image/png'); | |
| res.send(buffer); | |
| } catch (err) { | |
| res.status(400).json({ error: err.message }); | |
| } | |
| }); | |
| const port = process.env.PORT || 7860; | |
| app.listen(port, () => { | |
| console.log('API running on port ' + port); | |
| }); |