empath-ai / app.py
Navsatitagain's picture
Update app.py
de622d7 verified
raw
history blame
714 Bytes
import gradio as gr
from transformers import pipeline
text_emotion = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
def analyze_emotion(text):
results = text_emotion(text)[0]
results = sorted(results, key=lambda x: x['score'], reverse=True)
output = {r['label']: round(r['score'], 3) for r in results}
return output
demo = gr.Interface(
fn=analyze_emotion,
inputs=gr.Textbox(lines=3, placeholder="Type something here..."),
outputs=gr.Label(num_top_classes=3),
title="Empath AI - Emotion Detection",
description="Type a sentence to see what emotions it contains!"
)
if __name__ == "__main__":
demo.launch()