Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -12,11 +12,11 @@ import tqdm
|
|
12 |
nltk.download('punkt')
|
13 |
|
14 |
# Define the device (GPU or CPU)
|
15 |
-
device = torch.device("cuda
|
16 |
|
17 |
# Define the model and tokenizer
|
18 |
checkpoint = "ieq/IEQ-BERT"
|
19 |
-
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
20 |
model = AutoModelForSequenceClassification.from_pretrained(checkpoint).to(device)
|
21 |
|
22 |
|
@@ -212,6 +212,18 @@ def predict_from_csv(file, column_name, progress=gr.Progress()):
|
|
212 |
labels_predicted = []
|
213 |
prediction_scores = []
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
# Preprocess text and make predictions
|
216 |
for text_input in progress.tqdm(text_list, desc="Analysing data"):
|
217 |
# Sleep to avoid rate limiting
|
@@ -248,9 +260,69 @@ def predict_from_csv(file, column_name, progress=gr.Progress()):
|
|
248 |
labels_predicted.append(predicted_labels)
|
249 |
prediction_scores.append(prediction_score)
|
250 |
|
251 |
-
# Append
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
df_docs['IEQ_predicted'] = labels_predicted
|
253 |
df_docs['prediction_scores'] = prediction_scores
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
# Save the predictions to a CSV file
|
256 |
df_docs.to_csv('IEQ_predictions.csv')
|
|
|
12 |
nltk.download('punkt')
|
13 |
|
14 |
# Define the device (GPU or CPU)
|
15 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
16 |
|
17 |
# Define the model and tokenizer
|
18 |
checkpoint = "ieq/IEQ-BERT"
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
20 |
model = AutoModelForSequenceClassification.from_pretrained(checkpoint).to(device)
|
21 |
|
22 |
|
|
|
212 |
labels_predicted = []
|
213 |
prediction_scores = []
|
214 |
|
215 |
+
# Initialize empty lists for IEQ labels and scores
|
216 |
+
ieq1 = []
|
217 |
+
ieq2 = []
|
218 |
+
ieq3 = []
|
219 |
+
ieq4 = []
|
220 |
+
ieq5 = []
|
221 |
+
score1 = []
|
222 |
+
score2 = []
|
223 |
+
score3 = []
|
224 |
+
score4 = []
|
225 |
+
score5 = []
|
226 |
+
|
227 |
# Preprocess text and make predictions
|
228 |
for text_input in progress.tqdm(text_list, desc="Analysing data"):
|
229 |
# Sleep to avoid rate limiting
|
|
|
260 |
labels_predicted.append(predicted_labels)
|
261 |
prediction_scores.append(prediction_score)
|
262 |
|
263 |
+
# Append to ieq1 to ieq5
|
264 |
+
for i in range(5):
|
265 |
+
if i < len(predicted_labels):
|
266 |
+
if i == 0:
|
267 |
+
ieq1.append(predicted_labels[i])
|
268 |
+
elif i == 1:
|
269 |
+
ieq2.append(predicted_labels[i])
|
270 |
+
elif i == 2:
|
271 |
+
ieq3.append(predicted_labels[i])
|
272 |
+
elif i == 3:
|
273 |
+
ieq4.append(predicted_labels[i])
|
274 |
+
elif i == 4:
|
275 |
+
ieq5.append(predicted_labels[i])
|
276 |
+
else:
|
277 |
+
if i == 0:
|
278 |
+
ieq1.append("-")
|
279 |
+
elif i == 1:
|
280 |
+
ieq2.append("-")
|
281 |
+
elif i == 2:
|
282 |
+
ieq3.append("-")
|
283 |
+
elif i == 3:
|
284 |
+
ieq4.append("-")
|
285 |
+
elif i == 4:
|
286 |
+
ieq5.append("-")
|
287 |
+
|
288 |
+
# Append to score1 to score5
|
289 |
+
for i in range(5):
|
290 |
+
if i < len(prediction_score):
|
291 |
+
if i == 0:
|
292 |
+
score1.append(prediction_score[i])
|
293 |
+
elif i == 1:
|
294 |
+
score2.append(prediction_score[i])
|
295 |
+
elif i == 2:
|
296 |
+
score3.append(prediction_score[i])
|
297 |
+
elif i == 3:
|
298 |
+
score4.append(prediction_score[i])
|
299 |
+
elif i == 4:
|
300 |
+
score5.append(prediction_score[i])
|
301 |
+
else:
|
302 |
+
if i == 0:
|
303 |
+
score1.append("-")
|
304 |
+
elif i == 1:
|
305 |
+
score2.append("-")
|
306 |
+
elif i == 2:
|
307 |
+
score3.append("-")
|
308 |
+
elif i == 3:
|
309 |
+
score4.append("-")
|
310 |
+
elif i == 4:
|
311 |
+
score5.append("-")
|
312 |
+
|
313 |
+
# Append the predictions to the DataFrame
|
314 |
df_docs['IEQ_predicted'] = labels_predicted
|
315 |
df_docs['prediction_scores'] = prediction_scores
|
316 |
+
df_docs['IEQ1'] = ieq1
|
317 |
+
df_docs['IEQ2'] = ieq2
|
318 |
+
df_docs['IEQ3'] = ieq3
|
319 |
+
df_docs['IEQ4'] = ieq4
|
320 |
+
df_docs['IEQ5'] = ieq5
|
321 |
+
df_docs['Score1'] = score1
|
322 |
+
df_docs['Score2'] = score2
|
323 |
+
df_docs['Score3'] = score3
|
324 |
+
df_docs['Score4'] = score4
|
325 |
+
df_docs['Score5'] = score5
|
326 |
|
327 |
# Save the predictions to a CSV file
|
328 |
df_docs.to_csv('IEQ_predictions.csv')
|