Skip to content

Commit

Permalink
Merge branch 'main' into revert-story-book-version-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pngwn authored Nov 16, 2024
2 parents 88c56e9 + 4d520a8 commit c0b8032
Show file tree
Hide file tree
Showing 210 changed files with 2,348 additions and 342 deletions.
6 changes: 0 additions & 6 deletions .changeset/beige-badgers-argue.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/chatty-kings-visit.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changeset/empty-monkeys-do.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/fluffy-cats-drop.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/giant-baboons-lick.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/late-candies-boil.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/long-wolves-serve.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/moody-crews-pull.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/silver-planes-guess.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/slick-crabs-move.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/slow-baboons-report.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/tidy-bikes-allow.md

This file was deleted.

6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Before your create a PR, please check to see if there is [an existing issue](htt

Not adhering to this guideline will result in the PR being closed.

## Tests
## Testing and Formatting Your Code

1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up [your Gradio environment locally](https://github.com/gradio-app/gradio/blob/main/CONTRIBUTING.md) and run the tests: `bash scripts/run_all_tests.sh`
1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up [your Gradio environment locally](https://github.com/gradio-app/gradio/blob/main/CONTRIBUTING.md) and run the backed tests: `bash scripts/run_backend_tests.sh`

2. You may need to run the linters: `bash scripts/format_backend.sh` and `bash scripts/format_frontend.sh`
2. Please run these bash scripts to automatically format your code: `bash scripts/format_backend.sh`, and (if you made any changes to non-Python files) `bash scripts/format_frontend.sh`

49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# gradio

## 5.6.0

### Features

- [#9906](https://github.com/gradio-app/gradio/pull/9906) [`eafe22c`](https://github.com/gradio-app/gradio/commit/eafe22cd9404d536b03d3fa80003acea78599d49) - Clearer error message in CheckboxGroup's preprocess function. Thanks @muhammadyaseen!
- [#9930](https://github.com/gradio-app/gradio/pull/9930) [`eae345e`](https://github.com/gradio-app/gradio/commit/eae345e5fde39aea220b57c6a954cd7d72ff32d5) - Allow settings custom headers in js client. Thanks @elgiano!
- [#9921](https://github.com/gradio-app/gradio/pull/9921) [`a70ba5e`](https://github.com/gradio-app/gradio/commit/a70ba5e0f01f0c376da0d4e45634bc967f5299f4) - Clearer error message in Dropdown's and Radio's preprocess function. Thanks @muhammadyaseen!
- [#9933](https://github.com/gradio-app/gradio/pull/9933) [`66375ac`](https://github.com/gradio-app/gradio/commit/66375acb5c0a3a8eecc4cfa00701b14f21f3ed68) - Fix typo in Exception raised by base.py. Thanks @meg-huggingface!
- [#9950](https://github.com/gradio-app/gradio/pull/9950) [`fc06fe4`](https://github.com/gradio-app/gradio/commit/fc06fe41f015678a0545f4e5c99f6ae2704f0031) - Add ability to read and write from LocalStorage. Thanks @abidlabs!
- [#9966](https://github.com/gradio-app/gradio/pull/9966) [`da6f191`](https://github.com/gradio-app/gradio/commit/da6f1915547b03601d1808b28e57cca62308df71) - Remember token locally with `gr.load()`. Thanks @abidlabs!

### Fixes

- [#9949](https://github.com/gradio-app/gradio/pull/9949) [`cfb62bf`](https://github.com/gradio-app/gradio/commit/cfb62bfdb52d88295f27287f788fca977e37ae6d) - Allow dataframe column content to wrap. Thanks @hannahblair!
- [#9897](https://github.com/gradio-app/gradio/pull/9897) [`c0cf80b`](https://github.com/gradio-app/gradio/commit/c0cf80bddd99ad0f836e618cc3d2b13e73cb5611) - Allow datetime value to be null. Thanks @hannahblair!
- [#9958](https://github.com/gradio-app/gradio/pull/9958) [`75ad3e3`](https://github.com/gradio-app/gradio/commit/75ad3e341978a521df3d11d4f97d6e55f784c9a1) - SSR Safari Fix. Thanks @dawoodkhan82!
- [#9905](https://github.com/gradio-app/gradio/pull/9905) [`08f4b8b`](https://github.com/gradio-app/gradio/commit/08f4b8b000702456e04fac70961a4fbe0058f11c) - Add `allow_file_downloads` param to allow downloading image/video/audio media in chatbot. Thanks @hannahblair!
- [#9913](https://github.com/gradio-app/gradio/pull/9913) [`d81f430`](https://github.com/gradio-app/gradio/commit/d81f430fd50546001b76c0ae5fded32c6d3093f7) - fix: Fix filename stripping to preserve extensions. Thanks @TakaSoap!
- [#9946](https://github.com/gradio-app/gradio/pull/9946) [`a966e9f`](https://github.com/gradio-app/gradio/commit/a966e9f753af25eb9d813dfdbce39be6f3014d82) - Hide upload button after upload when `file_count="single"`. Thanks @abidlabs!
- [#9901](https://github.com/gradio-app/gradio/pull/9901) [`74b4ff0`](https://github.com/gradio-app/gradio/commit/74b4ff0e61a2a32e1cd5e3354d3002b369c7ad83) - Ensure radio radius is consistent with checkbox radius. Thanks @hannahblair!
- [#9904](https://github.com/gradio-app/gradio/pull/9904) [`f523c91`](https://github.com/gradio-app/gradio/commit/f523c915d3732859ff4a8019a82cb597b5208ae2) - Ensure dropped files are validated in MultimediaTextbox. Thanks @hannahblair!

## 5.5.0

### Features

- [#9875](https://github.com/gradio-app/gradio/pull/9875) [`8305ff8`](https://github.com/gradio-app/gradio/commit/8305ff8712183f27174cfb891548ad7cc1c67fed) - Adds `.expand()` and `.collapse()` events to `gr.Accordion`. Thanks @abidlabs!
- [#9424](https://github.com/gradio-app/gradio/pull/9424) [`a1582a6`](https://github.com/gradio-app/gradio/commit/a1582a6dca494618c734208cade87acfdac91004) - Lite worker refactoring. Thanks @whitphx!
- [#9891](https://github.com/gradio-app/gradio/pull/9891) [`fc12496`](https://github.com/gradio-app/gradio/commit/fc124964a1b4922e54a4ca4755f0a536dfae1a21) - Allow uploading more files in gr.File. Thanks @hannahblair!
- [#9898](https://github.com/gradio-app/gradio/pull/9898) [`dcfa7ad`](https://github.com/gradio-app/gradio/commit/dcfa7ad3e819002c0213a592ad726ccfd9e2bf0c) - Enforce `meta` key present during preprocess in FileData payloads. Thanks @freddyaboulton!
- [#9887](https://github.com/gradio-app/gradio/pull/9887) [`d407c00`](https://github.com/gradio-app/gradio/commit/d407c007153705a7f5446f4601c12f208ec32a5b) - Add `.download()` event to `gr.File`. Thanks @abidlabs!
- [#9726](https://github.com/gradio-app/gradio/pull/9726) [`b6725cf`](https://github.com/gradio-app/gradio/commit/b6725cf6c1fe9667dc10e1988976ed36d84d73d3) - Lite auto-load imported modules with `pyodide.loadPackagesFromImports`. Thanks @whitphx!
- [#9786](https://github.com/gradio-app/gradio/pull/9786) [`f109497`](https://github.com/gradio-app/gradio/commit/f109497e8281b3429b58e3f6a293dd63ebcc08af) - Fix frontend errors on ApiDocs and RecordingSnippet. Thanks @whitphx!
- [#9800](https://github.com/gradio-app/gradio/pull/9800) [`d1cfe1e`](https://github.com/gradio-app/gradio/commit/d1cfe1e9defa06f927aec2671656fe77514dd0fa) - Allow plot tooltip to show extra columns. Thanks @aliabid94!

### Fixes

- [#9835](https://github.com/gradio-app/gradio/pull/9835) [`4d90883`](https://github.com/gradio-app/gradio/commit/4d9088354df528c8edf981f3e756d8927d3e8805) - Allows selection of directories in File Explorer. Thanks @aliabid94!
- [#9883](https://github.com/gradio-app/gradio/pull/9883) [`e10bbd2`](https://github.com/gradio-app/gradio/commit/e10bbd236f5817698f5e5ac1c14c7ec179a725b6) - Fix live interfaces for audio/image streaming. Thanks @freddyaboulton!
- [#9804](https://github.com/gradio-app/gradio/pull/9804) [`458a38c`](https://github.com/gradio-app/gradio/commit/458a38cabb8e378bb008b1abec8eee8b780fe712) - Fixes for ChatInterface Examples when additional inputs are provided. Thanks @dawoodkhan82!
- [#9827](https://github.com/gradio-app/gradio/pull/9827) [`7ed8d02`](https://github.com/gradio-app/gradio/commit/7ed8d02979e8ad4db6ef62b29ce080f31bcf9a0d) - Fix Loading SSR'd apps via gr.load. Thanks @freddyaboulton!
- [#9882](https://github.com/gradio-app/gradio/pull/9882) [`6c8a064`](https://github.com/gradio-app/gradio/commit/6c8a064feeaa89a2ffc96260032f24f18eb032fa) - Ensure non-form elements are correctly positioned when scale is applied. Thanks @hannahblair!
- [#9880](https://github.com/gradio-app/gradio/pull/9880) [`120198f`](https://github.com/gradio-app/gradio/commit/120198fe2da2ded9e8f27549b9dfd1cd81992ec4) - Fixes LoginButton for SSR. Thanks @dawoodkhan82!
- [#9881](https://github.com/gradio-app/gradio/pull/9881) [`6866a54`](https://github.com/gradio-app/gradio/commit/6866a5433afe7e29ad73bac10ecbc3b44f5867f4) - Ensure gallery share button is positioned correctly. Thanks @hannahblair!
- [#9826](https://github.com/gradio-app/gradio/pull/9826) [`69acfeb`](https://github.com/gradio-app/gradio/commit/69acfebffd0d3479a40352de19c8763863557428) - Make sure the Tool accordion is closed if it is not the last message. Thanks @freddyaboulton!
- [#9892](https://github.com/gradio-app/gradio/pull/9892) [`7d77024`](https://github.com/gradio-app/gradio/commit/7d77024cb8f9cfd39a6468de9534e58dcfa69f49) - Fix dataframe height increasing on scroll. Thanks @abidlabs!
- [#9859](https://github.com/gradio-app/gradio/pull/9859) [`c1cb5be`](https://github.com/gradio-app/gradio/commit/c1cb5be2d79fce5d25032366b5864700ba9d1114) - Fix: Resolve copy button visibility issue in Textbox component. Thanks @rahulsamant37!
- [#9886](https://github.com/gradio-app/gradio/pull/9886) [`fa5d433`](https://github.com/gradio-app/gradio/commit/fa5d4339d6aafda529150d9536b895e2b239c831) - Do not load code in gr.NO_RELOAD in the reload mode watch thread. Thanks @freddyaboulton!

## 5.4.0

### Features
Expand Down
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ gradio app.py

This will start the backend server in reload mode, which will watch for changes in the `gradio` folder and reload the app if changes are made. By default, Gradio will launch on port 7860. You can also just use `python app.py`, but this won't automatically trigger updates.

Note: if you have `gradio` installed elsewhere in your system, you may need to uninstall it or at least make sure your `PYTHONPATH` includes the directory where the Gradio repository is cloned, e.g.,
`export PYTHONPATH="./"`


If you're making frontend changes, start the frontend server:

Expand All @@ -140,7 +143,7 @@ We use Pytest, Playwright and Vitest to test our code.
- The Python tests are located in `/test`. To run these tests:

```
bash scripts/run_all_tests.sh
bash scripts/run_backend_tests.sh
```

- The frontend unit tests are any defined with the filename `*.test.ts`. To run them:
Expand Down Expand Up @@ -348,5 +351,18 @@ Run `scripts/build_frontend.sh` with the environment variable `NODE_OPTIONS=--ma

---

In the case of:
- Unexpected exceptions being thrown, or
- The following warning:
`IMPORTANT: You are using gradio version <earlier version>, however version <later version> is available, please upgrade.`

ensure your `PYTHONPATH` includes the directory where the Gradio repository is cloned, e.g.:

```export PYTHONPATH="./"```

This ensures that when `gradio` is imported in a python program, it is this current version from this repository.

---

_Could these guidelines be clearer? Feel free to open a PR to help us facilitate open-source contributions!_

7 changes: 7 additions & 0 deletions client/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @gradio/client

## 1.8.0

### Features

- [#9930](https://github.com/gradio-app/gradio/pull/9930) [`eae345e`](https://github.com/gradio-app/gradio/commit/eae345e5fde39aea220b57c6a954cd7d72ff32d5) - Allow settings custom headers in js client. Thanks @elgiano!
- [#9950](https://github.com/gradio-app/gradio/pull/9950) [`fc06fe4`](https://github.com/gradio-app/gradio/commit/fc06fe41f015678a0545f4e5c99f6ae2704f0031) - Add ability to read and write from LocalStorage. Thanks @abidlabs!

## 1.7.1

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion client/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gradio/client",
"version": "1.7.1",
"version": "1.8.0",
"description": "Gradio API client",
"type": "module",
"main": "dist/index.js",
Expand Down
10 changes: 10 additions & 0 deletions client/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export class Client {
if (this && this.cookies) {
headers.append("Cookie", this.cookies);
}
if (this && this.options.headers) {
for (const name in this.options.headers) {
headers.append(name, this.options.headers[name]);
}
}

return fetch(input, { ...init, headers });
}
Expand All @@ -79,6 +84,11 @@ export class Client {
if (this && this.cookies) {
headers.append("Cookie", this.cookies);
}
if (this && this.options.headers) {
for (const name in this.options.headers) {
headers.append(name, this.options.headers[name]);
}
}

this.abort_controller = new AbortController();

Expand Down
1 change: 1 addition & 0 deletions client/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export interface ClientOptions {
auth?: [string, string] | null;
with_null_state?: boolean;
events?: EventType[];
headers?: Record<string, string>;
}

export interface FileData {
Expand Down
6 changes: 6 additions & 0 deletions client/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# gradio_client

## 1.4.3

### Fixes

- [#9913](https://github.com/gradio-app/gradio/pull/9913) [`d81f430`](https://github.com/gradio-app/gradio/commit/d81f430fd50546001b76c0ae5fded32c6d3093f7) - fix: Fix filename stripping to preserve extensions. Thanks @TakaSoap!

## 1.4.2

### Fixes
Expand Down
6 changes: 6 additions & 0 deletions client/python/gradio_client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# gradio_client

## 1.4.3

### Fixes

- [#9913](https://github.com/gradio-app/gradio/pull/9913) [`d81f430`](https://github.com/gradio-app/gradio/commit/d81f430fd50546001b76c0ae5fded32c6d3093f7) - fix: Fix filename stripping to preserve extensions. Thanks @TakaSoap!

## 1.4.2

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion client/python/gradio_client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gradio_client",
"version": "1.4.2",
"version": "1.4.3",
"description": "",
"python": "true",
"main_changeset": true,
Expand Down
15 changes: 11 additions & 4 deletions client/python/gradio_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,21 @@ def decode_base64_to_binary(encoding: str) -> tuple[bytes, str | None]:


def strip_invalid_filename_characters(filename: str, max_bytes: int = 200) -> str:
"""Strips invalid characters from a filename and ensures that the file_length is less than `max_bytes` bytes."""
filename = "".join([char for char in filename if char.isalnum() or char in "._- "])
"""
Strips invalid characters from a filename and ensures it does not exceed the maximum byte length
Invalid characters are any characters that are not alphanumeric or one of the following: . _ -
The filename may include an extension (in which case it is preserved exactly as is), or could be just a name without an extension.
"""
name, ext = os.path.splitext(filename)
name = "".join([char for char in name if char.isalnum() or char in "._- "])
filename = name + ext
filename_len = len(filename.encode())
if filename_len > max_bytes:
while filename_len > max_bytes:
if len(filename) == 0:
if len(name) == 0:
break
filename = filename[:-1]
name = name[:-1]
filename = name + ext
filename_len = len(filename.encode())
return filename

Expand Down
8 changes: 5 additions & 3 deletions client/python/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ def test_is_valid_file_type(path_or_url, file_types, expected_result):
[
("abc", "abc"),
("$$AAabc&3", "AAabc3"),
("$$AAabc&3", "AAabc3"),
("$$AAa..b-c&3_", "AAa..b-c3_"),
("$$AAa..b-c&3_", "AAa..b-c3_"),
("$$AAa&..b-c3_", "AAa..b-c3_"),
(
"ゆかりです。私、こんなかわいい服は初めて着ました…。なんだかうれしくって、楽しいです。歌いたくなる気分って、初めてです。これがアイドルってことなのかもしれませんね",
"ゆかりです私こんなかわいい服は初めて着ましたなんだかうれしくって楽しいです歌いたくなる気分って初めてですこれがアイドルってことなの",
),
(
"Bringing-computational-thinking-into-classrooms-a-systematic-review-on-supporting-teachers-in-integrating-computational-thinking-into-K12-classrooms_2024_Springer-Science-and-Business-Media-Deutschland-GmbH.pdf",
"Bringing-computational-thinking-into-classrooms-a-systematic-review-on-supporting-teachers-in-integrating-computational-thinking-into-K12-classrooms_2024_Springer-Science-and-Business-Media-Deutsc.pdf",
),
],
)
def test_strip_invalid_filename_characters(orig_filename, new_filename):
Expand Down
1 change: 1 addition & 0 deletions demo/browser_state_component/run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: browser_state_component"]}, {"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": ["import gradio as gr\n", "\n", "with gr.Blocks() as demo:\n", " gr.BrowserState()\n", "\n", "demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
6 changes: 6 additions & 0 deletions demo/browser_state_component/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import gradio as gr

with gr.Blocks() as demo:
gr.BrowserState()

demo.launch()
1 change: 1 addition & 0 deletions demo/browserstate/run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: browserstate"]}, {"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": ["import random\n", "import string\n", "import gradio as gr\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Your Username and Password will get saved in the browser's local storage. \"\n", " \"If you refresh the page, the values will be retained.\")\n", " username = gr.Textbox(label=\"Username\")\n", " password = gr.Textbox(label=\"Password\", type=\"password\")\n", " btn = gr.Button(\"Generate Randomly\")\n", " local_storage = gr.BrowserState([\"\", \"\"])\n", "\n", " @btn.click(outputs=[username, password])\n", " def generate_randomly():\n", " u = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", " p = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", " return u, p\n", "\n", " @demo.load(inputs=[local_storage], outputs=[username, password])\n", " def load_from_local_storage(saved_values):\n", " print(\"loading from local storage\", saved_values)\n", " return saved_values[0], saved_values[1]\n", "\n", " @gr.on([username.change, password.change], inputs=[username, password], outputs=[local_storage])\n", " def save_to_local_storage(username, password):\n", " return [username, password]\n", "\n", "demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
Loading

0 comments on commit c0b8032

Please sign in to comment.