Skip to content

Commit

Permalink
Merge branch '5.0-dev' into send-stream-data-queue-ready
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton authored Aug 19, 2024
2 parents d65e75e + c054ec8 commit a90ff07
Show file tree
Hide file tree
Showing 110 changed files with 559 additions and 440 deletions.
6 changes: 6 additions & 0 deletions .changeset/chubby-hairs-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gradio": minor
"gradio_client": minor
---

feat:Drop python 3.8 and 3.9
5 changes: 5 additions & 0 deletions .changeset/deep-ways-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Postprocess hardening
5 changes: 5 additions & 0 deletions .changeset/salty-vans-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Deprecate passing a tuple for gr.Code value
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
always_install_pnpm: true
python_version: "3.10"
skip_build: "false"
- name: Build packages
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/storybook-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
- name: install dependencies
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
python_version: "3.10"
always_install_pnpm: true
skip_build: "true"
- name: build client
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-functional-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
always_install_pnpm: true
build_lite: true
skip_build: true
python_version: "3.10"
test: true
- run: pnpm exec playwright install chromium firefox
- name: Run Lite E2E tests
run: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ jobs:
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
always_install_pnpm: true
- name: install outbreak_forecast dependencies
python_version: "3.10"
test: true
- name: install dependencies for specific tests
run: |
. venv/bin/activate
python -m pip install -r demo/outbreak_forecast/requirements.txt
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/website-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
with:
always_install_pnpm: true
skip_build: true
python_version: "3.10"
- name: build client
run: pnpm --filter @gradio/client build

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/website-docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ jobs:
- name: install dependencies
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
python_version: "3.10"
skip_build: true
test: true

# generated when installing deps
- name: upload website json artifacts
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ More than 200 awesome developers have contributed to the `gradio` library, and w

Prerequisites:

