Alexa17's picture
Update app.py
4d6aed4 verified
raw
history blame
749 Bytes
# Importar la librer铆a necesaria de Hugging Face
from transformers import pipeline
# Cargar el modelo preentrenado de Hugging Face para detecci贸n de emociones
emotion_detector = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
# Funci贸n que toma el texto y devuelve la emoci贸n detectada
def detect_emotion(text):
return emotion_detector(text)
# Si el script se ejecuta directamente, pedimos al usuario un texto y mostramos el resultado
if __name__ == "__main__":
text = input("Introduce el texto para detectar la emoci贸n: ")
result = detect_emotion(text)
# Mostrar el resultado
print(f"Emoci贸n detectada: {result[0]['label']} con una probabilidad de {result[0]['score']:.2f}")