Spaces:
Running
Running
Update index.html
Browse files- index.html +21 -22
index.html
CHANGED
@@ -3,55 +3,54 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Text-
|
7 |
<script type="module">
|
8 |
-
import { pipeline } from '@
|
9 |
|
10 |
-
let generator
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
status.innerText = "π‘ Loading text generation model... Please wait.";
|
15 |
|
16 |
try {
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
} catch (error) {
|
21 |
-
|
22 |
-
console.error("
|
23 |
}
|
24 |
-
}
|
25 |
|
26 |
async function generateText() {
|
27 |
const inputText = document.getElementById("userInput").value;
|
28 |
const outputDiv = document.getElementById("output");
|
29 |
|
30 |
if (!generator) {
|
31 |
-
outputDiv.innerText = "
|
32 |
return;
|
33 |
}
|
34 |
|
35 |
outputDiv.innerText = "β³ Generating response...";
|
|
|
36 |
try {
|
37 |
-
const response = await generator(inputText);
|
38 |
outputDiv.innerText = "π€ AI: " + response[0].generated_text;
|
39 |
} catch (error) {
|
40 |
-
outputDiv.innerText = "β Error
|
41 |
console.error("Generation error:", error);
|
42 |
}
|
43 |
}
|
44 |
-
|
45 |
-
window.onload = loadModel;
|
46 |
</script>
|
47 |
</head>
|
48 |
<body>
|
49 |
-
<
|
50 |
-
<p id="status"
|
51 |
|
52 |
-
<input type="text" id="userInput" placeholder="Type
|
53 |
<button onclick="generateText()">Generate</button>
|
54 |
-
|
55 |
<p id="output"></p>
|
56 |
</body>
|
57 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Text Generation with LaMini-Flan-T5</title>
|
7 |
<script type="module">
|
8 |
+
import { pipeline } from '@xenova/transformers';
|
9 |
|
10 |
+
let generator;
|
11 |
+
document.addEventListener("DOMContentLoaded", async () => {
|
12 |
+
const statusDiv = document.getElementById("status");
|
13 |
+
statusDiv.innerText = "β³ Loading model, please wait...";
|
|
|
14 |
|
15 |
try {
|
16 |
+
// Load the text-to-text generation pipeline
|
17 |
+
generator = await pipeline('text2text-generation', 'Xenova/LaMini-Flan-T5-783M');
|
18 |
+
statusDiv.innerText = "β
Model loaded! You can start chatting.";
|
19 |
+
statusDiv.style.color = "green";
|
20 |
} catch (error) {
|
21 |
+
statusDiv.innerText = "β Model loading failed. Check the console.";
|
22 |
+
console.error("Model loading error:", error);
|
23 |
}
|
24 |
+
});
|
25 |
|
26 |
async function generateText() {
|
27 |
const inputText = document.getElementById("userInput").value;
|
28 |
const outputDiv = document.getElementById("output");
|
29 |
|
30 |
if (!generator) {
|
31 |
+
outputDiv.innerText = "β οΈ Model is still loading. Please wait.";
|
32 |
return;
|
33 |
}
|
34 |
|
35 |
outputDiv.innerText = "β³ Generating response...";
|
36 |
+
|
37 |
try {
|
38 |
+
const response = await generator(inputText, { max_length: 100 });
|
39 |
outputDiv.innerText = "π€ AI: " + response[0].generated_text;
|
40 |
} catch (error) {
|
41 |
+
outputDiv.innerText = "β Error generating response.";
|
42 |
console.error("Generation error:", error);
|
43 |
}
|
44 |
}
|
|
|
|
|
45 |
</script>
|
46 |
</head>
|
47 |
<body>
|
48 |
+
<h2>LaMini-Flan-T5 Chatbot</h2>
|
49 |
+
<p id="status">π Initializing...</p>
|
50 |
|
51 |
+
<input type="text" id="userInput" placeholder="Type a message..." />
|
52 |
<button onclick="generateText()">Generate</button>
|
53 |
+
|
54 |
<p id="output"></p>
|
55 |
</body>
|
56 |
</html>
|