gradio-6-migration-tool / migration_guide.txt
multimodalart's picture
Create migration_guide.txt
0c5f6d7 verified
raw
history blame
4.81 kB
# Gradio 6 Migration Guide
We are excited to release Gradio 6, the latest major version of the Gradio library. Gradio 6 is significantly more performant, lighter, and easier to customize than previous versions of Gradio. The Gradio team is only planning on maintaining future versions of Gradio 6 so we encourage all developers to migrate to Gradio 6.x.
Gradio 6 includes several breaking changes that were made in order to standardize the Python API.
## App-level Changes
### App-level parameters have been moved from `Blocks` to `launch()`
The `gr.Blocks` class constructor previously contained several parameters that applied to your entire Gradio app (theme, css, js, head). Since `gr.Blocks` can be nested, these have moved to `launch()`.
**Before (Gradio 5.x):**
```python
with gr.Blocks(theme=gr.themes.Soft(), css=".my-class { color: red; }") as demo:
...
demo.launch()
```
**After (Gradio 6.x):**
```python
with gr.Blocks() as demo:
...
demo.launch(theme=gr.themes.Soft(), css=".my-class { color: red; }")
```
### `show_api` parameter replaced with `footer_links`
**Before (Gradio 5.x):**
- `demo.launch(show_api=False)`
**After (Gradio 6.x):**
- `demo.launch(footer_links=["gradio", "settings"])`
- To show API: `demo.launch(footer_links=["api", "gradio", "settings"])` (or default)
### Event listener parameters: `show_api` removed and `api_name=False` no longer supported
**Before (Gradio 5.x):**
```python
btn.click(fn=..., show_api=False)
# OR
btn.click(fn=..., api_name=False)
```
**After (Gradio 6.x):**
```python
# Equivalent to show_api=False
btn.click(fn=..., api_visibility="undocumented")
# Equivalent to api_name=False
btn.click(fn=..., api_visibility="private")
# Default is api_visibility="public"
```
### `like_user_message` moved from `.like()` event to constructor
**Before (Gradio 5.x):**
```python
chatbot.like(print_like_dislike, None, None, like_user_message=True)
```
**After (Gradio 6.x):**
```python
chatbot = gr.Chatbot(like_user_message=True)
chatbot.like(print_like_dislike, None, None)
```
### Default API names for `Interface` and `ChatInterface` now use function names
**Before:** `gr.Interface(fn=predict)` generated endpoint `/predict`.
**After:** `gr.Interface(fn=predict)` generates endpoint `/predict` (the function name).
To keep old names: `gr.Interface(..., api_name="predict")`.
### `gr.Chatbot` and `gr.ChatInterface` tuple format removed
**Before (Gradio 5.x):**
```python
chatbot = gr.Chatbot(value=[["User message", "Bot message"]])
```
**After (Gradio 6.x):**
```python
chatbot = gr.Chatbot(
value=[
{"role": "user", "content": "User message"},
{"role": "assistant", "content": "Bot message"}
],
type="messages"
)
```
### `gr.ChatInterface` `history` format now uses structured content
Content is now always a list of content blocks, even for text.
**Before:** `{"role": "user", "content": "Hello"}`
**After:** `{"role": "user", "content": [{"type": "text", "text": "Hello"}]}`
## Component-level Changes
### `gr.Video` no longer accepts tuple values for video and subtitles
**Before (Gradio 5.x):**
```python
return ("video.mp4", "subs.srt")
```
**After (Gradio 6.x):**
```python
return gr.Video(value="video.mp4", subtitles="subs.srt")
```
### `gr.HTML` `padding` parameter default changed to `False`
**After (Gradio 6.x):** Default is `padding=False`. Use `padding=True` explicitly to match old behavior.
### `gr.Dataframe` `row_count` and `col_count` parameters restructured
**Before:** `row_count=(5, "fixed")`
**After:** `row_count=5, row_limits=(5, 5)`
**Before:** `row_count=(5, "dynamic")`
**After:** `row_count=5, row_limits=None`
### `allow_tags=True` is now the default for `gr.Chatbot`
**After (Gradio 6.x):** Tags are allowed by default. To sanitize, use `allow_tags=False`.
### Removed Component Parameters
#### `gr.Chatbot`
- `bubble_full_width` removed.
- `show_copy_button` -> use `buttons=["copy"]`.
- `show_share_button` -> use `buttons=["share"]`.
#### `gr.Audio` / `gr.Video` / `gr.Image`
- `show_download_button` -> use `buttons=["download"]`.
- `show_share_button` -> use `buttons=["share"]`.
- `min_length` / `max_length` -> use `validator=...`.
- `mirror_webcam` -> use `webcam_options=gr.WebcamOptions(mirror=True)`.
#### `gr.ImageEditor`
- `crop_size` -> use `canvas_size`.
#### `gr.LogoutButton`
- Removed. Use `gr.LoginButton`.
#### Plot Components
- `show_fullscreen_button` -> `buttons=["fullscreen"]`.
- `color_legend_title` -> `color_title`.
## Python Client Changes
### `hf_token` parameter renamed to `token` in `Client`
**Before:** `Client(..., hf_token="...")`
**After:** `Client(..., token="...")`
### `deploy_discord` method deprecated
Removed.
### `AppError` now subclasses `Exception`
Catch `AppError` specifically, not `ValueError`.