krishna195 commited on
Commit
c3722f8
Β·
verified Β·
1 Parent(s): 3952763

Update index.html

Browse files
Files changed (1) hide show
  1. 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-to-Text Generation</title>
7
  <script type="module">
8
- import { pipeline } from '@huggingface/transformers';
9
 
10
- let generator = null; // Global model reference
11
-
12
- async function loadModel() {
13
- const status = document.getElementById("status");
14
- status.innerText = "🟑 Loading text generation model... Please wait.";
15
 
16
  try {
17
- generator = await pipeline('text2text-generation', 'Xenova/LaMini-Flan-T5-783M', { quantized: true });
18
- status.innerText = "βœ… Model loaded! You can start the conversation.";
19
- status.style.color = "green";
 
20
  } catch (error) {
21
- status.innerText = "❌ Model failed to load. Check the console.";
22
- console.error("Error loading model:", 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 not loaded yet!";
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 in response generation.";
41
  console.error("Generation error:", error);
42
  }
43
  }
44
-
45
- window.onload = loadModel;
46
  </script>
47
  </head>
48
  <body>
49
- <h1>Text-to-Text Generation (Xenova/LaMini-Flan-T5-783M)</h1>
50
- <p id="status" style="color: orange;">🟑 Initializing...</p>
51
 
52
- <input type="text" id="userInput" placeholder="Type something..." />
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>