Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -66,7 +66,11 @@ def predict_single_review(text_rating: TextRatingRequest):
|
|
| 66 |
# spans = [{'label': text, 'color': '', 'value': '', 'sentiment': '', 'score': ''}]
|
| 67 |
# has_sentiments = False
|
| 68 |
# processed_data['spans'] = spans
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
end_time = time.time()
|
| 71 |
print(f"Time taken to process the data : {end_time - start_time} seconds")
|
| 72 |
return {"processed_data": processed_data, "has_sentiments":has_sentiments}
|
|
@@ -79,7 +83,11 @@ def predict_all_reviews(reviews: AllTextRatingRequest):
|
|
| 79 |
start_time = time.time()
|
| 80 |
for review in reviews:
|
| 81 |
raw_data = {"text":review.get('text', str()), "star_rating":review.get('rating', 5), "skip":skip}
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
processed_data_list.append({"processed_data":processed_data, "has_sentiments":has_sentiments})
|
| 84 |
end_time = time.time()
|
| 85 |
print(f"Time taken to process the data : {end_time - start_time} seconds")
|
|
@@ -102,7 +110,11 @@ def predict_file_responses(file: UploadFile = File(...)):
|
|
| 102 |
star_rating = row['STAR RATING']
|
| 103 |
review_id = row['REVIEWID']
|
| 104 |
raw_data = {"text":text, "star_rating":star_rating, "skip":False}
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
now = datetime.now()
|
| 107 |
print(f"Processed review with index {index} at time {now.time()}")
|
| 108 |
processed_data_list.append({"processed_data":processed_data, "has_sentiments":has_sentiments, "review_id":review_id})
|
|
|
|
| 66 |
# spans = [{'label': text, 'color': '', 'value': '', 'sentiment': '', 'score': ''}]
|
| 67 |
# has_sentiments = False
|
| 68 |
# processed_data['spans'] = spans
|
| 69 |
+
try:
|
| 70 |
+
processed_data, has_sentiments = process_single_comment(raw_data, LANGUAGE_MODEL, SENTIMENT_MODEL, LABELS )
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print("error during prediction: ", e)
|
| 73 |
+
return {"error":e}
|
| 74 |
end_time = time.time()
|
| 75 |
print(f"Time taken to process the data : {end_time - start_time} seconds")
|
| 76 |
return {"processed_data": processed_data, "has_sentiments":has_sentiments}
|
|
|
|
| 83 |
start_time = time.time()
|
| 84 |
for review in reviews:
|
| 85 |
raw_data = {"text":review.get('text', str()), "star_rating":review.get('rating', 5), "skip":skip}
|
| 86 |
+
try:
|
| 87 |
+
processed_data, has_sentiments = process_single_comment(raw_data, LANGUAGE_MODEL, SENTIMENT_MODEL, LABELS )
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print("error during prediction: ", e)
|
| 90 |
+
return {"error":e}
|
| 91 |
processed_data_list.append({"processed_data":processed_data, "has_sentiments":has_sentiments})
|
| 92 |
end_time = time.time()
|
| 93 |
print(f"Time taken to process the data : {end_time - start_time} seconds")
|
|
|
|
| 110 |
star_rating = row['STAR RATING']
|
| 111 |
review_id = row['REVIEWID']
|
| 112 |
raw_data = {"text":text, "star_rating":star_rating, "skip":False}
|
| 113 |
+
try:
|
| 114 |
+
processed_data, has_sentiments = process_single_comment(raw_data,LANGUAGE_MODEL, SENTIMENT_MODEL, LABELS )
|
| 115 |
+
except Exception as e:
|
| 116 |
+
print("error during prediction: ", e)
|
| 117 |
+
return {"error":e}
|
| 118 |
now = datetime.now()
|
| 119 |
print(f"Processed review with index {index} at time {now.time()}")
|
| 120 |
processed_data_list.append({"processed_data":processed_data, "has_sentiments":has_sentiments, "review_id":review_id})
|