Spaces:
Runtime error
Runtime error
🔧 Fix BarPlot DataFrame format error
Browse filesProblem: gradio.BarPlot was failing with DataFrame format issue
Solution:
- Convert DataFrame to list of lists format for better compatibility
- Remove pandas DataFrame dependency from plot data
- Use simpler data structure that works with gradio.BarPlot
- Maintain x/y axis configuration for proper display
Changes:
- Updated analyze_sentiment function to use list format
- Fixed data structure: [[Negative, 0.1], [Neutral, 0.7], [Positive, 0.2]]
- Preserved all functionality while fixing plot display
- Maintained x=sentiment, y=confidence axis labels
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -256,13 +256,13 @@ def analyze_sentiment(text):
|
|
| 256 |
|
| 257 |
result, output = app_instance.predict_sentiment(text)
|
| 258 |
if result:
|
| 259 |
-
# Prepare data for confidence plot
|
| 260 |
-
plot_data =
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
]
|
| 265 |
-
return output, gr.BarPlot(visible=True, value=plot_data)
|
| 266 |
else:
|
| 267 |
return output, gr.BarPlot(visible=False)
|
| 268 |
|
|
|
|
| 256 |
|
| 257 |
result, output = app_instance.predict_sentiment(text)
|
| 258 |
if result:
|
| 259 |
+
# Prepare data for confidence plot - convert to list of lists format for BarPlot
|
| 260 |
+
plot_data = [
|
| 261 |
+
["Negative", result["probabilities"]["Negative"]],
|
| 262 |
+
["Neutral", result["probabilities"]["Neutral"]],
|
| 263 |
+
["Positive", result["probabilities"]["Positive"]]
|
| 264 |
+
]
|
| 265 |
+
return output, gr.BarPlot(visible=True, value=plot_data, x="sentiment", y="confidence")
|
| 266 |
else:
|
| 267 |
return output, gr.BarPlot(visible=False)
|
| 268 |
|