MJ106 commited on
Commit
b26190f
ยท
verified ยท
1 Parent(s): 0a881da

Update sentiments.html

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