Spaces:
Running
Running
Upload 2 files
Browse files- index.html +121 -0
- style.css +84 -7
index.html
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>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 |
+
<header class="header">
|
12 |
+
<h1>AI BATTLEGROUND 2023</h1>
|
13 |
+
</header>
|
14 |
+
<div class="container">
|
15 |
+
<h1>Sentiment Analysis</h1>
|
16 |
+
<textarea id="textInput" placeholder="Enter text..."></textarea><br>
|
17 |
+
<button onclick="classifySentiment()">Classify</button>
|
18 |
+
<div id="result" class="result-container"></div>
|
19 |
+
<canvas id="chart"></canvas>
|
20 |
+
</div>
|
21 |
+
|
22 |
+
<footer class="footer">
|
23 |
+
<p>© Team AIQA</p>
|
24 |
+
</footer>
|
25 |
+
|
26 |
+
<script>
|
27 |
+
let chart; // Declare chart variable outside the function
|
28 |
+
|
29 |
+
async function query(data) {
|
30 |
+
try {
|
31 |
+
const response = await fetch(
|
32 |
+
"https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis",
|
33 |
+
{
|
34 |
+
headers: { Authorization: "Bearer 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" },
|
35 |
+
method: "POST",
|
36 |
+
body: JSON.stringify(data),
|
37 |
+
}
|
38 |
+
);
|
39 |
+
|
40 |
+
if (!response.ok) {
|
41 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
42 |
+
}
|
43 |
+
|
44 |
+
const result = await response.json();
|
45 |
+
return result;
|
46 |
+
} catch (error) {
|
47 |
+
console.error("Error during API request:", error);
|
48 |
+
return { error: "Failed to get predictions from the model." };
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
function classifySentiment() {
|
53 |
+
const textInput = document.getElementById("textInput").value;
|
54 |
+
const chartCanvas = document.getElementById("chart");
|
55 |
+
|
56 |
+
if (textInput.trim() === "") {
|
57 |
+
alert("Please enter text for sentiment analysis.");
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
|
61 |
+
const data = { "inputs": textInput };
|
62 |
+
|
63 |
+
// Call the query function and handle the response
|
64 |
+
query(data).then((response) => {
|
65 |
+
console.log(JSON.stringify(response));
|
66 |
+
|
67 |
+
const resultDiv = document.getElementById("result");
|
68 |
+
|
69 |
+
if (response && Array.isArray(response) && response.length > 0) {
|
70 |
+
const predictions = response[0];
|
71 |
+
|
72 |
+
// Display the results for each sentiment label and score
|
73 |
+
resultDiv.innerHTML = predictions.map((prediction) => {
|
74 |
+
return `
|
75 |
+
<div class="result-item">
|
76 |
+
<p>Sentiment: ${prediction.label}</p>
|
77 |
+
<p>Confidence Score: ${(prediction.score*100).toFixed(0)}</p>
|
78 |
+
</div>
|
79 |
+
`;
|
80 |
+
}).join('');
|
81 |
+
|
82 |
+
// Destroy the existing chart if it exists
|
83 |
+
if (chart) {
|
84 |
+
chart.destroy();
|
85 |
+
}
|
86 |
+
|
87 |
+
// Create a new bar chart
|
88 |
+
const labels = predictions.map(prediction => prediction.label);
|
89 |
+
const scores = predictions.map(prediction => prediction.score * 100); // Scale scores to percentage
|
90 |
+
|
91 |
+
const ctx = chartCanvas.getContext('2d');
|
92 |
+
chart = new Chart(ctx, {
|
93 |
+
type: 'bar',
|
94 |
+
data: {
|
95 |
+
labels: labels,
|
96 |
+
datasets: [{
|
97 |
+
label: 'Confidence Scores (%)',
|
98 |
+
data: scores,
|
99 |
+
backgroundColor: 'rgba(255, 0, 0, 0.2)', // Red color with 20% opacity
|
100 |
+
borderColor: 'rgba(255, 0, 0, 1)', // Red color
|
101 |
+
borderWidth: 1
|
102 |
+
|
103 |
+
}]
|
104 |
+
},
|
105 |
+
options: {
|
106 |
+
scales: {
|
107 |
+
y: {
|
108 |
+
beginAtZero: true,
|
109 |
+
max: 100
|
110 |
+
}
|
111 |
+
}
|
112 |
+
}
|
113 |
+
});
|
114 |
+
} else {
|
115 |
+
resultDiv.textContent = "Unable to determine sentiment.";
|
116 |
+
}
|
117 |
+
});
|
118 |
+
}
|
119 |
+
</script>
|
120 |
+
</body>
|
121 |
+
</html>
|
style.css
CHANGED
@@ -1,26 +1,56 @@
|
|
1 |
body {
|
2 |
-
font-family:
|
3 |
-
background
|
|
|
4 |
display: flex;
|
|
|
5 |
align-items: center;
|
6 |
justify-content: center;
|
7 |
-
height: 100vh;
|
8 |
-
margin: 0;
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
.container {
|
12 |
text-align: center;
|
13 |
max-width: 400px;
|
|
|
14 |
padding: 20px;
|
15 |
-
background-color:
|
16 |
border-radius: 8px;
|
17 |
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
|
20 |
textarea {
|
21 |
-
width:
|
22 |
margin-bottom: 10px;
|
23 |
padding: 8px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
button {
|
@@ -30,6 +60,7 @@ button {
|
|
30 |
border: none;
|
31 |
border-radius: 4px;
|
32 |
cursor: pointer;
|
|
|
33 |
}
|
34 |
|
35 |
button:hover {
|
@@ -41,8 +72,15 @@ button:hover {
|
|
41 |
display: flex;
|
42 |
flex-direction: column;
|
43 |
align-items: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
-
|
46 |
.result-item {
|
47 |
background-color: #e0e0e0;
|
48 |
border-radius: 4px;
|
@@ -50,4 +88,43 @@ button:hover {
|
|
50 |
padding: 10px;
|
51 |
width: 100%;
|
52 |
box-sizing: border-box;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
|
|
1 |
body {
|
2 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
3 |
+
background: linear-gradient(to right bottom, #f8f3eb, #e4d4ae);
|
4 |
+
margin: 0;
|
5 |
display: flex;
|
6 |
+
flex-direction: column;
|
7 |
align-items: center;
|
8 |
justify-content: center;
|
9 |
+
min-height: 100vh;
|
|
|
10 |
}
|
11 |
|
12 |
+
.header {
|
13 |
+
background: linear-gradient(to right, #ffdb58, #ffaf00);
|
14 |
+
color: #fff;
|
15 |
+
padding: 5px;
|
16 |
+
text-align: center;
|
17 |
+
width: 100%;
|
18 |
+
position: fixed;
|
19 |
+
top: 0;
|
20 |
+
height:60px;
|
21 |
+
z-index: 1000;
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
.container {
|
26 |
text-align: center;
|
27 |
max-width: 400px;
|
28 |
+
width:600px;
|
29 |
padding: 20px;
|
30 |
+
background-color: #dec3ba;;
|
31 |
border-radius: 8px;
|
32 |
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
33 |
+
margin-top: 80px; /* Adjusted to accommodate the fixed header */
|
34 |
+
margin-bottom: 50px; /* Adjusted to add space between content and footer */
|
35 |
+
animation: fadeIn 1s ease-in-out;
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
h1 {
|
40 |
+
color: #333;
|
41 |
}
|
42 |
|
43 |
textarea {
|
44 |
+
width: 75%;
|
45 |
margin-bottom: 10px;
|
46 |
padding: 8px;
|
47 |
+
border: 1px solid #ddd;
|
48 |
+
border-radius: 4px;
|
49 |
+
transition: border-color 0.3s;
|
50 |
+
}
|
51 |
+
|
52 |
+
textarea:focus {
|
53 |
+
border-color: #4caf50;
|
54 |
}
|
55 |
|
56 |
button {
|
|
|
60 |
border: none;
|
61 |
border-radius: 4px;
|
62 |
cursor: pointer;
|
63 |
+
transition: background-color 0.3s;
|
64 |
}
|
65 |
|
66 |
button:hover {
|
|
|
72 |
display: flex;
|
73 |
flex-direction: column;
|
74 |
align-items: center;
|
75 |
+
|
76 |
+
}
|
77 |
+
#result.result-container {
|
78 |
+
margin-top: 10px; /* Adjusted margin-top to add space between the result items and the textarea */
|
79 |
+
padding: 3px; /* Adjusted padding to decrease the height */
|
80 |
+
display: flex;
|
81 |
+
flex-direction: column;
|
82 |
+
align-items: center;
|
83 |
}
|
|
|
84 |
.result-item {
|
85 |
background-color: #e0e0e0;
|
86 |
border-radius: 4px;
|
|
|
88 |
padding: 10px;
|
89 |
width: 100%;
|
90 |
box-sizing: border-box;
|
91 |
+
animation: fadeIn 0.5s ease-in-out;
|
92 |
+
}
|
93 |
+
|
94 |
+
.chart {
|
95 |
+
margin-top: 20px;
|
96 |
+
border-radius: 8px;
|
97 |
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
98 |
+
}
|
99 |
+
|
100 |
+
.footer {
|
101 |
+
background: linear-gradient(to right, #ffdb58, #ffaf00);
|
102 |
+
color: #fff;
|
103 |
+
padding: 7px;
|
104 |
+
text-align: center;
|
105 |
+
position: fixed;
|
106 |
+
bottom: 0;
|
107 |
+
width: 100%;
|
108 |
+
animation: slideUp 0.8s ease-in-out;
|
109 |
+
z-index: 1000;
|
110 |
+
}
|
111 |
+
|
112 |
+
@keyframes fadeIn {
|
113 |
+
from {
|
114 |
+
opacity: 0;
|
115 |
+
}
|
116 |
+
to {
|
117 |
+
opacity: 1;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
@keyframes slideUp {
|
122 |
+
from {
|
123 |
+
transform: translateY(50px);
|
124 |
+
opacity: 0;
|
125 |
+
}
|
126 |
+
to {
|
127 |
+
transform: translateY(0);
|
128 |
+
opacity: 1;
|
129 |
+
}
|
130 |
}
|