Download scripts/qa-plugin.js from ProCreations/minicpm5-2b-webgpu: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/spaces/ProCreations/minicpm5-2b-webgpu/resolve/main/scripts/qa-plugin.js
- Command line
-
hf download hf://spaces/ProCreations/minicpm5-2b-webgpu/scripts/qa-plugin.js
-
curl -L -o qa-plugin.js https://huggingface.co/spaces/ProCreations/minicpm5-2b-webgpu/resolve/main/scripts/qa-plugin.js
1.76 kB
| import fs from 'node:fs'; | |
| import path from 'node:path'; | |
| export function qaPlugin(){return {name:'local-qa',configureServer(server){server.middlewares.use('/__qa',async(req,res,next)=>{if(req.method==='GET'&&req.url==='/dspark'&&['127.0.0.1','::1','::ffff:127.0.0.1'].includes(req.socket.remoteAddress)){const filename='/tmp/minicpm-weights/dspark.safetensors';res.setHeader('Content-Length',fs.statSync(filename).size);fs.createReadStream(filename).pipe(res);return;}if(req.method==='GET'&&req.url.startsWith('/model/')&&['127.0.0.1','::1','::ffff:127.0.0.1'].includes(req.socket.remoteAddress)){const name=path.basename(req.url.slice(7));if(!/^MiniCPM5-2B-Q8_0-\d{5}-of-00006\.gguf$/.test(name)){res.statusCode=404;return res.end();}const filename=path.join('/tmp/minicpm-weights/split',name);res.setHeader('Content-Type','application/octet-stream');res.setHeader('Content-Length',fs.statSync(filename).size);fs.createReadStream(filename).pipe(res);return;}if(req.method==='HEAD'&&req.url.startsWith('/model/')){const name=path.basename(req.url.slice(7));if(!/^MiniCPM5-2B-Q8_0-\d{5}-of-00006\.gguf$/.test(name)){res.statusCode=404;return res.end();}res.setHeader('Content-Length',fs.statSync(path.join('/tmp/minicpm-weights/split',name)).size);return res.end();}if(req.method!=='POST')return next();if(!['127.0.0.1','::1','::ffff:127.0.0.1'].includes(req.socket.remoteAddress)){res.statusCode=403;return res.end();}const chunks=[];for await(const c of req)chunks.push(c);const data=Buffer.concat(chunks);fs.mkdirSync('.qa',{recursive:true});const name=req.url.startsWith('/file/')?path.basename(decodeURIComponent(req.url.slice(6))):req.url==='/report-local'?'report-local.json':'report.json';fs.writeFileSync(path.join('.qa',name),data);res.end('ok');});}};} | |