2023-05-27 15:10:30 +02:00
|
|
|
from flask import(
|
|
|
|
request,
|
|
|
|
jsonify,
|
|
|
|
Blueprint,
|
|
|
|
)
|
2023-05-30 00:00:34 +02:00
|
|
|
from application.functions.sentiment import sentiment_prediction, count_predictions, clear_data, scrapp_comments
|
2023-05-27 15:10:30 +02:00
|
|
|
|
|
|
|
sentiment_service = Blueprint("sentiment_service", __name__)
|
|
|
|
|
2023-05-27 18:39:33 +02:00
|
|
|
@sentiment_service.route("/get_sentiment_data", methods=['POST'])
|
2023-05-27 15:10:30 +02:00
|
|
|
def get_data():
|
|
|
|
data = request.get_json()
|
2023-06-10 13:39:05 +02:00
|
|
|
data_clear = clear_data(data) #czyszczenie danych wejsciowych
|
|
|
|
predicitons = sentiment_prediction(data_clear) #predykcje
|
|
|
|
count_labels = count_predictions(predicitons) #dane do wykresu
|
2023-05-27 16:44:44 +02:00
|
|
|
|
2023-05-27 17:18:28 +02:00
|
|
|
for i in range(0, len(predicitons)):
|
|
|
|
predicitons[i]['sentence'] = data['sentences'][i]
|
|
|
|
predicitons[i]['label'] = predicitons[i]['label'][6:]
|
|
|
|
|
2023-05-30 00:00:34 +02:00
|
|
|
return jsonify({"predictions": predicitons, "count_labels": count_labels})
|
|
|
|
|
|
|
|
|
|
|
|
@sentiment_service.route("/scrapp_comments", methods=['POST'])
|
|
|
|
def scrapp():
|
2023-05-30 13:57:44 +02:00
|
|
|
try:
|
|
|
|
url = request.get_json()
|
|
|
|
result = scrapp_comments(url['link'])
|
|
|
|
result['status'] = True
|
|
|
|
return result
|
2023-05-31 20:20:15 +02:00
|
|
|
except Exception as err:
|
|
|
|
return jsonify({'status':False, 'error':str(err)})
|