Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated parameters and classes for the 5.0 release #8797

Merged
merged 23 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-bears-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": major
---

feat:Deprecate for 5.0
26 changes: 0 additions & 26 deletions client/python/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,32 +238,6 @@ def show(n):
return demo


@pytest.fixture
def count_generator_demo_exception():
def count(n):
for i in range(int(n)):
time.sleep(0.01)
if i == 5:
raise ValueError("Oh no!")
yield i

def show(n):
return str(list(range(int(n))))

with gr.Blocks() as demo:
with gr.Column():
num = gr.Number(value=10)
with gr.Row():
count_btn = gr.Button("Count")
count_forever = gr.Button("Count forever")
with gr.Column():
out = gr.Textbox()

count_btn.click(count, num, out, api_name="count")
count_forever.click(show, num, out, api_name="count_forever", every=3)
return demo


@pytest.fixture
def file_io_demo():
demo = gr.Interface(
Expand Down
17 changes: 1 addition & 16 deletions client/python/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from gradio_client import Client, handle_file
from gradio_client.client import DEFAULT_TEMP_DIR
from gradio_client.exceptions import AppError, AuthenticationError
from gradio_client.exceptions import AuthenticationError
from gradio_client.utils import (
Communicator,
ProgressUnit,
Expand Down Expand Up @@ -1391,18 +1391,3 @@ def test_add_secrets(self, mock_time, mock_init, mock_duplicate, mock_add_secret
"test_value2",
token=HF_TOKEN,
)


def test_upstream_exceptions(count_generator_demo_exception):
with connect(count_generator_demo_exception, show_error=True) as client:
with pytest.raises(
AppError, match="The upstream Gradio app has raised an exception: Oh no!"
):
client.predict(7, api_name="/count")

with connect(count_generator_demo_exception) as client:
with pytest.raises(
AppError,
match="The upstream Gradio app has raised an exception but has not enabled verbose error reporting.",
):
client.predict(7, api_name="/count")
2 changes: 1 addition & 1 deletion demo/file_explorer_component_events/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: file_explorer_component_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('dir1')\n", "!wget -q -O dir1/bar.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/bar.txt\n", "!wget -q -O dir1/foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/foo.txt\n", "os.mkdir('dir2')\n", "!wget -q -O dir2/baz.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/baz.png\n", "!wget -q -O dir2/foo.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/foo.png\n", "os.mkdir('dir3')\n", "!wget -q -O dir3/dir3_bar.log https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir3_bar.log\n", "!wget -q -O dir3/dir3_foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir3_foo.txt\n", "!wget -q -O dir3/dir4 https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir4"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "base_root = Path(__file__).parent.resolve()\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " dd = gr.Dropdown(label=\"Select File Explorer Root\",\n", " value=str(base_root / \"dir1\"),\n", " choices=[str(base_root / \"dir1\"), str(base_root / \"dir2\"),\n", " str(base_root / \"dir3\")])\n", " with gr.Group():\n", " txt_only_glob = gr.Checkbox(label=\"Show only text files\", value=False)\n", " ignore_txt_in_glob = gr.Checkbox(label=\"Ignore text files in glob\", value=False)\n", "\n", " fe = gr.FileExplorer(root_dir=str(base_root / \"dir1\"),\n", " glob=\"**/*\", interactive=True)\n", " textbox = gr.Textbox(label=\"Selected Directory\")\n", " run = gr.Button(\"Run\")\n", " total_changes = gr.Number(0, elem_id=\"total-changes\")\n", " \n", " txt_only_glob.select(lambda s: gr.FileExplorer(glob=\"*.txt\" if s else \"*\") ,\n", " inputs=[txt_only_glob], outputs=[fe])\n", " ignore_txt_in_glob.select(lambda s: gr.FileExplorer(ignore_glob=\"*.txt\" if s else None),\n", " inputs=[ignore_txt_in_glob], outputs=[fe]) \n", "\n", " dd.select(lambda s: gr.FileExplorer(root=s), inputs=[dd], outputs=[fe])\n", " run.click(lambda s: \",\".join(s) if isinstance(s, list) else s, inputs=[fe], outputs=[textbox])\n", " fe.change(lambda num: num + 1, inputs=total_changes, outputs=total_changes)\n", "\n", " with gr.Row():\n", " a = gr.Textbox(elem_id=\"input-box\")\n", " a.change(lambda x: x, inputs=[a])\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: file_explorer_component_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('dir1')\n", "!wget -q -O dir1/bar.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/bar.txt\n", "!wget -q -O dir1/foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/foo.txt\n", "os.mkdir('dir2')\n", "!wget -q -O dir2/baz.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/baz.png\n", "!wget -q -O dir2/foo.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/foo.png\n", "os.mkdir('dir3')\n", "!wget -q -O dir3/dir3_bar.log https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir3_bar.log\n", "!wget -q -O dir3/dir3_foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir3_foo.txt\n", "!wget -q -O dir3/dir4 https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir4"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "base_root = Path(__file__).parent.resolve()\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " dd = gr.Dropdown(label=\"Select File Explorer Root\",\n", " value=str(base_root / \"dir1\"),\n", " choices=[str(base_root / \"dir1\"), str(base_root / \"dir2\"),\n", " str(base_root / \"dir3\")])\n", " with gr.Group():\n", " txt_only_glob = gr.Checkbox(label=\"Show only text files\", value=False)\n", " ignore_txt_in_glob = gr.Checkbox(label=\"Ignore text files in glob\", value=False)\n", "\n", " fe = gr.FileExplorer(root_dir=str(base_root / \"dir1\"),\n", " glob=\"**/*\", interactive=True)\n", " textbox = gr.Textbox(label=\"Selected Directory\")\n", " run = gr.Button(\"Run\")\n", " total_changes = gr.Number(0, elem_id=\"total-changes\")\n", " \n", " txt_only_glob.select(lambda s: gr.FileExplorer(glob=\"*.txt\" if s else \"*\") ,\n", " inputs=[txt_only_glob], outputs=[fe])\n", " ignore_txt_in_glob.select(lambda s: gr.FileExplorer(ignore_glob=\"*.txt\" if s else None),\n", " inputs=[ignore_txt_in_glob], outputs=[fe]) \n", "\n", " dd.select(lambda s: gr.FileExplorer(root_dir=s), inputs=[dd], outputs=[fe])\n", " run.click(lambda s: \",\".join(s) if isinstance(s, list) else s, inputs=[fe], outputs=[textbox])\n", " fe.change(lambda num: num + 1, inputs=total_changes, outputs=total_changes)\n", "\n", " with gr.Row():\n", " a = gr.Textbox(elem_id=\"input-box\")\n", " a.change(lambda x: x, inputs=[a])\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
2 changes: 1 addition & 1 deletion demo/file_explorer_component_events/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ignore_txt_in_glob.select(lambda s: gr.FileExplorer(ignore_glob="*.txt" if s else None),
inputs=[ignore_txt_in_glob], outputs=[fe])

dd.select(lambda s: gr.FileExplorer(root=s), inputs=[dd], outputs=[fe])
dd.select(lambda s: gr.FileExplorer(root_dir=s), inputs=[dd], outputs=[fe])
run.click(lambda s: ",".join(s) if isinstance(s, list) else s, inputs=[fe], outputs=[textbox])
fe.change(lambda num: num + 1, inputs=total_changes, outputs=total_changes)

Expand Down
1 change: 0 additions & 1 deletion demo/logoutbutton_component/requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion demo/logoutbutton_component/run.ipynb

This file was deleted.

6 changes: 0 additions & 6 deletions demo/logoutbutton_component/run.py

This file was deleted.

2 changes: 0 additions & 2 deletions gradio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
Label,
LinePlot,
LoginButton,
LogoutButton,
Markdown,
MessageDict,
Model3D,
Expand Down Expand Up @@ -77,7 +76,6 @@
from gradio.flagging import (
CSVLogger,
FlaggingCallback,
HuggingFaceDatasetSaver,
SimpleCSVLogger,
)
from gradio.helpers import (
Expand Down
9 changes: 1 addition & 8 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,7 @@ def __repr__(self):
def expects_oauth(self):
"""Return whether the app expects user to authenticate via OAuth."""
return any(
isinstance(block, (components.LoginButton, components.LogoutButton))
for block in self.blocks.values()
isinstance(block, components.LoginButton) for block in self.blocks.values()
)

def unload(self, fn: Callable):
Expand Down Expand Up @@ -2064,7 +2063,6 @@ def queue(
status_update_rate: float | Literal["auto"] = "auto",
api_open: bool | None = None,
max_size: int | None = None,
concurrency_count: int | None = None,
*,
default_concurrency_limit: int | None | Literal["not_set"] = "not_set",
):
Expand All @@ -2074,7 +2072,6 @@ def queue(
status_update_rate: If "auto", Queue will send status estimations to all clients whenever a job is finished. Otherwise Queue will send status at regular intervals set by this parameter as the number of seconds.
api_open: If True, the REST routes of the backend will be open, allowing requests made directly to those endpoints to skip the queue.
max_size: The maximum number of events the queue will store at any given moment. If the queue is full, new events will not be added and a user will receive a message saying that the queue is full. If None, the queue size will be unlimited.
concurrency_count: Deprecated. Set the concurrency_limit directly on event listeners e.g. btn.click(fn, ..., concurrency_limit=10) or gr.Interface(concurrency_limit=10). If necessary, the total number of workers can be configured via `max_threads` in launch().
default_concurrency_limit: The default value of `concurrency_limit` to use for event listeners that don't specify a value. Can be set by environment variable GRADIO_DEFAULT_CONCURRENCY_LIMIT. Defaults to 1 if not set otherwise.
Example: (Blocks)
with gr.Blocks() as demo:
Expand All @@ -2087,10 +2084,6 @@ def queue(
demo.queue(max_size=20)
demo.launch()
"""
if concurrency_count:
raise DeprecationWarning(
"concurrency_count has been deprecated. Set the concurrency_limit directly on event listeners e.g. btn.click(fn, ..., concurrency_limit=10) or gr.Interface(concurrency_limit=10). If necessary, the total number of workers can be configured via `max_threads` in launch()."
)
if api_open is not None:
self.api_open = api_open
if utils.is_zero_gpu_space():
Expand Down
9 changes: 0 additions & 9 deletions gradio/chat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def __init__(
chatbot: Chatbot | None = None,
textbox: Textbox | MultimodalTextbox | None = None,
additional_inputs: str | Component | list[str | Component] | None = None,
additional_inputs_accordion_name: str | None = None,
additional_inputs_accordion: str | Accordion | None = None,
examples: list[str] | list[dict[str, str | list]] | list[list] | None = None,
cache_examples: bool | Literal["lazy"] | None = None,
Expand Down Expand Up @@ -94,7 +93,6 @@ def __init__(
chatbot: An instance of the gr.Chatbot component to use for the chat interface, if you would like to customize the chatbot properties. If not provided, a default gr.Chatbot component will be created.
textbox: An instance of the gr.Textbox or gr.MultimodalTextbox component to use for the chat interface, if you would like to customize the textbox properties. If not provided, a default gr.Textbox or gr.MultimodalTextbox component will be created.
additional_inputs: An instance or list of instances of gradio components (or their string shortcuts) to use as additional inputs to the chatbot. If components are not already rendered in a surrounding Blocks, then the components will be displayed under the chatbot, in an accordion.
additional_inputs_accordion_name: Deprecated. Will be removed in a future version of Gradio. Use the `additional_inputs_accordion` parameter instead.
additional_inputs_accordion: If a string is provided, this is the label of the `gr.Accordion` to use to contain additional inputs. A `gr.Accordion` object can be provided as well to configure other properties of the container holding the additional inputs. Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This parameter is only used if `additional_inputs` is provided.
examples: Sample inputs for the function; if provided, appear below the chatbot and can be clicked to populate the chatbot input. Should be a list of strings if `multimodal` is False, and a list of dictionaries (with keys `text` and `files`) if `multimodal` is True.
cache_examples: If True, caches examples in the server for fast runtime in examples. The default option in HuggingFace Spaces is True. The default option elsewhere is False.
Expand Down Expand Up @@ -152,13 +150,6 @@ def __init__(
]
else:
self.additional_inputs = []
if additional_inputs_accordion_name is not None:
print(
"The `additional_inputs_accordion_name` parameter is deprecated and will be removed in a future version of Gradio. Use the `additional_inputs_accordion` parameter instead."
)
self.additional_inputs_accordion_params = {
"label": additional_inputs_accordion_name
}
if additional_inputs_accordion is None:
self.additional_inputs_accordion_params = {
"label": "Additional Inputs",
Expand Down
5 changes: 4 additions & 1 deletion gradio/cli/commands/components/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"FormComponent",
"Fallback",
"State",
"LogoutButton",
}

_BEGINNER_FRIENDLY = {"Slider", "Radio", "Checkbox", "Number", "CheckboxGroup", "File"}
Expand All @@ -34,10 +35,12 @@
def _get_table_items(module):
items = []
for name in module.__all__:
if name in _IGNORE:
continue
gr_cls = getattr(module, name)
if not (
inspect.isclass(gr_cls) and issubclass(gr_cls, (Component, BlockContext))
) or (name in _IGNORE):
):
continue
tags = []
if "Simple" in name or name in _BEGINNER_FRIENDLY:
Expand Down
1 change: 0 additions & 1 deletion gradio/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from gradio.components.label import Label
from gradio.components.line_plot import LinePlot
from gradio.components.login_button import LoginButton
from gradio.components.logout_button import LogoutButton
from gradio.components.markdown import Markdown
from gradio.components.model3d import Model3D
from gradio.components.multimodal_textbox import MultimodalTextbox
Expand Down
8 changes: 0 additions & 8 deletions gradio/components/file_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import fnmatch
import os
import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, List, Literal

Expand Down Expand Up @@ -55,7 +54,6 @@ def __init__(
elem_classes: list[str] | str | None = None,
render: bool = True,
key: int | str | None = None,
root: None = None,
):
"""
Parameters:
Expand All @@ -79,12 +77,6 @@ def __init__(
render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.
"""
if root is not None:
warnings.warn(
"The `root` parameter has been deprecated. Please use `root_dir` instead."
)
root_dir = root
self._constructor_args[0]["root_dir"] = root
self.root_dir = os.path.abspath(root_dir)
self.glob = glob
self.ignore_glob = ignore_glob
Expand Down
5 changes: 0 additions & 5 deletions gradio/components/login_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ def __init__(
key: int | str | None = None,
scale: int | None = 0,
min_width: int | None = None,
signed_in_value: str = "Signed in as {}",
):
"""
Parameters:
logout_value: The text to display when the user is signed in. The string should contain a placeholder for the username with a call-to-action to logout, e.g. "Logout ({})".
"""
if signed_in_value != "Signed in as {}":
warnings.warn(
"The `signed_in_value` parameter is deprecated. Please use `logout_value` instead."
)
self.logout_value = logout_value
super().__init__(
value,
Expand Down
Loading