oceankim commited on
Commit
c9bd8ba
1 Parent(s): b4f37d3

Update sentiments.html

Browse files
Files changed (1) hide show
  1. sentiments.html +133 -11
sentiments.html CHANGED
@@ -1,15 +1,137 @@
1
- <!DOCTYPE html><html lang="en">
2
- <head> <meta charset="UTF-8"> <title>Sentiment Analysis - Hugging Face Transformers.js</title>
3
- <script type="module"> // Import the library import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.4'; // Make it available globally window.pipeline = pipeline; </script>
 
 
 
 
 
 
 
 
 
 
 
4
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">
5
- <link rel="stylesheet" href="css/styles.css"></head>
6
- <body> <div class="container-main"> <!-- Back to Home button --> <div class="row mt-5"> <div class="col-md-12 text-center"> <a href="index.html" class="btn btn-outline-secondary" style="color: #3C650B; border-color: #3C650B;">Back to Main Page</a> </div> </div>
7
- <!-- Content --> <div class="container mt-5"> <!-- Centered Titles --> <div class="text-center"> <h2>Natural Language Processing</h2> <h4>Sentiment Analysis (Text Classification)</h4> </div>
8
- <!-- Actual Content of this page --> <div id="sentiment-analyzer-container" class="container mt-4"> <h5>Single Input:</h5> <div class="d-flex align-items-center"> <label for="sentimentText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to Analyze:</label> <input type="text" class="form-control flex-grow-1" id="sentimentText" value="I love transformers!" placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;"> <button id="analyzeButton" class="btn btn-primary" onclick="analyzeSentiment()">Analyze</button> </div> <div class="mt-4"> <h4>Output:</h4> <pre id="outputArea"></pre> </div> </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  <hr> <!-- Line Separator -->
10
- <div id="sentiment-analyzer-container2" class="container mt-4"> <h5>Multiple Inputs:</h5> <div class="d-flex align-items-center mb-2"> <label for="sentimentText1" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to Analyze 1:</label> <input type="text" class="form-control flex-grow-1" id="sentimentText1" value="I love transformers!" placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;"> </div> <div class="d-flex align-items-center"> <label for="sentimentText2" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to Analyze 2:</label> <input type="text" class="form-control flex-grow-1" id="sentimentText2" value="I hate transformers!" placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;"> <button id="analyzeButton" class="btn btn-primary ml-2" onclick="analyzeSentimentMulti()">Analyze</button> </div> <div class="mt-4"> <h4>Output:</h4> <pre id="outputArea2"></pre> </div> </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  <hr> <!-- Line Separator -->
12
- <!-- Toxic Comment Classification --> <div id="toxic-container" class="container mt-4"> <h5>Toxic Comment Classification (Return All Classes):</h5> <div class="d-flex align-items-center"> <label for="toxicText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Toxic Text:</label> <input type="text" class="form-control flex-grow-1" id="toxicText" value="I hate you!" placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;"> <button id="toxicButton" class="btn btn-primary" onclick="toxicReview()">Review</button> </div> <div class="mt-4"> <h4>Output:</h4> <pre id="toxicOutputArea"></pre> </div> </div>
13
- <!-- Back to Home button --> <div class="row mt-5"> <div class="col-md-12 text-center"> <a href="index.html" class="btn btn-outline-secondary" style="color: #3C650B; border-color: #3C650B;">Back to Main Page</a> </div> </div> </div> </div>
14
- <script> let sentimentAnalysis; let reviewer; let toxic_classifier; // Initialize the sentiment analysis model async function initializeModel() { sentimentAnalysis = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english'); toxic_classifier = await pipeline('text-classification', 'Xenova/toxic-bert'); } async function analyzeSentiment() { const textFieldValue = document.getElementById("sentimentText").value.trim(); const result = await sentimentAnalysis(textFieldValue); document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2); } async function analyzeSentimentMulti() { const textFieldValue1 = document.getElementById("sentimentText1").value.trim(); const textFieldValue2 = document.getElementById("sentimentText2").value.trim(); const result = await sentimentAnalysis([textFieldValue1, textFieldValue2]); document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2); } async function toxicReview() { const textFieldValue = document.getElementById("toxicText").value.trim(); const result = await toxic_classifier(textFieldValue, { topk: null }); document.getElementById("toxicOutputArea").innerText = JSON.stringify(result, null, 2); } // Initialize the model after the DOM is completely loaded window.addEventListener("DOMContentLoaded", initializeModel); </script></body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  </html>
 
