Spaces:
Running
Running
Update sentiments.html
Browse files- sentiments.html +7 -30
sentiments.html
CHANGED
|
@@ -6,12 +6,8 @@
|
|
| 6 |
<title>Sentiment Analysis - Hugging Face Transformers.js</title>
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
// To-Do: transfomers.js ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค pipeline ํจ์๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ import ๊ตฌ๋ฌธ์ ์์ฑํ์ญ์์ค.
|
| 13 |
-
// ํํธ: import {}
|
| 14 |
-
|
| 15 |
// Make it available globally
|
| 16 |
window.pipeline = pipeline;
|
| 17 |
</script>
|
|
@@ -108,50 +104,31 @@
|
|
| 108 |
</div>
|
| 109 |
</div>
|
| 110 |
|
| 111 |
-
<script>
|
| 112 |
-
|
| 113 |
let sentimentAnalysis;
|
| 114 |
let reviewer;
|
| 115 |
let toxic_classifier;
|
| 116 |
-
|
| 117 |
// Initialize the sentiment analysis model
|
| 118 |
async function initializeModel() {
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
sentimentAnalysis = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');
|
| 122 |
-
toxic_classifier = await pipeline('text-classification', 'Xenova/toxic-bert');
|
| 123 |
}
|
| 124 |
-
|
| 125 |
async function analyzeSentiment() {
|
| 126 |
const textFieldValue = document.getElementById("sentimentText").value.trim();
|
| 127 |
-
|
| 128 |
const result = await sentimentAnalysis(textFieldValue);
|
| 129 |
-
|
| 130 |
document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
|
| 131 |
}
|
| 132 |
-
|
| 133 |
async function analyzeSentimentMulti() {
|
| 134 |
-
const textFieldValue1 = document.getElementById("
|
| 135 |
const textFieldValue2 = document.getElementById("sentimentText2").value.trim();
|
| 136 |
-
|
| 137 |
-
// ํํธ : cont result =
|
| 138 |
-
|
| 139 |
-
const result = await sentimentAnalysis([textFieldValue1, textFieldValue2]);
|
| 140 |
-
|
| 141 |
document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
|
| 142 |
}
|
| 143 |
-
|
| 144 |
-
|
| 145 |
async function toxicReview() {
|
| 146 |
-
|
| 147 |
const textFieldValue = document.getElementById("toxicText").value.trim();
|
| 148 |
-
|
| 149 |
const result = await toxic_classifier(textFieldValue, { topk: null });
|
| 150 |
-
|
| 151 |
document.getElementById("toxicOutputArea").innerText = JSON.stringify(result, null, 2);
|
| 152 |
-
|
| 153 |
}
|
| 154 |
-
|
| 155 |
// Initialize the model after the DOM is completely loaded
|
| 156 |
window.addEventListener("DOMContentLoaded", initializeModel);
|
| 157 |
</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>
|
|
|
|
| 104 |
</div>
|
| 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>
|