Rowan Martnishn commited on
Commit
a749575
·
verified ·
1 Parent(s): 65e0008

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -292,31 +292,30 @@ body, .gradio-container {
292
  """
293
 
294
 
295
- with gr.Blocks(css=custom_css) as demo:
296
- # Initialize the HTML output with a default message
297
- html_output = gr.HTML("Processing data...")
298
-
299
- # Define the refresh function
300
- def refresh_html():
301
  if prediction_plot_base64:
302
- return (
303
  f'<img src="data:image/png;base64,{prediction_plot_base64}" '
304
  'alt="Prediction Plot" '
305
  'style="width: 100vw; height: 100vh; object-fit: contain;">'
306
  )
307
  else:
308
- return "Processing data..."
309
-
310
- # For newer versions of Gradio, Timer is used differently
311
- demo.load(fn=refresh_html, inputs=None, outputs=html_output)
 
 
 
 
 
 
 
312
 
313
- # Create a timer that updates the component
314
- timer = gr.on(
315
- triggers=[gr.triggers.Interval(10)], # Every 10 seconds
316
- fn=refresh_html,
317
- inputs=None,
318
- outputs=html_output,
319
- )
320
 
321
  # Launch the demo
322
  demo.launch()
 
292
  """
293
 
294
 
295
+ # Create a function to update the HTML in a separate thread
296
+ def update_html_periodically(html_component):
297
+ while True:
 
 
 
298
  if prediction_plot_base64:
299
+ new_html = (
300
  f'<img src="data:image/png;base64,{prediction_plot_base64}" '
301
  'alt="Prediction Plot" '
302
  'style="width: 100vw; height: 100vh; object-fit: contain;">'
303
  )
304
  else:
305
+ new_html = "Processing data..."
306
+
307
+ # Update the HTML component
308
+ html_component.update(value=new_html)
309
+
310
+ # Wait 10 seconds
311
+ time.sleep(10)
312
+
313
+ with gr.Blocks(css=custom_css) as demo:
314
+ # Initialize the HTML output with a default message
315
+ html_output = gr.HTML("Processing data...")
316
 
317
+ # Start the update thread when the demo loads
318
+ demo.load(lambda: threading.Thread(target=update_html_periodically, args=(html_output,), daemon=True).start())
 
 
 
 
 
319
 
320
  # Launch the demo
321
  demo.launch()