File size: 931 Bytes
feabdbe
 
2477995
4d6aed4
feabdbe
 
4d6aed4
feabdbe
 
4d6aed4
feabdbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97151c0
feabdbe
 
 
97151c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from flask import Flask, request, jsonify
from transformers import pipeline

# Inicializamos Flask y el pipeline de Hugging Face
app = Flask(__name__)

# Cargar el modelo de Hugging Face para clasificaci贸n de emociones
emotion_classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")

@app.route("/predict", methods=["POST"])
def predict_emotion():
    try:
        # Obtener el texto del cuerpo de la solicitud
        data = request.get_json()
        text = data["text"]
        
        # Hacer la predicci贸n
        result = emotion_classifier(text)
        
        # Retornar la emoci贸n predicha
        return jsonify({"emotion": result[0]['label'], "confidence": result[0]['score']})
    
    except Exception as e:
        return jsonify({"error": str(e)}), 400

if __name__ == "__main__":
    # Iniciar la aplicaci贸n Flask
    app.run(host="0.0.0.0", port=5000)