arvindk1 commited on
Commit
8ad0605
·
verified ·
1 Parent(s): 71a1747

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +13 -11
index.html CHANGED
@@ -4,7 +4,6 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Transformers.js Sentiment Analysis</title>
7
- <script src="https://cdn.jsdelivr.net/npm/@xenova/[email protected]"></script>
8
  <style>
9
  body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
10
  textarea { width: 100%; height: 100px; }
@@ -15,17 +14,18 @@
15
  <body>
16
  <h1>Transformers.js Sentiment Analysis</h1>
17
  <textarea id="input" placeholder="Enter text for sentiment analysis">I love this movie! It's amazing!</textarea>
18
- <button onclick="analyzeSentiment()">Analyze Sentiment</button>
19
  <div id="result"></div>
20
 
21
- <script>
22
- // Use the pipeline from Xenova's transformers package
23
- let pipeline;
24
-
 
25
  async function loadPipeline() {
26
  try {
27
- pipeline = await transformers.pipeline('sentiment-analysis');
28
- document.querySelector('button').disabled = false;
29
  } catch (error) {
30
  console.error('Error loading pipeline:', error);
31
  document.getElementById('result').innerHTML = `<p>Error: ${error.message}</p>`;
@@ -44,12 +44,12 @@
44
  result.innerHTML = '<p>Analyzing...</p>';
45
 
46
  try {
47
- if (!pipeline) {
48
  throw new Error('Pipeline not loaded. Please wait and try again.');
49
  }
50
 
51
  // Perform sentiment analysis
52
- const sentiment = await pipeline(input);
53
 
54
  // Display the result
55
  result.innerHTML = `
@@ -64,8 +64,10 @@
64
  }
65
 
66
  // Load the pipeline when the page loads
67
- document.querySelector('button').disabled = true;
68
  loadPipeline();
 
 
 
69
  </script>
70
  </body>
71
  </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Transformers.js Sentiment Analysis</title>
 
7
  <style>
8
  body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
9
  textarea { width: 100%; height: 100px; }
 
14
  <body>
15
  <h1>Transformers.js Sentiment Analysis</h1>
16
  <textarea id="input" placeholder="Enter text for sentiment analysis">I love this movie! It's amazing!</textarea>
17
+ <button id="analyzeButton" disabled>Analyze Sentiment</button>
18
  <div id="result"></div>
19
 
20
+ <script type="module">
21
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.0';
22
+
23
+ let sentimentPipeline;
24
+
25
  async function loadPipeline() {
26
  try {
27
+ sentimentPipeline = await pipeline('sentiment-analysis');
28
+ document.getElementById('analyzeButton').disabled = false;
29
  } catch (error) {
30
  console.error('Error loading pipeline:', error);
31
  document.getElementById('result').innerHTML = `<p>Error: ${error.message}</p>`;
 
44
  result.innerHTML = '<p>Analyzing...</p>';
45
 
46
  try {
47
+ if (!sentimentPipeline) {
48
  throw new Error('Pipeline not loaded. Please wait and try again.');
49
  }
50
 
51
  // Perform sentiment analysis
52
+ const sentiment = await sentimentPipeline(input);
53
 
54
  // Display the result
55
  result.innerHTML = `
 
64
  }
65
 
66
  // Load the pipeline when the page loads
 
67
  loadPipeline();
68
+
69
+ // Add event listener to the button
70
+ document.getElementById('analyzeButton').addEventListener('click', analyzeSentiment);
71
  </script>
72
  </body>
73
  </html>