1
+ <!DOCTYPE html>
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/transformers@2.5.4';
11
+ // Make it available globally
12
+ window.pipeline = pipeline;
13
+ </script>
14
+
15
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">
16
+
17
+ <link rel="stylesheet" href="css/styles.css">
18
+ </head>
19
+
20
+ <body>
21
+ <div class="container-main">
22
+
23
+ <!-- Back to Home button -->
24
+ <div class="row mt-5">
25
+ <div class="col-md-12 text-center">
26
+ <a href="index.html" class="btn btn-outline-secondary"
27
+ style="color: #3c650b; border-color: #3c650b;">Back to Main Page</a>
28
+ </div>
29
+ </div>
30
+
31
+ <!-- Content -->
32
+ <div class="container mt-5">
33
+ <!-- Centered Titles -->
34
+ <div class="text-center">
35
+ <h2>Natural Language Processing</h2>
36
+ <h4>Sentiment Analysis (Text Classification)</h4>
37
+ </div>
38
+
39
+ <!-- Actual Content of this page -->
40
+ <div id="sentiment-analyzer-container" class="container mt-4">
41
+ <h5>Single Input:</h5>
42
+ <div class="d-flex align-items-center">
43
+ <label for="sentimentText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to
44
+ Analyze:</label>
45
+ <input type="text" class="form-control flex-grow-1" id="sentimentText" value="I love transformers!"
46
+ placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;">
47
+ <button id="analyzeButton" class="btn btn-primary" onclick="analyzeSentiment()">Analyze</button>
48
+ </div>
49
+ <div class="mt-4">
50
+ <h4>Output:</h4>
51
+ <pre id="outputArea"></pre>
52
+ </div>
53
+ </div>
54
+
55
  <hr> <!-- Line Separator -->
56
+
57
+ <div id="sentiment-analyzer-container2" class="container mt-4">
58
+ <h5>Multiple Inputs:</h5>
59
+ <div class="d-flex align-items-center mb-2">
60
+ <label for="sentimentText1" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to
61
+ Analyze 1:</label>
62
+ <input type="text" class="form-control flex-grow-1" id="sentimentText1" value="I love transformers!"
63
+ placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;">
64
+ </div>
65
+ <div class="d-flex align-items-center">
66
+ <label for="sentimentText2" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to
67
+ Analyze 2:</label>
68
+ <input type="text" class="form-control flex-grow-1" id="sentimentText2" value="I hate transformers!"
69
+ placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;">
70
+ <button id="analyzeButton" class="btn btn-primary ml-2"
71
+ onclick="analyzeSentimentMulti()">Analyze</button>
72
+ </div>
73
+ <div class="mt-4">
74
+ <h4>Output:</h4>
75
+ <pre id="outputArea2"></pre>
76
+ </div>
77
+ </div>
78
+
79
  <hr> <!-- Line Separator -->
80
+
81
+ <!-- Toxic Comment Classification -->
82
+ <div id="toxic-container" class="container mt-4">
83
+ <h5>Toxic Comment Classification (Return All Classes):</h5>
84
+ <div class="d-flex align-items-center">
85
+ <label for="toxicText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Toxic
86
+ Text:</label>
87
+ <input type="text" class="form-control flex-grow-1" id="toxicText" value="I hate you!"
88
+ placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;">
89
+ <button id="toxicButton" class="btn btn-primary" onclick="toxicReview()">Review</button>
90
+ </div>
91
+ <div class="mt-4">
92
+ <h4>Output:</h4>
93
+ <pre id="toxicOutputArea"></pre>
94
+ </div>
95
+ </div>
96
+
97
+ <!-- Back to Home button -->
98
+ <div class="row mt-5">
99
+ <div class="col-md-12 text-center">
100
+ <a href="index.html" class="btn btn-outline-secondary"
101
+ style="color: #3c650b; border-color: #3c650b;">Back to Main Page</a>
102
+ </div>
103
+ </div>
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>
135
+ </body>
136
+
137
  </html>