Highlights
Automatically delete state after user has disconnected from the webpage (#7829 6a4bf7a
)
Gradio now automatically deletes gr.State
variables stored in the server's RAM when users close their browser tab.
The deletion will happen 60 minutes after the server detected a disconnect from the user's browser.
If the user connects again in that timeframe, their state will not be deleted.
Additionally, Gradio now includes a Blocks.unload()
event, allowing you to run arbitrary cleanup functions when users disconnect (this does not have a 60 minute delay).
You can think of the unload
event as the opposite of the load
event.
with gr.Blocks() as demo:
gr.Markdown(
"""# State Cleanup Demo
🖼️ Images are saved in a user-specific directory and deleted when the users closes the page via demo.unload.
""")
with gr.Row():
with gr.Column(scale=1):
with gr.Row():
img = gr.Image(label="Generated Image", height=300, width=300)
with gr.Row():
gen = gr.Button(value="Generate")
with gr.Row():
history = gr.Gallery(label="Previous Generations", height=500, columns=10)
state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
demo.load(generate_random_img, [state], [img, state, history])
gen.click(generate_random_img, [state], [img, state, history])
demo.unload(delete_directory)
demo.launch(auth=lambda user,pwd: True,
auth_message="Enter any username and password to continue")
Thanks @freddyaboulton!
Features
- #7863
024b44c
- Add support for lazy caching of examples, as well as addGRADIO_CACHE_EXAMPLES
env variable. Thanks @abidlabs! - #7892
c7933ff
- Suppress printing "Running on local URL:" when quiet is set. Thanks @dnoliver! - #7869
b9dbcf7
- Make buttons ingr.ChatInterface
more mobile-friendly. Thanks @abidlabs! - #7875
e6d051d
- Paste Images into MultimodalTextbox. Thanks @abidlabs! - #7893
f42d3e2
- Make internal event handlers of gr.Interface and gr.ChatInterface async. Thanks @freddyaboulton!
Fixes
- #7886
ccdab9b
- logout route deleting cookie fix. Thanks @MichaelPerger! - #7888
946487c
- Cache view_api info in server and python client. Thanks @freddyaboulton! - #7881
5e66e01
- Fix audio streaming out. Thanks @aliabid94! - #7865
7bbc3b6
- JS functions break entire app if there's no input, fixed. Thanks @aliabid94!