Spaces:
No application file
No application file
Download app.py from Alexa17/Detector_Emociones: direct link, hf CLI and curl.
- Browser
- Download file 931 Bytes
-
https://huggingface.co/spaces/Alexa17/Detector_Emociones/resolve/main/app.py
- Command line
-
hf download hf://spaces/Alexa17/Detector_Emociones/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Alexa17/Detector_Emociones/resolve/main/app.py
931 Bytes
| 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) | |