Spaces:
Sleeping
Sleeping
fix the bar chart
Browse files
app.py
CHANGED
@@ -41,11 +41,15 @@ def predict_emotion(text):
|
|
41 |
predictions = classifier(text)[0]
|
42 |
logger.info(f"Raw predictions: {predictions}")
|
43 |
|
44 |
-
# Convert to
|
45 |
-
|
|
|
46 |
logger.info(f"Processed scores: {scores}")
|
47 |
|
48 |
-
return
|
|
|
|
|
|
|
49 |
|
50 |
except Exception as e:
|
51 |
logger.error(f"Error in prediction: {str(e)}")
|
@@ -60,13 +64,15 @@ try:
|
|
60 |
demo = gr.Interface(
|
61 |
fn=predict_emotion,
|
62 |
inputs=gr.Textbox(placeholder="Enter text to analyze...", label="Input Text"),
|
63 |
-
outputs=
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
70 |
title="Emotion Detection with DistilBERT",
|
71 |
description="This app uses the DistilBERT model fine-tuned for emotion detection. Enter any text to analyze its emotional content.",
|
72 |
examples=[
|
|
|
41 |
predictions = classifier(text)[0]
|
42 |
logger.info(f"Raw predictions: {predictions}")
|
43 |
|
44 |
+
# Convert predictions to the format Gradio's BarPlot expects
|
45 |
+
# We need a list of tuples (emotion, score)
|
46 |
+
scores = [(pred['label'], float(pred['score'])) for pred in predictions]
|
47 |
logger.info(f"Processed scores: {scores}")
|
48 |
|
49 |
+
return (
|
50 |
+
[score[0] for score in scores], # x values (emotions)
|
51 |
+
[score[1] for score in scores] # y values (probabilities)
|
52 |
+
)
|
53 |
|
54 |
except Exception as e:
|
55 |
logger.error(f"Error in prediction: {str(e)}")
|
|
|
64 |
demo = gr.Interface(
|
65 |
fn=predict_emotion,
|
66 |
inputs=gr.Textbox(placeholder="Enter text to analyze...", label="Input Text"),
|
67 |
+
outputs=[
|
68 |
+
gr.BarPlot(
|
69 |
+
title="Emotion Probabilities",
|
70 |
+
x_title="Emotion",
|
71 |
+
y_title="Probability",
|
72 |
+
height=400,
|
73 |
+
vertical=False
|
74 |
+
)
|
75 |
+
],
|
76 |
title="Emotion Detection with DistilBERT",
|
77 |
description="This app uses the DistilBERT model fine-tuned for emotion detection. Enter any text to analyze its emotional content.",
|
78 |
examples=[
|