Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Text Generation - LaMini-Flan-T5</title> | |
<script type="module"> | |
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]'; | |
let generator; | |
async function loadModel() { | |
document.getElementById("status").innerText = "β³ Loading model..."; | |
try { | |
generator = await pipeline('text2text-generation', 'Xenova/LaMini-Flan-T5-783M'); | |
document.getElementById("status").innerText = "β Model loaded!"; | |
document.getElementById("generateBtn").disabled = false; | |
} catch (error) { | |
document.getElementById("status").innerText = "β Error loading model."; | |
console.error("Model load error:", error); | |
} | |
} | |
async function generateText() { | |
const inputText = document.getElementById("inputText").value.trim(); | |
if (!inputText) { | |
alert("Please enter some text!"); | |
return; | |
} | |
document.getElementById("output").innerText = "β³ Generating..."; | |
try { | |
const output = await generator(inputText, { max_new_tokens: 100 }); | |
document.getElementById("output").innerText = output[0].generated_text; | |
} catch (error) { | |
document.getElementById("output").innerText = "β Error generating text."; | |
console.error("Generation error:", error); | |
} | |
} | |
window.addEventListener("DOMContentLoaded", loadModel); | |
window.generateText = generateText; | |
</script> | |
</head> | |
<body> | |
<h2>Text Generation using LaMini-Flan-T5</h2> | |
<p id="status">β³ Loading model...</p> | |
<textarea id="inputText" rows="3" cols="50" placeholder="Enter text..."></textarea> | |
<br><br> | |
<button id="generateBtn" onclick="generateText()" disabled>Generate</button> | |
<h3>Output:</h3> | |
<pre id="output"></pre> | |
</body> | |
</html> | |