Join the conversation

Join the community of Machine Learners and AI enthusiasts.

Sign Up
freddyaboulton 
posted an update Mar 20
Post
1662
Tips for saving disk space with Gradio 💾

Try these out with gradio 4.22.0 ! Code snippet attached.

1. Set delete_cache. The delete_cache parameter will periodically delete files from gradio's cache that are older than a given age. Setting it will also delete all files created by that app when the app shuts down. It is a tuple of two ints, (frequency, age) expressed in seconds. So delete_cache=(3600, 3600), will delete files older than an hour every hour.

2. Use static files. Static files are not copied to the cache and are instead served directly to users of your app. This is useful for components displaying a lot of content that won't change, like a gallery with hundreds of images.

3. Set format="jpeg" for images and galleries. JPEGs take up less disk space than PNGs. This can also speed up the speed of your prediction function as they will be written to the cache faster.

Good stuff!

nice!! can you set the jpeg quality as well?

·

Not with the format parameter. That only applies if you return a numpy or PIL image from your prediction function. If you want to control how files are saved to jpeg, you can do that within your prediction function and gradio will not modify it further.