Skip to main content
When building Gradio apps, you can use hot reload mode to automatically refresh your app when you make changes to your code. You can also enable vibe mode to use AI to help you write and edit your Gradio app using natural language.

Hot reload mode

When you’re building a Gradio app, particularly with Blocks, you may find it cumbersome to keep re-running your code to test your changes. Hot reload mode solves this by automatically reloading your app whenever you make changes to your code.

Basic usage

Instead of running your app with python app.py, simply use the gradio command:
gradio app.py
Now, whenever you save changes to app.py, Gradio will automatically reload your app. You’ll see output like this:
Watching: '/Users/freddy/sources/gradio/gradio', '/Users/freddy/sources/gradio/demo/'

Running on local URL:  http://127.0.0.1:7860
The Watching... line indicates that Gradio is observing the directory where your app file lives. When the file changes, it will automatically rerun the file for you, so you can focus on writing your code and your Gradio demo will refresh automatically.
Hot reload mode also works if you change the Gradio source code itself, making it useful if you decide to contribute to Gradio.

Custom demo name

Gradio specifically looks for a Gradio Blocks/Interface demo called demo in your code. If you’ve named your demo something else, you need to pass the name as the second parameter:
import gradio as gr

with gr.Blocks() as my_demo:
    gr.Markdown("# Greetings from Gradio!")
    inp = gr.Textbox(placeholder="What is your name?")
    out = gr.Textbox()
    inp.change(fn=lambda x: f"Welcome, {x}!", inputs=inp, outputs=out)

if __name__ == "__main__":
    my_demo.launch()
Run this with:
gradio app.py --demo-name=my_demo

Encoding settings

By default, Gradio uses UTF-8 encoding for scripts. If you’re using a different encoding format (such as cp1252):
  1. Add an encoding declaration to your Python script:
    # -*- coding: cp1252 -*-
    
  2. Confirm your code editor has identified that encoding format
  3. Run with the encoding flag:
    gradio app.py --encoding cp1252
    

Command line arguments

If your application accepts command line arguments, you can pass them in as well:
import gradio as gr
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--name", type=str, default="User")
args, unknown = parser.parse_known_args()

with gr.Blocks() as demo:
    gr.Markdown(f"# Greetings {args.name}!")
    inp = gr.Textbox()
    out = gr.Textbox()
    inp.change(fn=lambda x: x, inputs=inp, outputs=out)

if __name__ == "__main__":
    demo.launch()
Run with:
gradio app.py --name Alice
The gradio command does not detect parameters passed to the launch() method because the launch() method is never called in reload mode. For example, setting auth or show_error in launch() will not be reflected in the app.

Controlling the reload

By default, reload mode will re-run your entire script for every change you make. However, there are cases where this is not desirable.

Preventing code re-execution

For example, loading a machine learning model should probably only happen once to save time. Some Python libraries that use C or Rust extensions (like numpy and tiktoken) may throw errors when reloaded. In these situations, you can place code that you do not want to be re-run inside an if gr.NO_RELOAD: code block:
import gradio as gr

if gr.NO_RELOAD:
    from transformers import pipeline
    pipe = pipeline(
        "text-classification",
        model="cardiffnlp/twitter-roberta-base-sentiment-latest"
    )

def classify(text):
    results = pipe(text)
    return {d["label"]: d["score"] for d in results}

demo = gr.Interface(classify, gr.Textbox(), gr.Label())

if __name__ == "__main__":
    demo.launch()
The value of gr.NO_RELOAD is True, so you don’t have to change your script when you’re done developing and want to run it in production. Simply run the file with python instead of gradio.

Vibe mode

Vibe mode provides an in-browser chat interface that can be used to write or edit your Gradio app using natural language. To enable this, use the --vibe flag:
gradio --vibe app.py
Vibe mode lets you describe commands using natural language and have an LLM write or edit the code in your Gradio app. The LLM is powered by Hugging Face’s Inference Providers, so you must be logged into Hugging Face locally to use this. To log in to Hugging Face:
huggingface-cli login
When vibe mode is enabled, anyone who can access the Gradio endpoint can modify files and run arbitrary code on the host machine. Use only for local development.

Hot reload in Jupyter notebooks

If you use Jupyter Notebooks (or Colab Notebooks), you can use Gradio’s magic command for hot reloading.

Setting up the magic command

Load the Gradio extension at the top of your notebook:
%load_ext gradio
Then, in the cell where you’re developing your Gradio demo, write the magic command %%blocks at the top:
%%blocks

import gradio as gr

with gr.Blocks() as demo:
    gr.Markdown("# Greetings!")
    inp = gr.Textbox()
    out = gr.Textbox()
    inp.change(fn=lambda x: x, inputs=inp, outputs=out)
Notice that:
  • You do not need to call launch() - Gradio does that for you automatically
  • Every time you rerun the cell, Gradio will re-render your app on the same port and using the same underlying web server
  • You’ll see your changes much faster than if you were rerunning the cell normally
This works in Colab notebooks too! Here’s a Colab notebook where you can see the Blocks magic in action.
You may have to use %%blocks --share in Colab to get the demo to appear in the cell.

Benefits of hot reload mode

Hot reload mode significantly improves your development workflow by:
  • Eliminating the need to manually restart your app after every change
  • Preserving the app’s network port across reloads
  • Allowing you to see changes instantly
  • Supporting both Python scripts and Jupyter notebooks
  • Working seamlessly with your existing development tools
Whether you’re building a simple interface or a complex multi-page app, hot reload mode makes Gradio development faster and more enjoyable.