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 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> | |