ilahaG commited on
Commit
d97a7c5
·
verified ·
1 Parent(s): b76ce7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,20 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the model locally (assuming model files are in this folder)
5
- classifier = pipeline("text-classification", model="./models/bert-base-goemotions-ekman", return_all_scores=True)
 
 
 
6
 
7
  def detect_emotions(text):
8
  results = classifier(text)[0]
9
- sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
10
- return {r['label']: round(r['score'], 3) for r in sorted_results}
11
 
12
  demo = gr.Interface(
13
  fn=detect_emotions,
14
  inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."),
15
  outputs="label",
16
  title="Emotion Detection with BERT (GoEmotions)",
17
- description="Detect joy, sadness, anger, and other emotions from text using a BERT-based model fine-tuned on the GoEmotions dataset."
18
  )
19
 
20
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ classifier = pipeline(
5
+ "text-classification",
6
+ model="bhadresh-savani/bert-base-goemotions-ekman",
7
+ return_all_scores=True
8
+ )
9
 
10
  def detect_emotions(text):
11
  results = classifier(text)[0]
12
+ return {r['label']: round(r['score'], 3) for r in sorted(results, key=lambda x: x["score"], reverse=True)}
 
13
 
14
  demo = gr.Interface(
15
  fn=detect_emotions,
16
  inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."),
17
  outputs="label",
18
  title="Emotion Detection with BERT (GoEmotions)",
19
+ description="Detect joy, sadness, anger, and more using BERT trained on GoEmotions."
20
  )
21
 
22
  demo.launch()