- [Python 3.8+](https://www.python.org/downloads/)
- [Python 3.10+](https://www.python.org/downloads/)
- [Node.js v16.14+](https://nodejs.dev/en/download/package-manager/) (only needed if you are making changes to the frontend)
- [pnpm 8.1+](https://pnpm.io/8.x/installation) (only needed if you are making changes to the frontend)

Expand Down
5 changes: 2 additions & 3 deletions client/python/gradio_client/cli/deploy_discord.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List, Optional
from typing import Annotated, Optional

from typer import Option
from typing_extensions import Annotated

from gradio_client import Client

Expand All @@ -17,7 +16,7 @@ def main(
str, Option(help="Discord bot token. Get one on the discord website.")
] = None,
api_names: Annotated[
List[str], Option(help="Api names to turn into discord bots")
list[str], Option(help="Api names to turn into discord bots")
] = None,
to_id: Annotated[
Optional[str], Option(help="Name of the space used to host the discord bot")
Expand Down
9 changes: 7 additions & 2 deletions client/python/gradio_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import urllib.parse
import uuid
import warnings
from collections.abc import Callable
from concurrent.futures import Future
from dataclasses import dataclass
from datetime import datetime
from functools import partial
from pathlib import Path
from threading import Lock
from typing import Any, Callable, Literal
from typing import Any, Literal

import httpx
import huggingface_hub
Expand Down Expand Up @@ -1303,7 +1304,11 @@ def download_files(self, *data) -> tuple:

def remove_skipped_components(self, *data) -> tuple:
""""""
data = [d for d, oct in zip(data, self.output_component_types) if not oct.skip]
data = [
d
for d, oct in zip(data, self.output_component_types, strict=False)
if not oct.skip
]
return tuple(data)

def reduce_singleton_output(self, *data) -> Any:
Expand Down
12 changes: 7 additions & 5 deletions client/python/gradio_client/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _upload(
"orig_name": Path(f).name,
"data": None,
}
for f, o in zip(fs, output)
for f, o in zip(fs, output, strict=False)
]
else:
o = next(o for ix, o in enumerate(result) if indices[ix] == i)
Expand Down Expand Up @@ -207,7 +207,7 @@ def insert_state(self, *data) -> tuple:
def remove_skipped_components(self, *data) -> tuple:
data = [
d
for d, oct in zip(data, self.output_component_types)
for d, oct in zip(data, self.output_component_types, strict=False)
if oct not in utils.SKIP_COMPONENTS
]
return tuple(data)
Expand Down Expand Up @@ -235,13 +235,15 @@ def serialize(self, *data) -> tuple:

files = [
f
for f, t in zip(data, self.input_component_types)
for f, t in zip(data, self.input_component_types, strict=False)
if t in ["file", "uploadbutton"]
]
uploaded_files = self._upload(files)
data = list(data)
self._add_uploaded_files_to_data(uploaded_files, data)
o = tuple([s.serialize(d) for s, d in zip(self.serializers, data)])
o = tuple(
[s.serialize(d) for s, d in zip(self.serializers, data, strict=False)]
)
return o

def deserialize(self, *data) -> tuple:
Expand All @@ -257,7 +259,7 @@ def deserialize(self, *data) -> tuple:
hf_token=self.client.hf_token,
root_url=self.root_url,
)
for s, d in zip(self.deserializers, data)
for s, d in zip(self.deserializers, data, strict=False)
]
)
return outputs
Expand Down
2 changes: 1 addition & 1 deletion client/python/gradio_client/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import inspect
import warnings
from collections import defaultdict
from collections.abc import Callable
from functools import lru_cache
from typing import Callable

classes_to_document = defaultdict(list)
classes_inherit_documentation = {}
Expand Down
3 changes: 2 additions & 1 deletion client/python/gradio_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import tempfile
import time
import warnings
from collections.abc import Callable, Coroutine
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from pathlib import Path
from threading import Lock
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Literal, Optional, TypedDict
from typing import TYPE_CHECKING, Any, Literal, Optional, TypedDict

import fsspec.asyn
import httpx
Expand Down
2 changes: 1 addition & 1 deletion client/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "gradio_client"
dynamic = ["version", "dependencies", "readme"]
description = "Python library for easily interacting with trained machine learning models"
license = "Apache-2.0"
requires-python = ">=3.8"
requires-python = ">=3.10"
authors = [
{ name = "Abubakar Abid", email = "gradio-team@huggingface.co" },
{ name = "Ali Abid", email = "gradio-team@huggingface.co" },
Expand Down
2 changes: 1 addition & 1 deletion demo/code/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: code"]}, {"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", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/code/file.css"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "from time import sleep\n", "\n", "css_file = os.path.join(os.path.abspath(''), \"file.css\")\n", "\n", "def set_lang(language):\n", " print(language)\n", " return gr.Code(language=language)\n", "\n", "def set_lang_from_path():\n", " sleep(1)\n", " return gr.Code((css_file,), language=\"css\")\n", "\n", "def code(language, code):\n", " return gr.Code(code, language=language)\n", "\n", "io = gr.Interface(lambda x: x, \"code\", \"code\")\n", "\n", "with gr.Blocks() as demo:\n", " lang = gr.Dropdown(value=\"python\", choices=gr.Code.languages)\n", " with gr.Row():\n", " code_in = gr.Code(\n", " language=\"python\",\n", " label=\"Input\",\n", " value='def all_odd_elements(sequence):\\n \"\"\"Returns every odd element of the sequence.\"\"\"',\n", " )\n", " code_out = gr.Code(label=\"Output\")\n", " btn = gr.Button(\"Run\")\n", " btn_two = gr.Button(\"Load File\")\n", "\n", " lang.change(set_lang, inputs=lang, outputs=code_in)\n", " btn.click(code, inputs=[lang, code_in], outputs=code_out)\n", " btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)\n", " io.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: code"]}, {"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", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/code/file.css"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "from time import sleep\n", "\n", "css_file = os.path.join(os.path.abspath(''), \"file.css\")\n", "\n", "def set_lang(language):\n", " print(language)\n", " return gr.Code(language=language)\n", "\n", "def set_lang_from_path():\n", " sleep(1)\n", " return gr.Code(open(css_file).read(), language=\"css\")\n", "\n", "def code(language, code):\n", " return gr.Code(code, language=language)\n", "\n", "io = gr.Interface(lambda x: x, \"code\", \"code\")\n", "\n", "with gr.Blocks() as demo:\n", " lang = gr.Dropdown(value=\"python\", choices=gr.Code.languages)\n", " with gr.Row():\n", " code_in = gr.Code(\n", " language=\"python\",\n", " label=\"Input\",\n", " value='def all_odd_elements(sequence):\\n \"\"\"Returns every odd element of the sequence.\"\"\"',\n", " )\n", " code_out = gr.Code(label=\"Output\")\n", " btn = gr.Button(\"Run\")\n", " btn_two = gr.Button(\"Load File\")\n", "\n", " lang.change(set_lang, inputs=lang, outputs=code_in)\n", " btn.click(code, inputs=[lang, code_in], outputs=code_out)\n", " btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)\n", " io.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
2 changes: 1 addition & 1 deletion demo/code/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def set_lang(language):

def set_lang_from_path():
sleep(1)
return gr.Code((css_file,), language="css")
return gr.Code(open(css_file).read(), language="css")

def code(language, code):
return gr.Code(code, language=language)
Expand Down
3 changes: 2 additions & 1 deletion gradio/_simple_templates/simpledropdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Any, Callable, Sequence
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING, Any

from gradio.components.base import Component, FormComponent
from gradio.events import Events
Expand Down
3 changes: 2 additions & 1 deletion gradio/_simple_templates/simpleimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any, Sequence
from typing import TYPE_CHECKING, Any

from gradio_client import handle_file
from gradio_client.documentation import document
Expand Down
3 changes: 2 additions & 1 deletion gradio/_simple_templates/simpletextbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, Sequence
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING, Any

from gradio.components.base import Component, FormComponent
from gradio.events import Events
Expand Down
33 changes: 17 additions & 16 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
import warnings
import webbrowser
from collections import defaultdict
from collections.abc import AsyncIterator, Callable, Sequence, Set
from pathlib import Path
from types import ModuleType
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
AsyncIterator,
Callable,
Literal,
Sequence,
cast,
)
from urllib.parse import urlparse, urlunparse
Expand Down Expand Up @@ -681,14 +678,14 @@ def set_event_trigger(
Component
| BlockContext
| Sequence[Component | BlockContext]
| AbstractSet[Component | BlockContext]
| Set[Component | BlockContext]
| None
),
outputs: (
Component
| BlockContext
| Sequence[Component | BlockContext]
| AbstractSet[Component | BlockContext]
| Set[Component | BlockContext]
| None
),
preprocess: bool = True,
Expand Down Expand Up @@ -754,7 +751,7 @@ def set_event_trigger(
)
for target in targets
]
if isinstance(inputs, AbstractSet):
if isinstance(inputs, Set):
inputs_as_dict = True
inputs = sorted(inputs, key=lambda x: x._id)
else:
Expand All @@ -764,7 +761,7 @@ def set_event_trigger(
elif not isinstance(inputs, Sequence):
inputs = [inputs]

if isinstance(outputs, AbstractSet):
if isinstance(outputs, Set):
outputs = sorted(outputs, key=lambda x: x._id)
elif outputs is None:
outputs = []
Expand Down Expand Up @@ -1215,7 +1212,7 @@ def iterate_over_children(children_list):
raise ValueError(
"This config is missing the 'dependencies' field and cannot be loaded."
)
for dependency, fn in zip(config["dependencies"], fns):
for dependency, fn in zip(config["dependencies"], fns, strict=False):
# We used to add a "fake_event" to the config to cache examples
# without removing it. This was causing bugs in calling gr.load
# We fixed the issue by removing "fake_event" from the config in examples.py
Expand Down Expand Up @@ -1521,7 +1518,9 @@ async def call_function(

if iterator is None: # If not a generator function that has already run
if block_fn.inputs_as_dict:
processed_input = [dict(zip(block_fn.inputs, processed_input))]
processed_input = [
dict(zip(block_fn.inputs, processed_input, strict=False))
]

processed_input, progress_index, _ = special_args(
block_fn.fn, processed_input, request, event_data
Expand Down Expand Up @@ -1772,7 +1771,6 @@ async def postprocess_data(
kwargs["render"] = False

state[block._id] = block.__class__(**kwargs)

prediction_value = postprocess_update_dict(
block=state[block._id],
update_dict=prediction_value,
Expand Down Expand Up @@ -1909,6 +1907,7 @@ async def process_api(
batch = block_fn.batch
state_ids_to_track, hashed_values = self.get_state_ids_to_track(block_fn, state)
changed_state_ids = []
LocalContext.blocks.set(self)

if batch:
max_batch_size = block_fn.max_batch_size
Expand All @@ -1928,11 +1927,11 @@ async def process_api(
)
inputs = [
await self.preprocess_data(block_fn, list(i), state, explicit_call)
for i in zip(*inputs)
for i in zip(*inputs, strict=False)
]
result = await self.call_function(
block_fn,
list(zip(*inputs)),
list(zip(*inputs, strict=False)),
None,
request,
event_id,
Expand All @@ -1943,11 +1942,11 @@ async def process_api(
preds = result["prediction"]
data = [
await self.postprocess_data(block_fn, list(o), state)
for o in zip(*preds)
for o in zip(*preds, strict=False)
]
if root_path is not None:
data = processing_utils.add_root_url(data, root_path, None) # type: ignore
data = list(zip(*data))
data = list(zip(*data, strict=False))
is_generating, iterator = None, None
else:
old_iterator = iterator
Expand All @@ -1972,7 +1971,9 @@ async def process_api(
if state:
changed_state_ids = [
state_id
for hash_value, state_id in zip(hashed_values, state_ids_to_track)
for hash_value, state_id in zip(
hashed_values, state_ids_to_track, strict=False
)
if hash_value != utils.deep_hash(state[state_id])
]

Expand Down
3 changes: 2 additions & 1 deletion gradio/chat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import functools
import inspect
import warnings
from typing import AsyncGenerator, Callable, Literal, Union, cast
from collections.abc import AsyncGenerator, Callable
from typing import Literal, Union, cast

import anyio
from gradio_client.documentation import document
Expand Down
Loading

0 comments on commit a90ff07

Please sign in to comment.