Navsatitagain commited on
Commit
ccffc2e
·
verified ·
1 Parent(s): 096ce4b

Update app_text_only_backup.py

Browse files
Files changed (1) hide show
  1. app_text_only_backup.py +21 -0
app_text_only_backup.py CHANGED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ text_emotion = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
5
+
6
+ def analyze_emotion(text):
7
+ results = text_emotion(text)[0]
8
+ results = sorted(results, key=lambda x: x['score'], reverse=True)
9
+ output = {r['label']: round(r['score'], 3) for r in results}
10
+ return output
11
+
12
+ demo = gr.Interface(
13
+ fn=analyze_emotion,
14
+ inputs=gr.Textbox(lines=3, placeholder="Type something here..."),
15
+ outputs=gr.Label(num_top_classes=3),
16
+ title="Empath AI - Emotion Detection",
17
+ description="Type a sentence to see what emotions it contains!"
18
+ )
19
+
20
+ if __name__ == "__main__":
21
+ demo.launch()