> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
> Use this file to discover all available pages before exploring further.

# Hot reload and vibe mode

> Develop Gradio apps faster with hot reload mode and AI-powered vibe mode

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:

```bash theme={null}
gradio app.py
```

Now, whenever you save changes to `app.py`, Gradio will automatically reload your app. You'll see output like this:

```bash theme={null}
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.

<Tip>
  Hot reload mode also works if you change the Gradio source code itself, making it useful if you decide to [contribute to Gradio](https://github.com/gradio-app/gradio/blob/main/CONTRIBUTING.md).
</Tip>

### 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:

```python theme={null}
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:

```bash theme={null}
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:
   ```python theme={null}
   # -*- coding: cp1252 -*-
   ```

2. Confirm your code editor has identified that encoding format

3. Run with the encoding flag:
   ```bash theme={null}
   gradio app.py --encoding cp1252
   ```

### Command line arguments

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

```python theme={null}
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:

```bash theme={null}
gradio app.py --name Alice
```

<Warning>
  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.
</Warning>

## 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:

```python theme={null}
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()
```

<Tip>
  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`.
</Tip>

## 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:

```bash theme={null}
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](https://huggingface.co/docs/inference-providers/en/index), so you must be logged into Hugging Face locally to use this.

To log in to Hugging Face:

```bash theme={null}
huggingface-cli login
```

<Warning>
  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.
</Warning>

## 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:

```python theme={null}
%load_ext gradio
```

Then, in the cell where you're developing your Gradio demo, write the magic command `%%blocks` at the top:

```python theme={null}
%%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

<Tip>
  This works in Colab notebooks too! Here's [a Colab notebook](https://colab.research.google.com/drive/1zAuWoiTIb3O2oitbtVb2_ekv1K6ggtC1?usp=sharing) where you can see the Blocks magic in action.
</Tip>

<Note>
  You may have to use `%%blocks --share` in Colab to get the demo to appear in the cell.
</Note>

## 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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.