add irony service

This commit is contained in:
Maciej Ścigacz 2023-06-10 01:51:01 +02:00
parent 1be5f4b898
commit 85cac92433
3 changed files with 33 additions and 0 deletions

View File

@ -7,7 +7,10 @@ def create_app():
from application.services.sentiment_service import sentiment_service from application.services.sentiment_service import sentiment_service
from application.services.errors_service import errors_service from application.services.errors_service import errors_service
from application.services.irony_service import irony_service
application.register_blueprint(sentiment_service) application.register_blueprint(sentiment_service)
application.register_blueprint(errors_service) application.register_blueprint(errors_service)
application.register_blueprint(irony_service)
return application return application

View File

@ -0,0 +1,11 @@
from transformers import pipeline
pipe = pipeline('text-classification', model="olczig/irony-polish-detection", tokenizer = "olczig/irony-polish-detection")
def irony_prediction(data):
result = pipe(data)
return result
def clear_data(data):
#czyszczenie danych
return data

View File

@ -0,0 +1,19 @@
from flask import(
request,
jsonify,
Blueprint,
)
from application.functions.irony import irony_prediction
irony_service = Blueprint("irony_service", __name__)
@irony_service.route("/get_irony_data", methods=['POST'])
def get_data():
data = request.get_json()
predicitons = irony_prediction(data['sentences'])
for i in range(0, len(predicitons)):
predicitons[i]['sentence'] = data['sentences'][i]
predicitons[i]['label'] = predicitons[i]['label'][6:]
return jsonify({"predictions": predicitons})