Spaces:
No application file
No application file
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") | |
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) | |