Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
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,
|
17 |
-
plt.pie(
|
18 |
-
plt.title("Emotion
|
|
|
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()
|