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

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +31 -33
index.html CHANGED
@@ -3,54 +3,52 @@
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>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Text Generation with DistilGPT-2</title>
7
+ </head>
8
+ <body>
9
+ <h2>Text Generation using DistilGPT-2</h2>
10
+ <p id="status">⏳ Loading model, please wait...</p>
11
+ <textarea id="inputText" rows="3" cols="50" placeholder="Enter your text..."></textarea>
12
+ <button id="generateBtn" disabled>Generate Text</button>
13
+ <p><strong>Generated Output:</strong></p>
14
+ <p id="output"></p>
15
+
16
  <script type="module">
17
+ import { pipeline } from "@xenova/transformers";
18
 
19
  let generator;
20
+ async function initializeModel() {
21
+ document.getElementById("status").innerText = "⏳ Loading model, please wait...";
 
 
22
  try {
23
+ generator = await pipeline("text-generation", "Xenova/distilgpt2");
24
+ document.getElementById("status").innerText = "βœ… Model loaded! Ready to generate text.";
25
+ document.getElementById("generateBtn").disabled = false;
 
26
  } catch (error) {
27
+ document.getElementById("status").innerText = "❌ Failed to load model.";
28
  console.error("Model loading error:", error);
29
  }
30
+ }
31
 
32
  async function generateText() {
33
+ const inputText = document.getElementById("inputText").value;
34
+ if (!inputText.trim()) {
35
+ alert("Please enter some text!");
 
 
36
  return;
37
  }
38
+ document.getElementById("output").innerText = "⏳ Generating...";
 
 
39
  try {
40
+ const output = await generator(inputText, { max_new_tokens: 64, do_sample: true });
41
+ document.getElementById("output").innerText = output[0].generated_text;
42
  } catch (error) {
43
+ document.getElementById("output").innerText = "❌ Error in generation.";
44
+ console.error("Text generation error:", error);
45
  }
46
  }
47
+
48
+ document.getElementById("generateBtn").addEventListener("click", generateText);
49
+
50
+ // Initialize model on page load
51
+ initializeModel();
52
  </script>
 
 
 
 
 
 
 
 
 
53
  </body>
54
  </html>