Spaces:
Sleeping
Sleeping
Rowan Martnishn
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -292,31 +292,30 @@ body, .gradio-container {
|
|
292 |
"""
|
293 |
|
294 |
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
# Define the refresh function
|
300 |
-
def refresh_html():
|
301 |
if prediction_plot_base64:
|
302 |
-
|
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 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
-
#
|
314 |
-
|
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()
|