fix direct download link for sample data
Browse files- templates/upload.html +157 -99
templates/upload.html
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<title>Upload Reviews or Enter Text</title>
|
|
|
5 |
<style>
|
6 |
body {
|
7 |
font-family: Arial, sans-serif;
|
@@ -43,17 +44,31 @@
|
|
43 |
}
|
44 |
|
45 |
input[type="submit"]:hover {
|
46 |
-
background: #
|
47 |
}
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
|
53 |
-
.
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
|
59 |
.error-message {
|
@@ -64,115 +79,158 @@
|
|
64 |
.positive {
|
65 |
color: green;
|
66 |
}
|
|
|
67 |
.negative {
|
68 |
color: blue;
|
69 |
}
|
70 |
|
|
|
71 |
.file-upload-specifications {
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
text-align: justify;
|
86 |
-
}
|
87 |
-
.file-upload-specifications ul {
|
88 |
-
text-align: justify;
|
89 |
-
}
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
</style>
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
<div id="fileError" class="error-message"></div>
|
129 |
-
</form>
|
130 |
-
|
131 |
-
<h2>Or Enter Text for Sentiment Analysis</h2>
|
132 |
-
<form name="textInputForm" action="/analyze_text" method="post" onsubmit="return validateTextInput()">
|
133 |
-
<textarea name="text" rows="4" cols="50"></textarea><br>
|
134 |
-
<input type="submit" value="Predict Sentiment">
|
135 |
-
<div id="textError" class="error-message"></div>
|
136 |
-
</form>
|
137 |
-
|
138 |
-
<h2>Sentiment:</h2>
|
139 |
-
<p id="sentiment" class="{{ sentiment|lower }}">{{ sentiment }}</p>
|
140 |
-
|
141 |
-
<script>
|
142 |
-
window.onload = function() {
|
143 |
-
var sentimentElement = document.getElementById('sentiment');
|
144 |
-
if (sentimentElement) {
|
145 |
-
var sentiment = sentimentElement.textContent.trim().toLowerCase();
|
146 |
-
if (sentiment === 'positive') {
|
147 |
-
sentimentElement.className = 'positive';
|
148 |
-
} else if (sentiment === 'negative') {
|
149 |
-
sentimentElement.className = 'negative';
|
150 |
-
}
|
151 |
-
}
|
152 |
-
};
|
153 |
-
</script>
|
154 |
-
<div class="file-upload-specifications">
|
155 |
-
<a href="https://huggingface.co/spaces/philipobiorah/bert-sentiment-analysis/resolve/main/Student_Feedback_Dataset__20_Rows_.csv"><h3>Download Sample Dataset:</h3></a>
|
156 |
-
<h3>File Upload Specifications:</h3>
|
157 |
<p>Please ensure your file adheres to the following specifications for successful analysis:</p>
|
158 |
<ul>
|
159 |
<li><strong>File Format:</strong> CSV (Comma-Separated Values)</li>
|
160 |
-
<li><strong>Required
|
161 |
<li><strong>'review' Column:</strong> This column should contain the text of the reviews or sentiments to be analyzed.</li>
|
162 |
-
<li><strong>Maximum File Size:</strong>
|
163 |
<li><strong>Encoding:</strong> UTF-8 encoding is recommended for compatibility.</li>
|
164 |
-
<li><strong>Example:</strong> The first column should be named 'review' and contain the review text. Additional columns are optional and will be ignored.</li>
|
165 |
</ul>
|
166 |
-
<p>If your file does not meet these specifications, the analysis may not be performed correctly.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
</div>
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
Project by Philip Obiorah & Supervised by: Prof. Hongbo Du<br>
|
172 |
Submitted to the University of Buckingham, in partial fulfilment of the requirements for the degree of Master of Science in Applied Data Science.<br>
|
173 |
© 2023 University of Buckingham. All rights reserved.<br>
|
174 |
<small>Last updated: <time datetime="2023-12-15">February 10, 2025</time>.</small>
|
175 |
</div>
|
176 |
-
|
177 |
-
</html>
|
178 |
</html>
|
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<title>Upload Reviews or Enter Text</title>
|
5 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
6 |
<style>
|
7 |
body {
|
8 |
font-family: Arial, sans-serif;
|
|
|
44 |
}
|
45 |
|
46 |
input[type="submit"]:hover {
|
47 |
+
background: #333;
|
48 |
}
|
49 |
|
50 |
+
.progress-container {
|
51 |
+
width: 100%;
|
52 |
+
background-color: #f3f3f3;
|
53 |
+
border-radius: 5px;
|
54 |
+
margin-top: 10px;
|
55 |
+
display: none;
|
56 |
}
|
57 |
|
58 |
+
.progress-bar {
|
59 |
+
width: 0%;
|
60 |
+
height: 20px;
|
61 |
+
background-color: #4caf50;
|
62 |
+
text-align: center;
|
63 |
+
line-height: 20px;
|
64 |
+
color: white;
|
65 |
+
border-radius: 5px;
|
66 |
+
}
|
67 |
+
|
68 |
+
.loading {
|
69 |
+
display: none;
|
70 |
+
font-weight: bold;
|
71 |
+
color: #007BFF;
|
72 |
}
|
73 |
|
74 |
.error-message {
|
|
|
79 |
.positive {
|
80 |
color: green;
|
81 |
}
|
82 |
+
|
83 |
.negative {
|
84 |
color: blue;
|
85 |
}
|
86 |
|
87 |
+
/* File Upload Specification Styles */
|
88 |
.file-upload-specifications {
|
89 |
+
background-color: #f8f8f8;
|
90 |
+
border: 1px solid #ddd;
|
91 |
+
border-radius: 8px;
|
92 |
+
padding: 15px;
|
93 |
+
margin-top: 20px;
|
94 |
+
margin-bottom: 20px;
|
95 |
+
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1);
|
96 |
+
text-align: left;
|
97 |
+
width: 80%;
|
98 |
+
max-width: 600px;
|
99 |
+
margin-left: auto;
|
100 |
+
margin-right: auto;
|
101 |
+
}
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
+
.file-upload-specifications h3 {
|
104 |
+
color: #000000;
|
105 |
+
text-align: center;
|
106 |
+
}
|
107 |
+
|
108 |
+
.file-upload-specifications ul {
|
109 |
+
text-align: left;
|
110 |
+
list-style: disc;
|
111 |
+
margin-left: 20px;
|
112 |
+
}
|
113 |
</style>
|
114 |
+
</head>
|
115 |
+
<body>
|
116 |
+
<h1>UoB BERT-Based Sentiment Analyzer 1.0</h1>
|
117 |
+
|
118 |
+
<h2>-Upload File-</h2>
|
119 |
+
<form id="upload-form" enctype="multipart/form-data">
|
120 |
+
<input type="file" id="file" name="file" accept=".csv" required>
|
121 |
+
<input type="submit" value="Upload and Analyze">
|
122 |
+
|
123 |
+
<div class="progress-container">
|
124 |
+
<div class="progress-bar" id="upload-progress-bar">0%</div>
|
125 |
+
</div>
|
126 |
+
|
127 |
+
<p class="loading">Processing... Please wait.</p>
|
128 |
+
<div id="fileError" class="error-message"></div>
|
129 |
+
</form>
|
130 |
+
|
131 |
+
<h2>Or Enter Text for Sentiment Analysis</h2>
|
132 |
+
<form id="text-form">
|
133 |
+
<textarea id="text" name="text" rows="4" cols="50"></textarea><br>
|
134 |
+
<input type="submit" value="Predict Sentiment">
|
135 |
+
|
136 |
+
<div class="progress-container">
|
137 |
+
<div class="progress-bar" id="text-progress-bar">0%</div>
|
138 |
+
</div>
|
139 |
+
|
140 |
+
<p class="loading">Processing... Please wait.</p>
|
141 |
+
<div id="textError" class="error-message"></div>
|
142 |
+
</form>
|
143 |
+
|
144 |
+
<h2>Sentiment:</h2>
|
145 |
+
<p id="sentiment" class="{{ sentiment|lower }}">{{ sentiment }}</p>
|
146 |
+
|
147 |
+
<!-- File Upload Specifications -->
|
148 |
+
<div class="file-upload-specifications">
|
149 |
+
<h3>📄 File Upload Specifications:</h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
<p>Please ensure your file adheres to the following specifications for successful analysis:</p>
|
151 |
<ul>
|
152 |
<li><strong>File Format:</strong> CSV (Comma-Separated Values)</li>
|
153 |
+
<li><strong>Required Column:</strong> The file must contain a column named <code>'review'</code>.</li>
|
154 |
<li><strong>'review' Column:</strong> This column should contain the text of the reviews or sentiments to be analyzed.</li>
|
155 |
+
<li><strong>Maximum File Size:</strong> 5MB</li>
|
156 |
<li><strong>Encoding:</strong> UTF-8 encoding is recommended for compatibility.</li>
|
157 |
+
<li><strong>Example:</strong> The first column should be named <code>'review'</code> and contain the review text. Additional columns are optional and will be ignored.</li>
|
158 |
</ul>
|
159 |
+
<p>If your file does not meet these specifications, - the analysis may not be performed correctly.</p>
|
160 |
+
|
161 |
+
<a href="/download-sample">
|
162 |
+
<h3>📥 Download Sample Dataset</h3>
|
163 |
+
</a>
|
164 |
+
|
165 |
+
|
166 |
+
|
167 |
</div>
|
168 |
+
|
169 |
+
<script>
|
170 |
+
$(document).ready(function() {
|
171 |
+
// Handle Text Analysis
|
172 |
+
$("#text-form").submit(function(event) {
|
173 |
+
event.preventDefault();
|
174 |
+
$("#text-progress-bar").parent().show();
|
175 |
+
$("#text-progress-bar").css("width", "50%").text("Processing...");
|
176 |
+
$(".loading").show();
|
177 |
+
|
178 |
+
$.post("/analyze_text", { text: $("#text").val() }, function(response) {
|
179 |
+
$("#text-progress-bar").css("width", "100%").text("Done!");
|
180 |
+
$(".loading").hide();
|
181 |
+
$("#sentiment").text(response.sentiment).attr("class", response.sentiment.toLowerCase());
|
182 |
+
}).fail(function() {
|
183 |
+
$("#textError").text("Error: Could not analyze text.");
|
184 |
+
});
|
185 |
+
});
|
186 |
+
|
187 |
+
// Handle File Upload
|
188 |
+
$("#upload-form").submit(function(event) {
|
189 |
+
event.preventDefault();
|
190 |
+
let formData = new FormData(this);
|
191 |
+
|
192 |
+
$("#upload-progress-bar").parent().show();
|
193 |
+
$("#upload-progress-bar").css("width", "50%").text("Uploading...");
|
194 |
+
$(".loading").show();
|
195 |
+
|
196 |
+
$.ajax({
|
197 |
+
url: "/uploader",
|
198 |
+
type: "POST",
|
199 |
+
data: formData,
|
200 |
+
processData: false,
|
201 |
+
contentType: false,
|
202 |
+
success: function(response) {
|
203 |
+
$("#upload-progress-bar").css("width", "100%").text("Done!");
|
204 |
+
$(".loading").hide();
|
205 |
+
document.open();
|
206 |
+
document.write(response);
|
207 |
+
document.close();
|
208 |
+
},
|
209 |
+
error: function() {
|
210 |
+
$("#fileError").text("Error: Could not upload file.");
|
211 |
+
}
|
212 |
+
});
|
213 |
+
});
|
214 |
+
});
|
215 |
+
|
216 |
+
window.onload = function() {
|
217 |
+
var sentimentElement = document.getElementById('sentiment');
|
218 |
+
if (sentimentElement) {
|
219 |
+
var sentiment = sentimentElement.textContent.trim().toLowerCase();
|
220 |
+
if (sentiment === 'positive') {
|
221 |
+
sentimentElement.className = 'positive';
|
222 |
+
} else if (sentiment === 'negative') {
|
223 |
+
sentimentElement.className = 'negative';
|
224 |
+
}
|
225 |
+
}
|
226 |
+
};
|
227 |
+
</script>
|
228 |
+
|
229 |
+
<div class="footer">
|
230 |
Project by Philip Obiorah & Supervised by: Prof. Hongbo Du<br>
|
231 |
Submitted to the University of Buckingham, in partial fulfilment of the requirements for the degree of Master of Science in Applied Data Science.<br>
|
232 |
© 2023 University of Buckingham. All rights reserved.<br>
|
233 |
<small>Last updated: <time datetime="2023-12-15">February 10, 2025</time>.</small>
|
234 |
</div>
|
235 |
+
</body>
|
|
|
236 |
</html>
|