philipobiorah commited on
Commit
93308cb
·
verified ·
1 Parent(s): 0e74490

update upload.html to display confidence level of prediction

Browse files
Files changed (1) hide show
  1. templates/upload.html +72 -2
templates/upload.html CHANGED
@@ -113,7 +113,7 @@
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">
@@ -142,10 +142,80 @@
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>
 
113
  </style>
114
  </head>
115
  <body>
116
+ <h1>BERT-Based Sentiment Analyzer 1.0</h1>
117
 
118
  <h2>-Upload File-</h2>
119
  <form id="upload-form" enctype="multipart/form-data">
 
142
  </form>
143
 
144
  <h2>Sentiment:</h2>
145
+ <p id="sentiment" class="hidden"></p>
146
+ <p id="confidence" class="hidden"></p>
147
+
148
+ <script>
149
+ $(document).ready(function() {
150
+ // Handle Text Analysis
151
+ $("#text-form").submit(function(event) {
152
+ event.preventDefault();
153
+ $("#text-progress-bar").parent().show();
154
+ $("#text-progress-bar").css("width", "50%").text("Processing...");
155
+ $(".loading").show();
156
+
157
+ $.ajax({
158
+ url: "/analyze_text",
159
+ type: "POST",
160
+ data: { text: $("#text").val() },
161
+ success: function(response) {
162
+ $("#text-progress-bar").css("width", "100%").text("Done!");
163
+ $(".loading").hide();
164
+ $("#sentiment").text("Sentiment: " + response.sentiment).attr("class", response.sentiment.toLowerCase()).show();
165
+ $("#confidence").text("Confidence: " + response.confidence + "%").show();
166
+ },
167
+ error: function(xhr) {
168
+ $("#textError").text("Error: " + xhr.responseJSON.error);
169
+ }
170
+ });
171
+ });
172
+
173
+ // Handle File Upload
174
+ $("#upload-form").submit(function(event) {
175
+ event.preventDefault();
176
+ let formData = new FormData(this);
177
+
178
+ $("#upload-progress-bar").parent().show();
179
+ $("#upload-progress-bar").css("width", "50%").text("Uploading...");
180
+ $(".loading").show();
181
+
182
+ $.ajax({
183
+ url: "/uploader",
184
+ type: "POST",
185
+ data: formData,
186
+ processData: false,
187
+ contentType: false,
188
+ success: function(response) {
189
+ $("#upload-progress-bar").css("width", "100%").text("Done!");
190
+ $(".loading").hide();
191
+ document.open();
192
+ document.write(response);
193
+ document.close();
194
+ },
195
+ error: function() {
196
+ $("#fileError").text("Error: Could not upload file.");
197
+ }
198
+ });
199
+ });
200
+ });
201
+
202
+ window.onload = function() {
203
+ var sentimentElement = document.getElementById('sentiment');
204
+ var confidenceElement = document.getElementById('confidence');
205
+ if (sentimentElement && sentimentElement.textContent.trim() !== "") {
206
+ sentimentElement.classList.remove("hidden");
207
+ confidenceElement.classList.remove("hidden");
208
+ }
209
+ };
210
+ </script>
211
+
212
 
213
  <!-- File Upload Specifications -->
214
  <div class="file-upload-specifications">
215
+ <a href="/download-sample">
216
+ <h3>📥 Download and use sample data </h3>
217
+ </a>
218
+
219
  <h3>📄 File Upload Specifications:</h3>
220
  <p>Please ensure your file adheres to the following specifications for successful analysis:</p>
221
  <ul>