just / index.html
krishna195's picture
Update index.html
c3722f8 verified
raw
history blame
2.09 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Generation with LaMini-Flan-T5</title>
<script type="module">
import { pipeline } from '@xenova/transformers';
let generator;
document.addEventListener("DOMContentLoaded", async () => {
const statusDiv = document.getElementById("status");
statusDiv.innerText = "⏳ Loading model, please wait...";
try {
// Load the text-to-text generation pipeline
generator = await pipeline('text2text-generation', 'Xenova/LaMini-Flan-T5-783M');
statusDiv.innerText = "βœ… Model loaded! You can start chatting.";
statusDiv.style.color = "green";
} catch (error) {
statusDiv.innerText = "❌ Model loading failed. Check the console.";
console.error("Model loading error:", error);
}
});
async function generateText() {
const inputText = document.getElementById("userInput").value;
const outputDiv = document.getElementById("output");
if (!generator) {
outputDiv.innerText = "⚠️ Model is still loading. Please wait.";
return;
}
outputDiv.innerText = "⏳ Generating response...";
try {
const response = await generator(inputText, { max_length: 100 });
outputDiv.innerText = "πŸ€– AI: " + response[0].generated_text;
} catch (error) {
outputDiv.innerText = "❌ Error generating response.";
console.error("Generation error:", error);
}
}
</script>
</head>
<body>
<h2>LaMini-Flan-T5 Chatbot</h2>
<p id="status">πŸ”„ Initializing...</p>
<input type="text" id="userInput" placeholder="Type a message..." />
<button onclick="generateText()">Generate</button>
<p id="output"></p>
</body>
</html>