Spaces:
Sleeping
Sleeping
molokhovdmitry
commited on
Commit
·
ecaa557
1
Parent(s):
c988650
Update predict method for readability
Browse files- src/main.py +5 -10
src/main.py
CHANGED
@@ -39,18 +39,13 @@ def predict(video_id):
|
|
39 |
batch_size = settings.PRED_BATCH_SIZE
|
40 |
text_batches = [text_list[i:i + batch_size]
|
41 |
for i in range(0, len(text_list), batch_size)]
|
42 |
-
preds = [
|
43 |
-
|
44 |
-
|
45 |
|
46 |
# Add predictions to DataFrame
|
47 |
-
preds_df = []
|
48 |
-
|
49 |
-
pred_dict = {}
|
50 |
-
for emotion in pred:
|
51 |
-
pred_dict[emotion['label']] = emotion['score']
|
52 |
-
preds_df.append(pred_dict)
|
53 |
-
preds_df = pd.DataFrame(preds_df)
|
54 |
comments_df = pd.concat([comments_df, preds_df], axis=1)
|
55 |
|
56 |
# Return DataFrame as a JSON file
|
|
|
39 |
batch_size = settings.PRED_BATCH_SIZE
|
40 |
text_batches = [text_list[i:i + batch_size]
|
41 |
for i in range(0, len(text_list), batch_size)]
|
42 |
+
preds = [comment_emotions
|
43 |
+
for text_batch in text_batches
|
44 |
+
for comment_emotions in emotions_clf(text_batch)]
|
45 |
|
46 |
# Add predictions to DataFrame
|
47 |
+
preds_df = pd.DataFrame([{emotion['label']: emotion['score']
|
48 |
+
for emotion in pred} for pred in preds])
|
|
|
|
|
|
|
|
|
|
|
49 |
comments_df = pd.concat([comments_df, preds_df], axis=1)
|
50 |
|
51 |
# Return DataFrame as a JSON file
|