Spaces:
Running
Running
Update index.html
Browse files- index.html +45 -19
index.html
CHANGED
|
@@ -1,19 +1,45 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 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://cdnjs.cloudflare.com/ajax/libs/transformers/2.5.0/transformers.min.js"></script>
|
| 8 |
+
<style>
|
| 9 |
+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
| 10 |
+
textarea { width: 100%; height: 100px; }
|
| 11 |
+
button { margin-top: 10px; }
|
| 12 |
+
#result { margin-top: 20px; }
|
| 13 |
+
</style>
|
| 14 |
+
</head>
|
| 15 |
+
<body>
|
| 16 |
+
<h1>Transformers.js Sentiment Analysis</h1>
|
| 17 |
+
<textarea id="input" placeholder="Enter text for sentiment analysis"></textarea>
|
| 18 |
+
<button onclick="analyzeSentiment()">Analyze Sentiment</button>
|
| 19 |
+
<div id="result"></div>
|
| 20 |
+
|
| 21 |
+
<script>
|
| 22 |
+
async function analyzeSentiment() {
|
| 23 |
+
const input = document.getElementById('input').value;
|
| 24 |
+
const result = document.getElementById('result');
|
| 25 |
+
|
| 26 |
+
try {
|
| 27 |
+
// Load the sentiment analysis pipeline
|
| 28 |
+
const pipeline = await transformers.pipeline('sentiment-analysis');
|
| 29 |
+
|
| 30 |
+
// Perform sentiment analysis
|
| 31 |
+
const sentiment = await pipeline(input);
|
| 32 |
+
|
| 33 |
+
// Display the result
|
| 34 |
+
result.innerHTML = `
|
| 35 |
+
<h3>Sentiment Analysis Result:</h3>
|
| 36 |
+
<p>Label: ${sentiment[0].label}</p>
|
| 37 |
+
<p>Score: ${sentiment[0].score.toFixed(4)}</p>
|
| 38 |
+
`;
|
| 39 |
+
} catch (error) {
|
| 40 |
+
result.innerHTML = `<p>Error: ${error.message}</p>`;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
</script>
|
| 44 |
+
</body>
|
| 45 |
+
</html>
|