Spaces:
Running
Running
import { pipeline, env } from "@xenova/transformers"; | |
async function main() { | |
const inputEl = document.getElementById("input-text"); | |
const btnEl = document.getElementById("generate-btn"); | |
const outEl = document.getElementById("output-text"); | |
// (Optional) force ONNX CPU backend | |
env.backends.onnx.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2/dist/"; | |
env.useWasmCPU(); | |
// Load the text2text-generation pipeline with the ONNX weights | |
// hosted at onnx-community/orpheus-3b-0.1-ft-ONNX :contentReference[oaicite:0]{index=0} | |
const generator = await pipeline( | |
"text2text-generation", | |
"onnx-community/orpheus-3b-0.1-ft-ONNX" | |
); | |
// Enable button once ready | |
btnEl.disabled = false; | |
btnEl.addEventListener("click", async () => { | |
const prompt = inputEl.value.trim(); | |
if (!prompt) return; | |
btnEl.disabled = true; | |
outEl.textContent = "Generating…"; | |
try { | |
// Generate up to 256 tokens; adjust max_length as needed :contentReference[oaicite:1]{index=1} | |
const [res] = await generator(prompt, { max_length: 256 }); | |
outEl.textContent = res.generated_text; | |
} catch (err) { | |
outEl.textContent = `Error: ${err}`; | |
} finally { | |
btnEl.disabled = false; | |
} | |
}); | |
} | |
main(); | |