Spaces:
Running
Running
graph
Browse files- index.html +31 -1
index.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Sentiment Analysis Web App</title>
|
| 7 |
<link rel="stylesheet" href="style.css">
|
|
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="container">
|
|
@@ -12,6 +13,7 @@
|
|
| 12 |
<textarea id="textInput" placeholder="Enter text..."></textarea>
|
| 13 |
<button onclick="classifySentiment()">Classify</button>
|
| 14 |
<div id="result" class="result-container"></div>
|
|
|
|
| 15 |
</div>
|
| 16 |
|
| 17 |
<script>
|
|
@@ -40,6 +42,8 @@
|
|
| 40 |
|
| 41 |
function classifySentiment() {
|
| 42 |
const textInput = document.getElementById("textInput").value;
|
|
|
|
|
|
|
| 43 |
|
| 44 |
if (textInput.trim() === "") {
|
| 45 |
alert("Please enter text for sentiment analysis.");
|
|
@@ -62,10 +66,36 @@
|
|
| 62 |
return `
|
| 63 |
<div class="result-item">
|
| 64 |
<p>Sentiment: ${prediction.label}</p>
|
| 65 |
-
<p>Confidence Score: ${prediction.score}</p>
|
| 66 |
</div>
|
| 67 |
`;
|
| 68 |
}).join('');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
} else {
|
| 70 |
resultDiv.textContent = "Unable to determine sentiment.";
|
| 71 |
}
|
|
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Sentiment Analysis Web App</title>
|
| 7 |
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
<div class="container">
|
|
|
|
| 13 |
<textarea id="textInput" placeholder="Enter text..."></textarea>
|
| 14 |
<button onclick="classifySentiment()">Classify</button>
|
| 15 |
<div id="result" class="result-container"></div>
|
| 16 |
+
<canvas id="chart"></canvas>
|
| 17 |
</div>
|
| 18 |
|
| 19 |
<script>
|
|
|
|
| 42 |
|
| 43 |
function classifySentiment() {
|
| 44 |
const textInput = document.getElementById("textInput").value;
|
| 45 |
+
const chartCanvas = document.getElementById("chart");
|
| 46 |
+
|
| 47 |
|
| 48 |
if (textInput.trim() === "") {
|
| 49 |
alert("Please enter text for sentiment analysis.");
|
|
|
|
| 66 |
return `
|
| 67 |
<div class="result-item">
|
| 68 |
<p>Sentiment: ${prediction.label}</p>
|
| 69 |
+
<p>Confidence Score: ${prediction.score*100}</p>
|
| 70 |
</div>
|
| 71 |
`;
|
| 72 |
}).join('');
|
| 73 |
+
|
| 74 |
+
const labels = predictions.map(prediction => prediction.label);
|
| 75 |
+
const scores = predictions.map(prediction => prediction.score * 100); // Scale scores to percentage
|
| 76 |
+
|
| 77 |
+
const ctx = chartCanvas.getContext('2d');
|
| 78 |
+
const chart = new Chart(ctx, {
|
| 79 |
+
type: 'bar',
|
| 80 |
+
data: {
|
| 81 |
+
labels: labels,
|
| 82 |
+
datasets: [{
|
| 83 |
+
label: 'Confidence Scores (%)',
|
| 84 |
+
data: scores,
|
| 85 |
+
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
| 86 |
+
borderColor: 'rgba(75, 192, 192, 1)',
|
| 87 |
+
borderWidth: 1
|
| 88 |
+
}]
|
| 89 |
+
},
|
| 90 |
+
options: {
|
| 91 |
+
scales: {
|
| 92 |
+
y: {
|
| 93 |
+
beginAtZero: true,
|
| 94 |
+
max: 100
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
});
|
| 99 |
} else {
|
| 100 |
resultDiv.textContent = "Unable to determine sentiment.";
|
| 101 |
}
|