Gradio lauch demo when webpage is opened and close demo when webpage is closed

hi @SloganTapleton , have you tried the Block.load() method? it runs every time the demo is refresh in the browser. I’m sure you can leverage it to refresh the model as you need.

Instance method: adds event that runs as soon as the demo loads in the browser.

example

import gradio as gr
import datetime
with gr.Blocks() as demo:
    def get_time():
        return datetime.datetime.now().time()
    dt = gr.Textbox(label="Current time")
    demo.load(get_time, inputs=None, outputs=dt)
demo.launch()
1 Like