File size: 2,276 Bytes
fb5f1e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | const http = require('http'), fs = require('fs'), path = require('path');
const PORT = 8170;
const ROOT = __dirname;
const MODEL_DIR = path.join(ROOT, 'model_splits');
const MIME = {
'.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
'.json': 'application/json', '.gguf': 'application/octet-stream',
'.wasm': 'application/wasm', '.css': 'text/css',
};
http.createServer((req, res) => {
if (req.method === 'OPTIONS') {
res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,HEAD',
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
});
return res.end();
}
let p = decodeURIComponent(req.url.split('?')[0]);
if (p === '/') p = '/index.html';
let fp;
if (p.startsWith('/model/')) {
fp = path.join(MODEL_DIR, p.slice('/model/'.length));
} else {
fp = path.resolve(ROOT, '.' + p);
}
fs.stat(fp, (e, st) => {
if (e) { res.writeHead(404); return res.end('not found: ' + p); }
const total = st.size;
const range = req.headers.range;
const ct = MIME[path.extname(fp)] || 'application/octet-stream';
const headers = {
'Content-Type': ct, 'Accept-Ranges': 'bytes',
'Access-Control-Allow-Origin': '*',
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
};
if (range) {
const m = range.match(/bytes=(\d+)-(\d*)/);
if (m) {
const start = parseInt(m[1]);
const end = m[2] ? parseInt(m[2]) : total - 1;
headers['Content-Range'] = `bytes ${start}-${end}/${total}`;
headers['Content-Length'] = end - start + 1;
res.writeHead(206, headers);
return fs.createReadStream(fp, { start, end }).pipe(res);
}
}
headers['Content-Length'] = total;
res.writeHead(200, headers);
fs.createReadStream(fp).pipe(res);
});
}).listen(PORT, () => {
console.log(`EXAONE-Deep WebGPU on http://localhost:${PORT}`);
console.log(`Model splits: ${MODEL_DIR}`);
try {
const files = fs.readdirSync(MODEL_DIR).filter(f => f.endsWith('.gguf'));
console.log(`Split files: ${files.length}`);
} catch(e) { console.log('No model_splits dir yet'); }
});
|