Rowan Martnishn commited on
Commit
e88e59d
·
verified ·
1 Parent(s): 6e3fbdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -258,22 +258,22 @@ thread = threading.Thread(target=run_schedule)
258
  thread.daemon = True
259
  thread.start()
260
 
261
- # Gradio Interface
262
- if prediction_plot_base64:
263
- html_content = (
264
- f'<img src="data:image/png;base64,{prediction_plot_base64}" '
265
- 'alt="Prediction Plot" '
266
- 'style="width: 100vw; height: 100vh; object-fit: contain;">'
267
- )
268
- else:
269
- html_content = "Processing data..."
270
 
271
- custom_css = """
272
- body, .gradio-container {
273
- margin: 0;
274
- padding: 0;
275
- }
276
- """
277
 
278
  # with gr.Blocks(css=custom_css) as demo:
279
  # gr.HTML(value=html_content)
@@ -284,8 +284,10 @@ body, .gradio-container {
284
  # demo.launch()
285
 
286
  with gr.Blocks(css=custom_css) as demo:
287
- html_output = gr.HTML()
288
-
 
 
289
  def refresh_html():
290
  if prediction_plot_base64:
291
  return (
@@ -295,12 +297,17 @@ with gr.Blocks(css=custom_css) as demo:
295
  )
296
  else:
297
  return "Processing data..."
298
-
299
- # Use gr.Timer to trigger refresh_html every 10 seconds
300
- gr.Timer(
 
 
 
 
301
  fn=refresh_html,
302
- every=10, # Interval in seconds
303
  inputs=None,
304
  outputs=html_output,
305
  )
306
 
 
 
 
258
  thread.daemon = True
259
  thread.start()
260
 
261
+ # # Gradio Interface
262
+ # if prediction_plot_base64:
263
+ # html_content = (
264
+ # f'<img src="data:image/png;base64,{prediction_plot_base64}" '
265
+ # 'alt="Prediction Plot" '
266
+ # 'style="width: 100vw; height: 100vh; object-fit: contain;">'
267
+ # )
268
+ # else:
269
+ # html_content = "Processing data..."
270
 
271
+ # custom_css = """
272
+ # body, .gradio-container {
273
+ # margin: 0;
274
+ # padding: 0;
275
+ # }
276
+ # """
277
 
278
  # with gr.Blocks(css=custom_css) as demo:
279
  # gr.HTML(value=html_content)
 
284
  # demo.launch()
285
 
286
  with gr.Blocks(css=custom_css) as demo:
287
+ # Initialize the HTML output with a default message
288
+ html_output = gr.HTML("Processing data...")
289
+
290
+ # Define the refresh function
291
  def refresh_html():
292
  if prediction_plot_base64:
293
  return (
 
297
  )
298
  else:
299
  return "Processing data..."
300
+
301
+ # For newer versions of Gradio, Timer is used differently
302
+ demo.load(fn=refresh_html, inputs=None, outputs=html_output)
303
+
304
+ # Create a timer that updates the component
305
+ timer = gr.on(
306
+ triggers=[gr.triggers.Interval(10)], # Every 10 seconds
307
  fn=refresh_html,
 
308
  inputs=None,
309
  outputs=html_output,
310
  )
311
 
312
+ # Launch the demo
313
+ demo.launch()