Update migration_guide.txt
Browse files- migration_guide.txt +774 -59
migration_guide.txt
CHANGED
|
@@ -1,62 +1,158 @@
|
|
| 1 |
# Gradio 6 Migration Guide
|
| 2 |
|
| 3 |
-
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.
|
| 4 |
-
|
| 5 |
-
Gradio 6 includes several breaking changes that were made in order to standardize the Python API.
|
| 6 |
-
|
| 7 |
## App-level Changes
|
| 8 |
|
| 9 |
### App-level parameters have been moved from `Blocks` to `launch()`
|
| 10 |
|
| 11 |
-
The `gr.Blocks` class constructor previously contained several parameters that applied to your entire Gradio app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
**Before (Gradio 5.x):**
|
|
|
|
| 14 |
```python
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
demo.launch()
|
| 18 |
```
|
| 19 |
|
| 20 |
**After (Gradio 6.x):**
|
|
|
|
| 21 |
```python
|
|
|
|
|
|
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
```
|
| 26 |
|
|
|
|
|
|
|
| 27 |
### `show_api` parameter replaced with `footer_links`
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
**Before (Gradio 5.x):**
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
**After (Gradio 6.x):**
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
### Event listener parameters: `show_api` removed and `api_name=False` no longer supported
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
**Before (Gradio 5.x):**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
```python
|
| 40 |
-
btn.click(fn
|
| 41 |
-
# OR
|
| 42 |
-
btn.click(fn=..., api_name=False)
|
| 43 |
```
|
| 44 |
|
| 45 |
**After (Gradio 6.x):**
|
|
|
|
| 46 |
```python
|
| 47 |
-
|
| 48 |
-
btn.click(fn=..., api_visibility="undocumented")
|
| 49 |
|
| 50 |
-
|
| 51 |
-
btn.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
```
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
### `like_user_message` moved from `.like()` event to constructor
|
| 57 |
|
|
|
|
|
|
|
| 58 |
**Before (Gradio 5.x):**
|
| 59 |
```python
|
|
|
|
| 60 |
chatbot.like(print_like_dislike, None, None, like_user_message=True)
|
| 61 |
```
|
| 62 |
|
|
@@ -66,98 +162,717 @@ chatbot = gr.Chatbot(like_user_message=True)
|
|
| 66 |
chatbot.like(print_like_dislike, None, None)
|
| 67 |
```
|
| 68 |
|
|
|
|
| 69 |
### Default API names for `Interface` and `ChatInterface` now use function names
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
### `gr.Chatbot` and `gr.ChatInterface` tuple format removed
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
**Before (Gradio 5.x):**
|
|
|
|
| 78 |
```python
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
```
|
| 81 |
|
| 82 |
**After (Gradio 6.x):**
|
|
|
|
| 83 |
```python
|
|
|
|
|
|
|
|
|
|
| 84 |
chatbot = gr.Chatbot(
|
| 85 |
value=[
|
| 86 |
-
{"role": "user", "content": "
|
| 87 |
-
{"role": "assistant", "content": "
|
| 88 |
],
|
| 89 |
type="messages"
|
| 90 |
)
|
| 91 |
```
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
### `gr.ChatInterface` `history` format now uses structured content
|
| 94 |
|
| 95 |
-
Content is now always a list of content blocks, even for text.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
**
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
## Component-level Changes
|
| 101 |
|
| 102 |
### `gr.Video` no longer accepts tuple values for video and subtitles
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
**Before (Gradio 5.x):**
|
|
|
|
| 105 |
```python
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
```
|
| 108 |
|
| 109 |
**After (Gradio 6.x):**
|
|
|
|
| 110 |
```python
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
```
|
| 113 |
|
| 114 |
### `gr.HTML` `padding` parameter default changed to `False`
|
| 115 |
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
### `gr.Dataframe` `row_count` and `col_count` parameters restructured
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
### `allow_tags=True` is now the default for `gr.Chatbot`
|
| 127 |
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
|
| 133 |
-
- `
|
| 134 |
-
-
|
| 135 |
-
-
|
| 136 |
|
| 137 |
-
|
| 138 |
-
- `show_download_button` -> use `buttons=["download"]`.
|
| 139 |
-
- `show_share_button` -> use `buttons=["share"]`.
|
| 140 |
-
- `min_length` / `max_length` -> use `validator=...`.
|
| 141 |
-
- `mirror_webcam` -> use `webcam_options=gr.WebcamOptions(mirror=True)`.
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
-
|
| 147 |
-
- Removed. Use `gr.LoginButton`.
|
| 148 |
|
| 149 |
-
|
| 150 |
-
- `
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
## Python Client Changes
|
| 154 |
|
| 155 |
### `hf_token` parameter renamed to `token` in `Client`
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
### `deploy_discord` method deprecated
|
| 160 |
-
Removed.
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Gradio 6 Migration Guide
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
## App-level Changes
|
| 4 |
|
| 5 |
### App-level parameters have been moved from `Blocks` to `launch()`
|
| 6 |
|
| 7 |
+
The `gr.Blocks` class constructor previously contained several parameters that applied to your entire Gradio app, specifically:
|
| 8 |
+
|
| 9 |
+
* `theme`: The theme for your Gradio app
|
| 10 |
+
* `css`: Custom CSS code as a string
|
| 11 |
+
* `css_paths`: Paths to custom CSS files
|
| 12 |
+
* `js`: Custom JavaScript code
|
| 13 |
+
* `head`: Custom HTML code to insert in the head of the page
|
| 14 |
+
* `head_paths`: Paths to custom HTML files to insert in the head
|
| 15 |
+
|
| 16 |
+
Since `gr.Blocks` can be nested and are not necessarily unique to a Gradio app, these parameters have now been moved to `Blocks.launch()`, which can only be called once for your entire Gradio app.
|
| 17 |
|
| 18 |
**Before (Gradio 5.x):**
|
| 19 |
+
|
| 20 |
```python
|
| 21 |
+
import gradio as gr
|
| 22 |
+
|
| 23 |
+
with gr.Blocks(
|
| 24 |
+
theme=gr.themes.Soft(),
|
| 25 |
+
css=".my-class { color: red; }",
|
| 26 |
+
) as demo:
|
| 27 |
+
gr.Textbox(label="Input")
|
| 28 |
+
|
| 29 |
demo.launch()
|
| 30 |
```
|
| 31 |
|
| 32 |
**After (Gradio 6.x):**
|
| 33 |
+
|
| 34 |
```python
|
| 35 |
+
import gradio as gr
|
| 36 |
+
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
+
gr.Textbox(label="Input")
|
| 39 |
+
|
| 40 |
+
demo.launch(
|
| 41 |
+
theme=gr.themes.Soft(),
|
| 42 |
+
css=".my-class { color: red; }",
|
| 43 |
+
)
|
| 44 |
```
|
| 45 |
|
| 46 |
+
This change makes it clearer that these parameters apply to the entire app and not to individual `Blocks` instances.
|
| 47 |
+
|
| 48 |
### `show_api` parameter replaced with `footer_links`
|
| 49 |
|
| 50 |
+
The `show_api` parameter in `launch()` has been replaced with a more flexible `footer_links` parameter that allows you to control which links appear in the footer of your Gradio app.
|
| 51 |
+
|
| 52 |
+
**In Gradio 5.x:**
|
| 53 |
+
- `show_api=True` (default) showed the API documentation link in the footer
|
| 54 |
+
- `show_api=False` hid the API documentation link
|
| 55 |
+
|
| 56 |
+
**In Gradio 6.x:**
|
| 57 |
+
- `footer_links` accepts a list of strings: `["api", "gradio", "settings"]`
|
| 58 |
+
- You can now control precisely which footer links are shown:
|
| 59 |
+
- `"api"`: Shows the API documentation link
|
| 60 |
+
- `"gradio"`: Shows the "Built with Gradio" link
|
| 61 |
+
- `"settings"`: Shows the settings link
|
| 62 |
+
|
| 63 |
**Before (Gradio 5.x):**
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
import gradio as gr
|
| 67 |
+
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
gr.Textbox(label="Input")
|
| 70 |
+
|
| 71 |
+
demo.launch(show_api=False)
|
| 72 |
+
```
|
| 73 |
|
| 74 |
**After (Gradio 6.x):**
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
import gradio as gr
|
| 78 |
+
|
| 79 |
+
with gr.Blocks() as demo:
|
| 80 |
+
gr.Textbox(label="Input")
|
| 81 |
+
|
| 82 |
+
demo.launch(footer_links=["gradio", "settings"])
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
To replicate the old behavior:
|
| 86 |
+
- `show_api=True` → `footer_links=["api", "gradio", "settings"]` (or just omit the parameter, as this is the default)
|
| 87 |
+
- `show_api=False` → `footer_links=["gradio", "settings"]`
|
| 88 |
|
| 89 |
### Event listener parameters: `show_api` removed and `api_name=False` no longer supported
|
| 90 |
|
| 91 |
+
In event listeners (such as `.click()`, `.change()`, etc.), the `show_api` parameter has been removed, and `api_name` no longer accepts `False` as a valid value. These have been replaced with a new `api_visibility` parameter that provides more fine-grained control.
|
| 92 |
+
|
| 93 |
+
**In Gradio 5.x:**
|
| 94 |
+
- `show_api=True` (default) showed the endpoint in the API documentation
|
| 95 |
+
- `show_api=False` hid the endpoint from API docs but still allowed downstream apps to use it
|
| 96 |
+
- `api_name=False` completely disabled the API endpoint (no downstream apps could use it)
|
| 97 |
+
|
| 98 |
+
**In Gradio 6.x:**
|
| 99 |
+
- `api_visibility` accepts one of three string values:
|
| 100 |
+
- `"public"`: The endpoint is shown in API docs and accessible to all (equivalent to old `show_api=True`)
|
| 101 |
+
- `"undocumented"`: The endpoint is hidden from API docs but still accessible to downstream apps (equivalent to old `show_api=False`)
|
| 102 |
+
- `"private"`: The endpoint is completely disabled and inaccessible (equivalent to old `api_name=False`)
|
| 103 |
+
|
| 104 |
**Before (Gradio 5.x):**
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
import gradio as gr
|
| 108 |
+
|
| 109 |
+
with gr.Blocks() as demo:
|
| 110 |
+
btn = gr.Button("Click me")
|
| 111 |
+
output = gr.Textbox()
|
| 112 |
+
|
| 113 |
+
btn.click(fn=lambda: "Hello", outputs=output, show_api=False)
|
| 114 |
+
|
| 115 |
+
demo.launch()
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
Or to completely disable the API:
|
| 119 |
+
|
| 120 |
```python
|
| 121 |
+
btn.click(fn=lambda: "Hello", outputs=output, api_name=False)
|
|
|
|
|
|
|
| 122 |
```
|
| 123 |
|
| 124 |
**After (Gradio 6.x):**
|
| 125 |
+
|
| 126 |
```python
|
| 127 |
+
import gradio as gr
|
|
|
|
| 128 |
|
| 129 |
+
with gr.Blocks() as demo:
|
| 130 |
+
btn = gr.Button("Click me")
|
| 131 |
+
output = gr.Textbox()
|
| 132 |
+
|
| 133 |
+
btn.click(fn=lambda: "Hello", outputs=output, api_visibility="undocumented")
|
| 134 |
+
|
| 135 |
+
demo.launch()
|
| 136 |
+
```
|
| 137 |
|
| 138 |
+
Or to completely disable the API:
|
| 139 |
+
|
| 140 |
+
```python
|
| 141 |
+
btn.click(fn=lambda: "Hello", outputs=output, api_visibility="private")
|
| 142 |
```
|
| 143 |
|
| 144 |
+
To replicate the old behavior:
|
| 145 |
+
- `show_api=True` → `api_visibility="public"` (or just omit the parameter, as this is the default)
|
| 146 |
+
- `show_api=False` → `api_visibility="undocumented"`
|
| 147 |
+
- `api_name=False` → `api_visibility="private"`
|
| 148 |
+
|
| 149 |
### `like_user_message` moved from `.like()` event to constructor
|
| 150 |
|
| 151 |
+
The `like_user_message` parameter has been moved from the `.like()` event listener to the Chatbot constructor.
|
| 152 |
+
|
| 153 |
**Before (Gradio 5.x):**
|
| 154 |
```python
|
| 155 |
+
chatbot = gr.Chatbot()
|
| 156 |
chatbot.like(print_like_dislike, None, None, like_user_message=True)
|
| 157 |
```
|
| 158 |
|
|
|
|
| 162 |
chatbot.like(print_like_dislike, None, None)
|
| 163 |
```
|
| 164 |
|
| 165 |
+
|
| 166 |
### Default API names for `Interface` and `ChatInterface` now use function names
|
| 167 |
|
| 168 |
+
The default API endpoint names for `gr.Interface` and `gr.ChatInterface` have changed to be consistent with how `gr.Blocks` events work and to better support MCP (Model Context Protocol) tools.
|
| 169 |
+
|
| 170 |
+
**In Gradio 5.x:**
|
| 171 |
+
- `gr.Interface` had a default API name of `/predict`
|
| 172 |
+
- `gr.ChatInterface` had a default API name of `/chat`
|
| 173 |
+
|
| 174 |
+
**In Gradio 6.x:**
|
| 175 |
+
- Both `gr.Interface` and `gr.ChatInterface` now use the name of the function you pass in as the default API endpoint name
|
| 176 |
+
- This makes the API more descriptive and consistent with `gr.Blocks` behavior
|
| 177 |
+
|
| 178 |
+
E.g. if your Gradio app is:
|
| 179 |
+
|
| 180 |
+
```python
|
| 181 |
+
import gradio as gr
|
| 182 |
+
|
| 183 |
+
def generate_text(prompt):
|
| 184 |
+
return f"Generated: {prompt}"
|
| 185 |
+
|
| 186 |
+
demo = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
| 187 |
+
demo.launch()
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
Previously, the API endpoint that Gradio generated would be: `/predict`. Now, the API endpoint will be: `/generate_text`
|
| 191 |
+
|
| 192 |
+
**To maintain the old endpoint names:**
|
| 193 |
+
|
| 194 |
+
If you need to keep the old endpoint names for backward compatibility (e.g., if you have external services calling these endpoints), you can explicitly set the `api_name` parameter:
|
| 195 |
+
|
| 196 |
+
```python
|
| 197 |
+
demo = gr.Interface(fn=generate_text, inputs="text", outputs="text", api_name="predict")
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
Similarly for `ChatInterface`:
|
| 201 |
+
|
| 202 |
+
```python
|
| 203 |
+
demo = gr.ChatInterface(fn=chat_function, api_name="chat")
|
| 204 |
+
```
|
| 205 |
|
| 206 |
### `gr.Chatbot` and `gr.ChatInterface` tuple format removed
|
| 207 |
|
| 208 |
+
The tuple format for chatbot messages has been removed in Gradio 6.0. You must now use the messages format with dictionaries containing "role" and "content" keys.
|
| 209 |
+
|
| 210 |
+
**In Gradio 5.x:**
|
| 211 |
+
- You could use `type="tuples"` or the default tuple format: `[["user message", "assistant message"], ...]`
|
| 212 |
+
- The tuple format was a list of lists where each inner list had two elements: `[user_message, assistant_message]`
|
| 213 |
+
|
| 214 |
+
**In Gradio 6.x:**
|
| 215 |
+
- Only the messages format is supported: `type="messages"`
|
| 216 |
+
- Messages must be dictionaries with "role" and "content" keys: `[{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi there!"}]`
|
| 217 |
+
|
| 218 |
**Before (Gradio 5.x):**
|
| 219 |
+
|
| 220 |
```python
|
| 221 |
+
import gradio as gr
|
| 222 |
+
|
| 223 |
+
# Using tuple format
|
| 224 |
+
chatbot = gr.Chatbot(value=[["Hello", "Hi there!"]])
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
Or with `type="tuples"`:
|
| 228 |
+
|
| 229 |
+
```python
|
| 230 |
+
chatbot = gr.Chatbot(value=[["Hello", "Hi there!"]], type="tuples")
|
| 231 |
```
|
| 232 |
|
| 233 |
**After (Gradio 6.x):**
|
| 234 |
+
|
| 235 |
```python
|
| 236 |
+
import gradio as gr
|
| 237 |
+
|
| 238 |
+
# Must use messages format
|
| 239 |
chatbot = gr.Chatbot(
|
| 240 |
value=[
|
| 241 |
+
{"role": "user", "content": "Hello"},
|
| 242 |
+
{"role": "assistant", "content": "Hi there!"}
|
| 243 |
],
|
| 244 |
type="messages"
|
| 245 |
)
|
| 246 |
```
|
| 247 |
|
| 248 |
+
Similarly for `gr.ChatInterface`, if you were manually setting the chat history:
|
| 249 |
+
|
| 250 |
+
```python
|
| 251 |
+
# Before (Gradio 5.x)
|
| 252 |
+
demo = gr.ChatInterface(
|
| 253 |
+
fn=chat_function,
|
| 254 |
+
examples=[["Hello", "Hi there!"]]
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
# After (Gradio 6.x)
|
| 258 |
+
demo = gr.ChatInterface(
|
| 259 |
+
fn=chat_function,
|
| 260 |
+
examples=[{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi there!"}]
|
| 261 |
+
)
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
**Note:** If you're using `gr.ChatInterface` with a function that returns messages, the function should return messages in the new format. The tuple format is no longer supported.
|
| 265 |
+
|
| 266 |
### `gr.ChatInterface` `history` format now uses structured content
|
| 267 |
|
| 268 |
+
The `history` format in `gr.ChatInterface` has been updated to consistently use OpenAI-style structured content format. Content is now always a list of content blocks, even for simple text messages.
|
| 269 |
+
|
| 270 |
+
**In Gradio 5.x:**
|
| 271 |
+
- Content could be a simple string: `{"role": "user", "content": "Hello"}`
|
| 272 |
+
- Simple text messages used a string directly
|
| 273 |
+
|
| 274 |
+
**In Gradio 6.x:**
|
| 275 |
+
- Content is always a list of content blocks: `{"role": "user", "content": [{"type": "text", "text": "Hello"}]}`
|
| 276 |
+
- This format is consistent with OpenAI's message format and supports multimodal content (text, images, etc.)
|
| 277 |
+
|
| 278 |
+
**Before (Gradio 5.x):**
|
| 279 |
+
|
| 280 |
+
```python
|
| 281 |
+
history = [
|
| 282 |
+
{"role": "user", "content": "What is the capital of France?"},
|
| 283 |
+
{"role": "assistant", "content": "Paris"}
|
| 284 |
+
]
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
**After (Gradio 6.x):**
|
| 288 |
+
|
| 289 |
+
```python
|
| 290 |
+
history = [
|
| 291 |
+
{"role": "user", "content": [{"type": "text", "text": "What is the capital of France?"}]},
|
| 292 |
+
{"role": "assistant", "content": [{"type": "text", "text": "Paris"}]}
|
| 293 |
+
]
|
| 294 |
+
```
|
| 295 |
|
| 296 |
+
**With files:**
|
| 297 |
+
|
| 298 |
+
When files are uploaded in the chat, they are represented as content blocks with `"type": "file"`. All content blocks (files and text) are grouped together in the same message's content array:
|
| 299 |
+
|
| 300 |
+
```python
|
| 301 |
+
history = [
|
| 302 |
+
{
|
| 303 |
+
"role": "user",
|
| 304 |
+
"content": [
|
| 305 |
+
{"type": "file", "file": {"path": "cat1.png"}},
|
| 306 |
+
{"type": "file", "file": {"path": "cat2.png"}},
|
| 307 |
+
{"type": "text", "text": "What's the difference between these two images?"}
|
| 308 |
+
]
|
| 309 |
+
}
|
| 310 |
+
]
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
This structured format allows for multimodal content (text, images, files, etc.) in chat messages, making it consistent with OpenAI's API format. All files uploaded in a single message are grouped together in the `content` array along with any text content.
|
| 314 |
|
| 315 |
## Component-level Changes
|
| 316 |
|
| 317 |
### `gr.Video` no longer accepts tuple values for video and subtitles
|
| 318 |
|
| 319 |
+
The tuple format for returning video with subtitles has been deprecated. Instead of returning a tuple `(video_path, subtitle_path)`, you should now use the `gr.Video` component directly with the `subtitles` parameter.
|
| 320 |
+
|
| 321 |
+
**In Gradio 5.x:**
|
| 322 |
+
- You could return a tuple of `(video_path, subtitle_path)` from a function
|
| 323 |
+
- The tuple format was `(str | Path, str | Path | None)`
|
| 324 |
+
|
| 325 |
+
**In Gradio 6.x:**
|
| 326 |
+
- Return a `gr.Video` component instance with the `subtitles` parameter
|
| 327 |
+
- This provides more flexibility and consistency with other components
|
| 328 |
+
|
| 329 |
**Before (Gradio 5.x):**
|
| 330 |
+
|
| 331 |
```python
|
| 332 |
+
import gradio as gr
|
| 333 |
+
|
| 334 |
+
def generate_video_with_subtitles(input):
|
| 335 |
+
video_path = "output.mp4"
|
| 336 |
+
subtitle_path = "subtitles.srt"
|
| 337 |
+
return (video_path, subtitle_path)
|
| 338 |
+
|
| 339 |
+
demo = gr.Interface(
|
| 340 |
+
fn=generate_video_with_subtitles,
|
| 341 |
+
inputs="text",
|
| 342 |
+
outputs=gr.Video()
|
| 343 |
+
)
|
| 344 |
+
demo.launch()
|
| 345 |
```
|
| 346 |
|
| 347 |
**After (Gradio 6.x):**
|
| 348 |
+
|
| 349 |
```python
|
| 350 |
+
import gradio as gr
|
| 351 |
+
|
| 352 |
+
def generate_video_with_subtitles(input):
|
| 353 |
+
video_path = "output.mp4"
|
| 354 |
+
subtitle_path = "subtitles.srt"
|
| 355 |
+
return gr.Video(value=video_path, subtitles=subtitle_path)
|
| 356 |
+
|
| 357 |
+
demo = gr.Interface(
|
| 358 |
+
fn=generate_video_with_subtitles,
|
| 359 |
+
inputs="text",
|
| 360 |
+
outputs=gr.Video()
|
| 361 |
+
)
|
| 362 |
+
demo.launch()
|
| 363 |
```
|
| 364 |
|
| 365 |
### `gr.HTML` `padding` parameter default changed to `False`
|
| 366 |
|
| 367 |
+
The default value of the `padding` parameter in `gr.HTML` has been changed from `True` to `False` for consistency with `gr.Markdown`.
|
| 368 |
+
|
| 369 |
+
**In Gradio 5.x:**
|
| 370 |
+
- `padding=True` was the default for `gr.HTML`
|
| 371 |
+
- HTML components had padding by default
|
| 372 |
+
|
| 373 |
+
**In Gradio 6.x:**
|
| 374 |
+
- `padding=False` is the default for `gr.HTML`
|
| 375 |
+
- This matches the default behavior of `gr.Markdown` for consistency
|
| 376 |
+
|
| 377 |
+
**To maintain the old behavior:**
|
| 378 |
+
|
| 379 |
+
If you want to keep the padding that was present in Gradio 5.x, explicitly set `padding=True`:
|
| 380 |
+
|
| 381 |
+
```python
|
| 382 |
+
html = gr.HTML("<div>Content</div>", padding=True)
|
| 383 |
+
```
|
| 384 |
+
|
| 385 |
|
| 386 |
### `gr.Dataframe` `row_count` and `col_count` parameters restructured
|
| 387 |
|
| 388 |
+
The `row_count` and `col_count` parameters in `gr.Dataframe` have been restructured to provide more flexibility and clarity. The tuple format for specifying fixed/dynamic behavior has been replaced with separate parameters for initial counts and limits.
|
| 389 |
+
|
| 390 |
+
**In Gradio 5.x:**
|
| 391 |
+
- `row_count: int | tuple[int, str]` - Could be an int or tuple like `(5, "fixed")` or `(5, "dynamic")`
|
| 392 |
+
- `col_count: int | tuple[int, str] | None` - Could be an int or tuple like `(3, "fixed")` or `(3, "dynamic")`
|
| 393 |
+
|
| 394 |
+
**In Gradio 6.x:**
|
| 395 |
+
- `row_count: int | None` - Just the initial number of rows to display
|
| 396 |
+
- `row_limits: tuple[int | None, int | None] | None` - Tuple specifying (min_rows, max_rows) constraints
|
| 397 |
+
- `column_count: int | None` - The initial number of columns to display
|
| 398 |
+
- `column_limits: tuple[int | None, int | None] | None` - Tuple specifying (min_columns, max_columns) constraints
|
| 399 |
+
|
| 400 |
+
**Before (Gradio 5.x):**
|
| 401 |
+
|
| 402 |
+
```python
|
| 403 |
+
import gradio as gr
|
| 404 |
+
|
| 405 |
+
# Fixed number of rows (users can't add/remove rows)
|
| 406 |
+
df = gr.Dataframe(row_count=(5, "fixed"), col_count=(3, "dynamic"))
|
| 407 |
+
```
|
| 408 |
+
|
| 409 |
+
Or with dynamic rows:
|
| 410 |
+
|
| 411 |
+
```python
|
| 412 |
+
# Dynamic rows (users can add/remove rows)
|
| 413 |
+
df = gr.Dataframe(row_count=(5, "dynamic"), col_count=(3, "fixed"))
|
| 414 |
+
```
|
| 415 |
+
|
| 416 |
+
Or with just integers (defaults to dynamic):
|
| 417 |
+
|
| 418 |
+
```python
|
| 419 |
+
df = gr.Dataframe(row_count=5, col_count=3)
|
| 420 |
+
```
|
| 421 |
+
|
| 422 |
+
**After (Gradio 6.x):**
|
| 423 |
+
|
| 424 |
+
```python
|
| 425 |
+
import gradio as gr
|
| 426 |
+
|
| 427 |
+
# Fixed number of rows (users can't add/remove rows)
|
| 428 |
+
df = gr.Dataframe(row_count=5, row_limits=(5, 5), column_count=3, column_limits=None)
|
| 429 |
+
```
|
| 430 |
+
|
| 431 |
+
Or with dynamic rows (users can add/remove rows):
|
| 432 |
+
|
| 433 |
+
```python
|
| 434 |
+
# Dynamic rows with no limits
|
| 435 |
+
df = gr.Dataframe(row_count=5, row_limits=None, column_count=3, column_limits=None)
|
| 436 |
+
```
|
| 437 |
|
| 438 |
+
Or with min/max constraints:
|
| 439 |
+
|
| 440 |
+
```python
|
| 441 |
+
# Rows between 3 and 10, columns between 2 and 5
|
| 442 |
+
df = gr.Dataframe(row_count=5, row_limits=(3, 10), column_count=3, column_limits=(2, 5))
|
| 443 |
+
```
|
| 444 |
+
|
| 445 |
+
**Migration examples:**
|
| 446 |
+
|
| 447 |
+
- `row_count=(5, "fixed")` → `row_count=5, row_limits=(5, 5)`
|
| 448 |
+
- `row_count=(5, "dynamic")` → `row_count=5, row_limits=None`
|
| 449 |
+
- `row_count=5` → `row_count=5, row_limits=None` (same behavior)
|
| 450 |
+
- `col_count=(3, "fixed")` → `column_count=3, column_limits=(3, 3)`
|
| 451 |
+
- `col_count=(3, "dynamic")` → `column_count=3, column_limits=None`
|
| 452 |
+
- `col_count=3` → `column_count=3, column_limits=None` (same behavior)
|
| 453 |
|
| 454 |
### `allow_tags=True` is now the default for `gr.Chatbot`
|
| 455 |
|
| 456 |
+
Due to the rise in LLMs returning HTML, markdown tags, and custom tags (such as `<thinking>` tags), the default value of `allow_tags` in `gr.Chatbot` has changed from `False` to `True` in Gradio 6.
|
| 457 |
|
| 458 |
+
**In Gradio 5.x:**
|
| 459 |
+
- `allow_tags=False` was the default
|
| 460 |
+
- All HTML and custom tags were sanitized/removed from chatbot messages (unless explicitly allowed)
|
| 461 |
|
| 462 |
+
**In Gradio 6.x:**
|
| 463 |
+
- `allow_tags=True` is the default
|
| 464 |
+
- All custom tags (non-standard HTML tags) are preserved in chatbot messages
|
| 465 |
+
- Standard HTML tags are still sanitized for security unless `sanitize_html=False`
|
| 466 |
|
| 467 |
+
**Before (Gradio 5.x):**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
+
```python
|
| 470 |
+
import gradio as gr
|
| 471 |
+
|
| 472 |
+
chatbot = gr.Chatbot()
|
| 473 |
+
```
|
| 474 |
+
|
| 475 |
+
This would remove all tags from messages, including custom tags like `<thinking>`.
|
| 476 |
+
|
| 477 |
+
**After (Gradio 6.x):**
|
| 478 |
+
|
| 479 |
+
```python
|
| 480 |
+
import gradio as gr
|
| 481 |
+
|
| 482 |
+
chatbot = gr.Chatbot()
|
| 483 |
+
```
|
| 484 |
+
|
| 485 |
+
This will now preserve custom tags like `<thinking>` in the messages.
|
| 486 |
+
|
| 487 |
+
**To maintain the old behavior:**
|
| 488 |
+
|
| 489 |
+
If you want to continue removing all tags from chatbot messages (the old default behavior), explicitly set `allow_tags=False`:
|
| 490 |
+
|
| 491 |
+
```python
|
| 492 |
+
import gradio as gr
|
| 493 |
+
|
| 494 |
+
chatbot = gr.Chatbot(allow_tags=False)
|
| 495 |
+
```
|
| 496 |
+
|
| 497 |
+
**Note:** You can also specify a list of specific tags to allow:
|
| 498 |
+
|
| 499 |
+
```python
|
| 500 |
+
chatbot = gr.Chatbot(allow_tags=["thinking", "tool_call"])
|
| 501 |
+
```
|
| 502 |
+
|
| 503 |
+
This will only preserve `<thinking>` and `<tool_call>` tags while removing all other custom tags.
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
### Other removed component parameters
|
| 507 |
+
|
| 508 |
+
Several component parameters have been removed in Gradio 6.0. These parameters were previously deprecated and have now been fully removed.
|
| 509 |
+
|
| 510 |
+
#### `gr.Chatbot` removed parameters
|
| 511 |
|
| 512 |
+
**`bubble_full_width`** - This parameter has been removed as it no longer has any effect.
|
|
|
|
| 513 |
|
| 514 |
+
|
| 515 |
+
**`resizeable`** - This parameter (with the typo) has been removed. Use `resizable` instead.
|
| 516 |
+
|
| 517 |
+
**Before (Gradio 5.x):**
|
| 518 |
+
```python
|
| 519 |
+
chatbot = gr.Chatbot(resizeable=True)
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
**After (Gradio 6.x):**
|
| 523 |
+
```python
|
| 524 |
+
chatbot = gr.Chatbot(resizable=True)
|
| 525 |
+
```
|
| 526 |
+
|
| 527 |
+
**`show_copy_button`, `show_copy_all_button`, `show_share_button`** - These parameters have been removed. Use the `buttons` parameter instead.
|
| 528 |
+
|
| 529 |
+
**Before (Gradio 5.x):**
|
| 530 |
+
```python
|
| 531 |
+
chatbot = gr.Chatbot(show_copy_button=True, show_copy_all_button=True, show_share_button=True)
|
| 532 |
+
```
|
| 533 |
+
|
| 534 |
+
**After (Gradio 6.x):**
|
| 535 |
+
```python
|
| 536 |
+
chatbot = gr.Chatbot(buttons=["copy", "copy_all", "share"])
|
| 537 |
+
```
|
| 538 |
+
|
| 539 |
+
#### `gr.Audio` / `WaveformOptions` removed parameters
|
| 540 |
+
|
| 541 |
+
**`show_controls`** - This parameter in `WaveformOptions` has been removed. Use `show_recording_waveform` instead.
|
| 542 |
+
|
| 543 |
+
**Before (Gradio 5.x):**
|
| 544 |
+
```python
|
| 545 |
+
audio = gr.Audio(
|
| 546 |
+
waveform_options=gr.WaveformOptions(show_controls=False)
|
| 547 |
+
)
|
| 548 |
+
```
|
| 549 |
+
|
| 550 |
+
**After (Gradio 6.x):**
|
| 551 |
+
```python
|
| 552 |
+
audio = gr.Audio(
|
| 553 |
+
waveform_options=gr.WaveformOptions(show_recording_waveform=False)
|
| 554 |
+
)
|
| 555 |
+
```
|
| 556 |
+
|
| 557 |
+
**`min_length` and `max_length`** - These parameters have been removed. Use validators instead.
|
| 558 |
+
|
| 559 |
+
**Before (Gradio 5.x):**
|
| 560 |
+
```python
|
| 561 |
+
audio = gr.Audio(min_length=1, max_length=10)
|
| 562 |
+
```
|
| 563 |
+
|
| 564 |
+
**After (Gradio 6.x):**
|
| 565 |
+
```python
|
| 566 |
+
audio = gr.Audio(
|
| 567 |
+
validator=lambda audio: gr.validators.is_audio_correct_length(audio, min_length=1, max_length=10)
|
| 568 |
+
)
|
| 569 |
+
```
|
| 570 |
+
|
| 571 |
+
**`show_download_button`, `show_share_button`** - These parameters have been removed. Use the `buttons` parameter instead.
|
| 572 |
+
|
| 573 |
+
**Before (Gradio 5.x):**
|
| 574 |
+
```python
|
| 575 |
+
audio = gr.Audio(show_download_button=True, show_share_button=True)
|
| 576 |
+
```
|
| 577 |
+
|
| 578 |
+
**After (Gradio 6.x):**
|
| 579 |
+
```python
|
| 580 |
+
audio = gr.Audio(buttons=["download", "share"])
|
| 581 |
+
```
|
| 582 |
+
|
| 583 |
+
**Note:** For components where `show_share_button` had a default of `None` (which would show the button on Spaces), you can use `buttons=["share"]` to always show it, or omit it from the list to hide it.
|
| 584 |
+
|
| 585 |
+
#### `gr.Image` removed parameters
|
| 586 |
+
|
| 587 |
+
**`mirror_webcam`** - This parameter has been removed. Use `webcam_options` with `gr.WebcamOptions` instead.
|
| 588 |
+
|
| 589 |
+
**Before (Gradio 5.x):**
|
| 590 |
+
```python
|
| 591 |
+
image = gr.Image(mirror_webcam=True)
|
| 592 |
+
```
|
| 593 |
+
|
| 594 |
+
**After (Gradio 6.x):**
|
| 595 |
+
```python
|
| 596 |
+
image = gr.Image(webcam_options=gr.WebcamOptions(mirror=True))
|
| 597 |
+
```
|
| 598 |
+
|
| 599 |
+
**`webcam_constraints`** - This parameter has been removed. Use `webcam_options` with `gr.WebcamOptions` instead.
|
| 600 |
+
|
| 601 |
+
**Before (Gradio 5.x):**
|
| 602 |
+
```python
|
| 603 |
+
image = gr.Image(webcam_constraints={"facingMode": "user"})
|
| 604 |
+
```
|
| 605 |
+
|
| 606 |
+
**After (Gradio 6.x):**
|
| 607 |
+
```python
|
| 608 |
+
image = gr.Image(webcam_options=gr.WebcamOptions(constraints={"facingMode": "user"}))
|
| 609 |
+
```
|
| 610 |
+
|
| 611 |
+
**`show_download_button`, `show_share_button`, `show_fullscreen_button`** - These parameters have been removed. Use the `buttons` parameter instead.
|
| 612 |
+
|
| 613 |
+
**Before (Gradio 5.x):**
|
| 614 |
+
```python
|
| 615 |
+
image = gr.Image(show_download_button=True, show_share_button=True, show_fullscreen_button=True)
|
| 616 |
+
```
|
| 617 |
+
|
| 618 |
+
**After (Gradio 6.x):**
|
| 619 |
+
```python
|
| 620 |
+
image = gr.Image(buttons=["download", "share", "fullscreen"])
|
| 621 |
+
```
|
| 622 |
+
|
| 623 |
+
#### `gr.Video` removed parameters
|
| 624 |
+
|
| 625 |
+
**`mirror_webcam`** - This parameter has been removed. Use `webcam_options` with `gr.WebcamOptions` instead.
|
| 626 |
+
|
| 627 |
+
**Before (Gradio 5.x):**
|
| 628 |
+
```python
|
| 629 |
+
video = gr.Video(mirror_webcam=True)
|
| 630 |
+
```
|
| 631 |
+
|
| 632 |
+
**After (Gradio 6.x):**
|
| 633 |
+
```python
|
| 634 |
+
video = gr.Video(webcam_options=gr.WebcamOptions(mirror=True))
|
| 635 |
+
```
|
| 636 |
+
|
| 637 |
+
**`webcam_constraints`** - This parameter has been removed. Use `webcam_options` with `gr.WebcamOptions` instead.
|
| 638 |
+
|
| 639 |
+
**Before (Gradio 5.x):**
|
| 640 |
+
```python
|
| 641 |
+
video = gr.Video(webcam_constraints={"facingMode": "user"})
|
| 642 |
+
```
|
| 643 |
+
|
| 644 |
+
**After (Gradio 6.x):**
|
| 645 |
+
```python
|
| 646 |
+
video = gr.Video(webcam_options=gr.WebcamOptions(constraints={"facingMode": "user"}))
|
| 647 |
+
```
|
| 648 |
+
|
| 649 |
+
**`min_length` and `max_length`** - These parameters have been removed. Use validators instead.
|
| 650 |
+
|
| 651 |
+
**Before (Gradio 5.x):**
|
| 652 |
+
```python
|
| 653 |
+
video = gr.Video(min_length=1, max_length=10)
|
| 654 |
+
```
|
| 655 |
+
|
| 656 |
+
**After (Gradio 6.x):**
|
| 657 |
+
```python
|
| 658 |
+
video = gr.Video(
|
| 659 |
+
validator=lambda video: gr.validators.is_video_correct_length(video, min_length=1, max_length=10)
|
| 660 |
+
)
|
| 661 |
+
```
|
| 662 |
+
|
| 663 |
+
**`show_download_button`, `show_share_button`** - These parameters have been removed. Use the `buttons` parameter instead.
|
| 664 |
+
|
| 665 |
+
**Before (Gradio 5.x):**
|
| 666 |
+
```python
|
| 667 |
+
video = gr.Video(show_download_button=True, show_share_button=True)
|
| 668 |
+
```
|
| 669 |
+
|
| 670 |
+
**After (Gradio 6.x):**
|
| 671 |
+
```python
|
| 672 |
+
video = gr.Video(buttons=["download", "share"])
|
| 673 |
+
```
|
| 674 |
+
|
| 675 |
+
#### `gr.ImageEditor` removed parameters
|
| 676 |
+
|
| 677 |
+
**`crop_size`** - This parameter has been removed. Use `canvas_size` instead.
|
| 678 |
+
|
| 679 |
+
**Before (Gradio 5.x):**
|
| 680 |
+
```python
|
| 681 |
+
editor = gr.ImageEditor(crop_size=(512, 512))
|
| 682 |
+
```
|
| 683 |
+
|
| 684 |
+
**After (Gradio 6.x):**
|
| 685 |
+
```python
|
| 686 |
+
editor = gr.ImageEditor(canvas_size=(512, 512))
|
| 687 |
+
```
|
| 688 |
+
|
| 689 |
+
#### Removed components
|
| 690 |
+
|
| 691 |
+
**`gr.LogoutButton`** - This component has been removed. Use `gr.LoginButton` instead, which handles both login and logout processes.
|
| 692 |
+
|
| 693 |
+
**Before (Gradio 5.x):**
|
| 694 |
+
```python
|
| 695 |
+
logout_btn = gr.LogoutButton()
|
| 696 |
+
```
|
| 697 |
+
|
| 698 |
+
**After (Gradio 6.x):**
|
| 699 |
+
```python
|
| 700 |
+
login_btn = gr.LoginButton()
|
| 701 |
+
```
|
| 702 |
+
|
| 703 |
+
#### Native plot components removed parameters
|
| 704 |
+
|
| 705 |
+
The following parameters have been removed from `gr.LinePlot`, `gr.BarPlot`, and `gr.ScatterPlot`:
|
| 706 |
+
|
| 707 |
+
- `overlay_point` - This parameter has been removed.
|
| 708 |
+
- `width` - This parameter has been removed. Use CSS styling or container width instead.
|
| 709 |
+
- `stroke_dash` - This parameter has been removed.
|
| 710 |
+
- `interactive` - This parameter has been removed.
|
| 711 |
+
- `show_actions_button` - This parameter has been removed.
|
| 712 |
+
- `color_legend_title` - This parameter has been removed. Use `color_title` instead.
|
| 713 |
+
- `show_fullscreen_button`, `show_export_button` - These parameters have been removed. Use the `buttons` parameter instead.
|
| 714 |
+
|
| 715 |
+
**Before (Gradio 5.x):**
|
| 716 |
+
```python
|
| 717 |
+
plot = gr.LinePlot(
|
| 718 |
+
value=data,
|
| 719 |
+
x="date",
|
| 720 |
+
y="downloads",
|
| 721 |
+
overlay_point=True,
|
| 722 |
+
width=900,
|
| 723 |
+
show_fullscreen_button=True,
|
| 724 |
+
show_export_button=True
|
| 725 |
+
)
|
| 726 |
+
```
|
| 727 |
+
|
| 728 |
+
**After (Gradio 6.x):**
|
| 729 |
+
```python
|
| 730 |
+
plot = gr.LinePlot(
|
| 731 |
+
value=data,
|
| 732 |
+
x="date",
|
| 733 |
+
y="downloads",
|
| 734 |
+
buttons=["fullscreen", "export"]
|
| 735 |
+
)
|
| 736 |
+
```
|
| 737 |
+
|
| 738 |
+
**Note:** For `color_legend_title`, use `color_title` instead:
|
| 739 |
+
|
| 740 |
+
**Before (Gradio 5.x):**
|
| 741 |
+
```python
|
| 742 |
+
plot = gr.ScatterPlot(color_legend_title="Category")
|
| 743 |
+
```
|
| 744 |
+
|
| 745 |
+
**After (Gradio 6.x):**
|
| 746 |
+
```python
|
| 747 |
+
plot = gr.ScatterPlot(color_title="Category")
|
| 748 |
+
```
|
| 749 |
+
|
| 750 |
+
#### `gr.Textbox` removed parameters
|
| 751 |
+
|
| 752 |
+
**`show_copy_button`** - This parameter has been removed. Use the `buttons` parameter instead.
|
| 753 |
+
|
| 754 |
+
**Before (Gradio 5.x):**
|
| 755 |
+
```python
|
| 756 |
+
text = gr.Textbox(show_copy_button=True)
|
| 757 |
+
```
|
| 758 |
+
|
| 759 |
+
**After (Gradio 6.x):**
|
| 760 |
+
```python
|
| 761 |
+
text = gr.Textbox(buttons=["copy"])
|
| 762 |
+
```
|
| 763 |
+
|
| 764 |
+
#### `gr.Markdown` removed parameters
|
| 765 |
+
|
| 766 |
+
**`show_copy_button`** - This parameter has been removed. Use the `buttons` parameter instead.
|
| 767 |
+
|
| 768 |
+
**Before (Gradio 5.x):**
|
| 769 |
+
```python
|
| 770 |
+
markdown = gr.Markdown(show_copy_button=True)
|
| 771 |
+
```
|
| 772 |
+
|
| 773 |
+
**After (Gradio 6.x):**
|
| 774 |
+
```python
|
| 775 |
+
markdown = gr.Markdown(buttons=["copy"])
|
| 776 |
+
```
|
| 777 |
+
|
| 778 |
+
#### `gr.Dataframe` removed parameters
|
| 779 |
+
|
| 780 |
+
**`show_copy_button`, `show_fullscreen_button`** - These parameters have been removed. Use the `buttons` parameter instead.
|
| 781 |
+
|
| 782 |
+
**Before (Gradio 5.x):**
|
| 783 |
+
```python
|
| 784 |
+
df = gr.Dataframe(show_copy_button=True, show_fullscreen_button=True)
|
| 785 |
+
```
|
| 786 |
+
|
| 787 |
+
**After (Gradio 6.x):**
|
| 788 |
+
```python
|
| 789 |
+
df = gr.Dataframe(buttons=["copy", "fullscreen"])
|
| 790 |
+
```
|
| 791 |
+
|
| 792 |
+
#### `gr.Slider` removed parameters
|
| 793 |
+
|
| 794 |
+
**`show_reset_button`** - This parameter has been removed. Use the `buttons` parameter instead.
|
| 795 |
+
|
| 796 |
+
**Before (Gradio 5.x):**
|
| 797 |
+
```python
|
| 798 |
+
slider = gr.Slider(show_reset_button=True)
|
| 799 |
+
```
|
| 800 |
+
|
| 801 |
+
**After (Gradio 6.x):**
|
| 802 |
+
```python
|
| 803 |
+
slider = gr.Slider(buttons=["reset"])
|
| 804 |
+
```
|
| 805 |
|
| 806 |
## Python Client Changes
|
| 807 |
|
| 808 |
### `hf_token` parameter renamed to `token` in `Client`
|
| 809 |
+
|
| 810 |
+
The `hf_token` parameter in the `Client` class has been renamed to `token` for consistency and simplicity.
|
| 811 |
+
|
| 812 |
+
**Before (Gradio 5.x):**
|
| 813 |
+
|
| 814 |
+
```python
|
| 815 |
+
from gradio_client import Client
|
| 816 |
+
|
| 817 |
+
client = Client("abidlabs/my-private-space", hf_token="hf_...")
|
| 818 |
+
```
|
| 819 |
+
|
| 820 |
+
**After (Gradio 6.x):**
|
| 821 |
+
|
| 822 |
+
```python
|
| 823 |
+
from gradio_client import Client
|
| 824 |
+
|
| 825 |
+
client = Client("abidlabs/my-private-space", token="hf_...")
|
| 826 |
+
```
|
| 827 |
|
| 828 |
### `deploy_discord` method deprecated
|
|
|
|
| 829 |
|
| 830 |
+
The `deploy_discord` method in the `Client` class has been deprecated and will be removed in Gradio 6.0. This method was used to deploy Gradio apps as Discord bots.
|
| 831 |
+
|
| 832 |
+
**Before (Gradio 5.x):**
|
| 833 |
+
|
| 834 |
+
```python
|
| 835 |
+
from gradio_client import Client
|
| 836 |
+
|
| 837 |
+
client = Client("username/space-name")
|
| 838 |
+
client.deploy_discord(discord_bot_token="...")
|
| 839 |
+
```
|
| 840 |
+
|
| 841 |
+
**After (Gradio 6.x):**
|
| 842 |
+
|
| 843 |
+
The `deploy_discord` method is no longer available. Please see the [documentation on creating a Discord bot with Gradio](https://www.gradio.app/guides/creating-a-discord-bot-from-a-gradio-app) for alternative approaches.
|
| 844 |
+
|
| 845 |
+
### `AppError` now subclasses `Exception` instead of `ValueError`
|
| 846 |
+
|
| 847 |
+
The `AppError` exception class in the Python client now subclasses `Exception` directly instead of `ValueError`. This is a breaking change if you have code that specifically catches `ValueError` to handle `AppError` instances.
|
| 848 |
+
|
| 849 |
+
**Before (Gradio 5.x):**
|
| 850 |
+
|
| 851 |
+
```python
|
| 852 |
+
from gradio_client import Client
|
| 853 |
+
from gradio_client.exceptions import AppError
|
| 854 |
+
|
| 855 |
+
try:
|
| 856 |
+
client = Client("username/space-name")
|
| 857 |
+
result = client.predict("/predict", inputs)
|
| 858 |
+
except ValueError as e:
|
| 859 |
+
# This would catch AppError in Gradio 5.x
|
| 860 |
+
print(f"Error: {e}")
|
| 861 |
+
```
|
| 862 |
+
|
| 863 |
+
**After (Gradio 6.x):**
|
| 864 |
+
|
| 865 |
+
```python
|
| 866 |
+
from gradio_client import Client
|
| 867 |
+
from gradio_client.exceptions import AppError
|
| 868 |
+
|
| 869 |
+
try:
|
| 870 |
+
client = Client("username/space-name")
|
| 871 |
+
result = client.predict("/predict", inputs)
|
| 872 |
+
except AppError as e:
|
| 873 |
+
# Explicitly catch AppError
|
| 874 |
+
print(f"App error: {e}")
|
| 875 |
+
except ValueError as e:
|
| 876 |
+
# This will no longer catch AppError
|
| 877 |
+
print(f"Value error: {e}")
|
| 878 |
+
```
|