Rowan Martnishn commited on
Commit
25498b5
·
verified ·
1 Parent(s): a749575

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -292,30 +292,26 @@ body, .gradio-container {
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()
 
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
+ # Use the Timer component according to the documentation
311
+ timer = gr.Timer(10, refresh_html, [], html_output)
 
 
 
 
 
 
 
312
 
313
+ # Initial call to set the HTML content when the page loads
314
+ demo.load(refresh_html, [], html_output)
315
 
316
  # Launch the demo
317
  demo.launch()