shegga commited on
Commit
23c0426
·
1 Parent(s): d3bc543

🔧 Fix BarPlot DataFrame format error

Browse files

Problem: 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>

Files changed (1) hide show
  1. app.py +7 -7
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 = pd.DataFrame([
261
- {"sentiment": "Negative", "confidence": result["probabilities"]["Negative"]},
262
- {"sentiment": "Neutral", "confidence": result["probabilities"]["Neutral"]},
263
- {"sentiment": "Positive", "confidence": result["probabilities"]["Positive"]}
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