Update sentiments.html

#1
by seonoh12 - opened
Files changed (1) hide show
  1. sentiments.html +7 -25
sentiments.html CHANGED
@@ -2,13 +2,12 @@
2
  <html lang="en">
3
 
4
  <head>
5
- <meta charset="UTF-8">
6
  <title>Sentiment Analysis - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
9
- // To-Do: transfomers.js ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ค‘ pipeline ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ import ๊ตฌ๋ฌธ์„ ์™„์„ฑํ•˜์‹ญ์‹œ์˜ค.
10
- // ํžŒํŠธ: import {}
11
-
12
  // Make it available globally
13
  window.pipeline = pipeline;
14
  </script>
@@ -106,47 +105,30 @@
106
  </div>
107
 
108
  <script>
109
-
110
  let sentimentAnalysis;
111
  let reviewer;
112
  let toxic_classifier;
113
-
114
  // Initialize the sentiment analysis model
115
  async function initializeModel() {
116
- // pipeline ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์„ฑ๋ถ„์„์— ์‚ฌ์šฉํ•  Xenova/distilbert-base-uncased-finetuned-sst-2-english ๋ชจ๋ธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ sentimentAnalysis์— ์ €์žฅํ•˜์‹ญ์‹œ์˜ค
117
- // ํžŒํŠธ: sentimentAnalysis = await pipeline
118
-
119
  }
120
-
121
  async function analyzeSentiment() {
122
  const textFieldValue = document.getElementById("sentimentText").value.trim();
123
-
124
  const result = await sentimentAnalysis(textFieldValue);
125
-
126
  document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
127
  }
128
-
129
  async function analyzeSentimentMulti() {
130
- const textFieldValue1 = document.getElementById("sentimentText1sentimentText").value.trim();
131
  const textFieldValue2 = document.getElementById("sentimentText2").value.trim();
132
- // ์œ„์—์„œ ์ƒ์„ฑํ•œ ๊ฐ์„ฑ๋ถ„์„ ๋ชจ๋ธ ๊ฐ์ฒด์— sentimentText1๊ณผ sentimentText2๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๊ฐ์ƒ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๊ทธ ๊ฒฐ๊ณผ๋ฅผ result์— ์ €์ •ํ•˜์‹ญ์‹œ์˜ค.
133
- // ํžŒํŠธ : cont result =
134
-
135
-
136
  document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
137
  }
138
-
139
-
140
  async function toxicReview() {
141
-
142
  const textFieldValue = document.getElementById("toxicText").value.trim();
143
-
144
  const result = await toxic_classifier(textFieldValue, { topk: null });
145
-
146
  document.getElementById("toxicOutputArea").innerText = JSON.stringify(result, null, 2);
147
-
148
  }
149
-
150
  // Initialize the model after the DOM is completely loaded
151
  window.addEventListener("DOMContentLoaded", initializeModel);
152
  </script>
 
2
  <html lang="en">
3
 
4
  <head>
5
+ <meta charset="UTF-8">
6
  <title>Sentiment Analysis - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
9
+ // Import the library
10
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
 
11
  // Make it available globally
12
  window.pipeline = pipeline;
13
  </script>
 
105
  </div>
106
 
107
  <script>
 
108
  let sentimentAnalysis;
109
  let reviewer;
110
  let toxic_classifier;
 
111
  // Initialize the sentiment analysis model
112
  async function initializeModel() {
113
+ sentimentAnalysis = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');
114
+ toxic_classifier = await pipeline('text-classification', 'Xenova/toxic-bert');
 
115
  }
 
116
  async function analyzeSentiment() {
117
  const textFieldValue = document.getElementById("sentimentText").value.trim();
 
118
  const result = await sentimentAnalysis(textFieldValue);
 
119
  document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
120
  }
 
121
  async function analyzeSentimentMulti() {
122
+ const textFieldValue1 = document.getElementById("sentimentText1").value.trim();
123
  const textFieldValue2 = document.getElementById("sentimentText2").value.trim();
124
+ const result = await sentimentAnalysis([textFieldValue1, textFieldValue2]);
 
 
 
125
  document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
126
  }
 
 
127
  async function toxicReview() {
 
128
  const textFieldValue = document.getElementById("toxicText").value.trim();
 
129
  const result = await toxic_classifier(textFieldValue, { topk: null });
 
130
  document.getElementById("toxicOutputArea").innerText = JSON.stringify(result, null, 2);
 
131
  }
 
132
  // Initialize the model after the DOM is completely loaded
133
  window.addEventListener("DOMContentLoaded", initializeModel);
134
  </script>