Suzana commited on
Commit
5e0dcc9
·
verified ·
1 Parent(s): 847acaa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 1) Load the HF pipeline with all scores so we can show probabilities
5
+ classifier = pipeline(
6
+ "text-classification",
7
+ model="j-hartmann/emotion-english-roberta-large",
8
+ return_all_scores=True
9
+ )
10
+
11
+ # 2) Wrap it in a function that returns a label→score dict
12
+ def classify_emotion(text: str):
13
+ scores = classifier(text)[0] # returns list of {label, score}
14
+ return {item["label"]: float(item["score"]) for item in scores}
15
+
16
+ # 3) Build the Gradio interface
17
+ iface = gr.Interface(
18
+ fn=classify_emotion,
19
+ inputs=gr.Textbox(
20
+ lines=2,
21
+ placeholder="Type any English sentence here…",
22
+ label="Input Text"
23
+ ),
24
+ outputs=gr.Label(
25
+ num_top_classes=6,
26
+ label="Emotion Probabilities"
27
+ ),
28
+ examples=[
29
+ ["I love you!"],
30
+ ["The movie was heart breaking!"]
31
+ ],
32
+ title="English Emotion Classifier",
33
+ description=(
34
+ "Predicts one of Ekman's 6 basic emotions plus neutral "
35
+ "(anger 🤬, disgust 🤢, fear 😨, joy 😀, neutral 😐, "
36
+ "sadness 😭, surprise 😲)."
37
+ )
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ iface.launch()