diff --git a/application/functions/sentiment.py b/application/functions/sentiment.py index 5b1a088..5166186 100644 --- a/application/functions/sentiment.py +++ b/application/functions/sentiment.py @@ -8,4 +8,25 @@ tokenizer = AutoTokenizer.from_pretrained('application/tokenizers/sentiment_toke def sentiment_prediction(data): pipe = pipeline('text-classification', model=model, tokenizer = tokenizer) result = pipe(data) - return result \ No newline at end of file + + return result + +def count_predictions(predictions): + l0 = 0 + l1 = 0 + l2 = 0 + all = {} + + for i in predictions: + if i['label'] == 'LABEL_0': + l0 += 1 + if i['label'] == 'LABEL_1': + l1 += 1 + if i['label'] == 'LABEL_2': + l2 += 1 + + all['positive'] = l1 + all['negative'] = l0 + all['neutral'] = l2 + + return all \ No newline at end of file diff --git a/application/services/sentiment_service.py b/application/services/sentiment_service.py index d85f1d5..26b82c0 100644 --- a/application/services/sentiment_service.py +++ b/application/services/sentiment_service.py @@ -3,12 +3,14 @@ from flask import( jsonify, Blueprint, ) -from application.functions.sentiment import sentiment_prediction +from application.functions.sentiment import sentiment_prediction, count_predictions sentiment_service = Blueprint("sentiment_service", __name__) @sentiment_service.route("/get_sentiment_data", methods=['GET']) def get_data(): data = request.get_json() - result = sentiment_prediction(data['sentences']) - return result \ No newline at end of file + predicitons = sentiment_prediction(data['sentences']) #predykcje + count_labels = count_predictions(predicitons) #dane do wykresu + + return jsonify({"predictions": predicitons, "count_labels": count_labels}) \ No newline at end of file