Spaces:
Running
Running
File size: 1,126 Bytes
4a22613 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | let py, ready;
async function init() {
importScripts("https://cdn.jsdelivr.net/pyodide/v0.29.3/full/pyodide.js");
py = await loadPyodide();
await py.loadPackage(["micropip", "jinja2", "markupsafe"]);
const v = py.runPython("import jinja2; jinja2.__version__");
if (v.split(".").map(Number).join(".") < "3.1.6") await py.runPythonAsync("import micropip; await micropip.install('jinja2>=3.1.6')");
for (const f of ["ctt_bench.py", "web_checker.py"]) py.FS.writeFile(f, await (await fetch(f)).text());
py.runPython("import web_checker");
}
ready = init().then(() => postMessage({ type: "ready" }), (e) => postMessage({ type: "initerror", error: String(e) }));
onmessage = async (ev) => {
await ready;
const { id, template, special } = ev.data;
try {
py.globals.set("_t", template); py.globals.set("_s", JSON.stringify(special));
const out = py.runPython("web_checker.run(_t, _s)");
postMessage({ type: "result", id, data: JSON.parse(out) });
} catch (e) { postMessage({ type: "result", id, data: { ok: false, error: "Could not run the template: " + String(e).split("\n").slice(-2)[0] } }); }
};
|