Aryanshanu commited on
Commit
e8d79db
·
verified ·
1 Parent(s): a25d341

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from transformers import pipeline
2
  import gradio as gr
3
  import matplotlib.pyplot as plt
4
  import io
@@ -12,10 +12,15 @@ def analyze_emotions(text):
12
  results = emotion_pipeline(text, top_k=None) # Get probabilities for all emotions
13
  emotions = {res['label']: res['score'] for res in results}
14
 
 
 
 
 
15
  # Generate a pie chart for the emotions
16
- plt.figure(figsize=(8, 4))
17
- plt.pie(emotions.values(), labels=emotions.keys(), autopct='%1.1f%%')
18
- plt.title("Emotion Analysis")
 
19
 
20
  # Save the plot to a bytes buffer
21
  buf = io.BytesIO()
 
1
+ import transformers
2
  import gradio as gr
3
  import matplotlib.pyplot as plt
4
  import io
 
12
  results = emotion_pipeline(text, top_k=None) # Get probabilities for all emotions
13
  emotions = {res['label']: res['score'] for res in results}
14
 
15
+ # Extract emotion labels and probabilities
16
+ emotion_labels = list(emotions.keys())
17
+ emotion_probabilities = list(emotions.values())
18
+
19
  # Generate a pie chart for the emotions
20
+ plt.figure(figsize=(8, 6))
21
+ plt.pie(emotion_probabilities, labels=emotion_labels, autopct='%1.1f%%', startangle=140)
22
+ plt.title("Emotion Distribution")
23
+ plt.axis('equal')
24
 
25
  # Save the plot to a bytes buffer
26
  buf = io.BytesIO()