Rowan Martnishn commited on
Commit
19d8658
·
verified ·
1 Parent(s): 3f4fd8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -247,29 +247,30 @@ body, .gradio-container {
247
 
248
 
249
  with gr.Blocks(css=custom_css) as demo:
250
- # Initialize a placeholder for the loaded space
251
- space_placeholder = gr.HTML("Loading space...")
252
 
253
- # Define the refresh function to call load_space()
254
  def refresh_html():
255
- try:
256
- # Load the space
257
- space = load_space()
258
- # Return the rendered HTML of the space
259
- return space.render()
260
- except Exception as e:
261
- return f"Error loading space: {str(e)}"
 
262
 
263
- # Use the Timer component to refresh the HTML every hour (3600 seconds)
264
- timer = gr.Timer(
265
- every=3600, # Interval in seconds (1 hour)
266
- fn=refresh_html, # Function to call
267
- inputs=None, # No inputs
268
- outputs=space_placeholder, # Output to update
269
- )
270
 
271
  # Initial call to set the HTML content when the page loads
272
- demo.load(refresh_html, inputs=None, outputs=space_placeholder)
273
 
274
  # Launch the demo
275
  demo.launch()
 
247
 
248
 
249
  with gr.Blocks(css=custom_css) as demo:
250
+ # Initialize the HTML output with a default message
251
+ html_output = gr.HTML("Processing data...")
252
 
253
+ # Define the refresh function
254
  def refresh_html():
255
+ if prediction_plot_base64:
256
+ return (
257
+ f'<img src="data:image/png;base64,{prediction_plot_base64}" '
258
+ 'alt="Prediction Plot" '
259
+ 'style="width: 100vw; height: 100vh; object-fit: contain;">'
260
+ )
261
+ else:
262
+ return "Processing data..."
263
 
264
+ # Use the Timer component according to the documentation
265
+ timer = gr.Timer(3600, refresh_html, [], html_output)
266
+
267
+
268
+
269
+
270
+
271
 
272
  # Initial call to set the HTML content when the page loads
273
+ demo.load(refresh_html, [], html_output)
274
 
275
  # Launch the demo
276
  demo.launch()