File size: 659 Bytes
37f6af0
 
 
d97a7c5
 
2dec3da
d97a7c5
 
37f6af0
 
 
d97a7c5
37f6af0
 
 
 
 
 
d97a7c5
37f6af0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="bhadresh-savani/bert-base-go-emotion",
    return_all_scores=True
)

def detect_emotions(text):
    results = classifier(text)[0]
    return {r['label']: round(r['score'], 3) for r in sorted(results, key=lambda x: x["score"], reverse=True)}

demo = gr.Interface(
    fn=detect_emotions,
    inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."),
    outputs="label",
    title="Emotion Detection with BERT (GoEmotions)",
    description="Detect joy, sadness, anger, and more using BERT trained on GoEmotions."
)

demo.launch()