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

πŸ”§ Fix JavaScript addEventListener error by removing problematic BarPlot

Browse files

Problem: Svelte component error "can't access property 'addEventListener', y is undefined"
Solution:
- Remove problematic gradio.BarPlot component causing JavaScript errors
- Simplify interface to use text-based confidence display only
- Remove pandas dependency that was causing conflicts
- Update event handlers to remove BarPlot references
- Maintain all core functionality while fixing JavaScript errors

Changes:
- Removed gradio.BarPlot component completely
- Simplified analyze_sentiment function to return text only
- Updated clear_inputs function to remove BarPlot handling
- Fixed button event handlers to work without plot component
- Removed pandas import (no longer needed)

πŸ€– Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +6 -19
app.py CHANGED
@@ -12,7 +12,6 @@
12
  import gc
13
  import psutil
14
  import os
15
- import pandas as pd
16
 
17
  # Global app instance
18
  app_instance = None
@@ -252,22 +251,16 @@ def batch_predict(self, texts):
252
  # Define functions outside of interface creation for better scoping
253
  def analyze_sentiment(text):
254
  if not app_instance:
255
- return "❌ App not initialized. Please refresh the page.", gr.BarPlot(visible=False)
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
 
269
  def clear_inputs():
270
- return "", "", gr.BarPlot(visible=False)
271
 
272
  def analyze_batch(texts):
273
  if not app_instance:
@@ -366,12 +359,6 @@ def create_interface():
366
  )
367
 
368
  result_output = gr.Markdown(label="Analysis Result", visible=True)
369
- confidence_plot = gr.BarPlot(
370
- title="Confidence Scores",
371
- x="sentiment",
372
- y="confidence",
373
- visible=False
374
- )
375
 
376
  # Batch Analysis Tab
377
  with gr.Tab("πŸ“Š Batch Analysis"):
@@ -441,12 +428,12 @@ def create_interface():
441
  analyze_btn.click(
442
  fn=analyze_sentiment,
443
  inputs=[text_input],
444
- outputs=[result_output, confidence_plot]
445
  )
446
 
447
  clear_btn.click(
448
  fn=clear_inputs,
449
- outputs=[text_input, result_output, confidence_plot]
450
  )
451
 
452
  batch_analyze_btn.click(
 
12
  import gc
13
  import psutil
14
  import os
 
15
 
16
  # Global app instance
17
  app_instance = None
 
251
  # Define functions outside of interface creation for better scoping
252
  def analyze_sentiment(text):
253
  if not app_instance:
254
+ return "❌ App not initialized. Please refresh the page."
255
 
256
  result, output = app_instance.predict_sentiment(text)
257
  if result:
258
+ return output
 
 
 
 
 
 
259
  else:
260
+ return output
261
 
262
  def clear_inputs():
263
+ return "", ""
264
 
265
  def analyze_batch(texts):
266
  if not app_instance:
 
359
  )
360
 
361
  result_output = gr.Markdown(label="Analysis Result", visible=True)
 
 
 
 
 
 
362
 
363
  # Batch Analysis Tab
364
  with gr.Tab("πŸ“Š Batch Analysis"):
 
428
  analyze_btn.click(
429
  fn=analyze_sentiment,
430
  inputs=[text_input],
431
+ outputs=[result_output]
432
  )
433
 
434
  clear_btn.click(
435
  fn=clear_inputs,
436
+ outputs=[text_input, result_output]
437
  )
438
 
439
  batch_analyze_btn.click(