Spaces:
Sleeping
Sleeping
File size: 714 Bytes
cc9c39b de622d7 cc9c39b de622d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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()
|