ouhenio commited on
Commit
8eec983
·
verified ·
1 Parent(s): d7ed39d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -143,10 +143,11 @@ async def update_validation_space_on_answer(response, type, timestamp):
143
  # Store the error in the queue for display
144
  incoming_events.put({"event": "error", "error": str(e)})
145
 
146
- # Function to read the next event from the queue
147
  def read_next_event():
148
  if not incoming_events.empty():
149
- return incoming_events.get()
 
150
  return {}
151
 
152
  # Function to get the current annotation progress data
@@ -424,16 +425,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="pink", secondary_hue="purple"))
424
  return annotation_progress[code]
425
  return {}
426
 
427
- # Set up event handlers
428
- event_update = gr.on(
429
- triggers=[read_next_event],
430
- fn=lambda event: (
431
- event, # Update events JSON
432
- update_map() if event.get("event") == "progress_update" else None, # Update map
433
- update_stats() if event.get("event") == "progress_update" else (None, None, None), # Update stats
434
- ),
435
- outputs=[events_json, map_html, total_docs, avg_completion, countries_over_50]
436
- )
437
 
438
  country_selector.change(
439
  fn=update_country_details,
@@ -441,9 +442,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="pink", secondary_hue="purple"))
441
  outputs=[country_progress]
442
  )
443
 
444
- # Update everything every 10 seconds
445
- gr.Timer(10, active=True).tick(
446
- update_map,
 
 
447
  outputs=[map_html]
448
  )
449
 
 
143
  # Store the error in the queue for display
144
  incoming_events.put({"event": "error", "error": str(e)})
145
 
146
+ # Function to read the next event from the queue and update UI elements
147
  def read_next_event():
148
  if not incoming_events.empty():
149
+ event = incoming_events.get()
150
+ return event
151
  return {}
152
 
153
  # Function to get the current annotation progress data
 
425
  return annotation_progress[code]
426
  return {}
427
 
428
+ # Simple event processing functions for better compatibility
429
+ def update_events():
430
+ return read_next_event()
431
+
432
+ def update_all_stats():
433
+ return update_stats()
434
+
435
+ # Use separate timers for each component for better compatibility
436
+ gr.Timer(1, active=True).tick(update_events, outputs=events_json)
437
+ gr.Timer(5, active=True).tick(update_all_stats, outputs=[total_docs, avg_completion, countries_over_50])
438
 
439
  country_selector.change(
440
  fn=update_country_details,
 
442
  outputs=[country_progress]
443
  )
444
 
445
+ # Use refresh button instead of timer for map updates (more compatible across versions)
446
+ refresh_btn = gr.Button("Refresh Map")
447
+ refresh_btn.click(
448
+ fn=update_map,
449
+ inputs=None,
450
  outputs=[map_html]
451
  )
452