data for bar plot

This commit is contained in:
Maciej Ścigacz 2023-05-27 16:44:44 +02:00
parent 250b4b67f1
commit cfc9b1c0d8
2 changed files with 27 additions and 4 deletions

View File

@ -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
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

View File

@ -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
predicitons = sentiment_prediction(data['sentences']) #predykcje
count_labels = count_predictions(predicitons) #dane do wykresu
return jsonify({"predictions": predicitons, "count_labels": count_labels})