just / index.html
krishna195's picture
Update index.html
7d57aa1 verified
<!DOCTYPE html>
<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/transformers@2.5.4';
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>