-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where ImageEditor always sends empty layers list to the backe…
…nd (#10306) * Add code * add changeset * lint * empty --------- Co-authored-by: gradio-pr-bot <[email protected]>
- Loading branch information
1 parent
1e253ff
commit 9fc988e
Showing
4 changed files
with
15 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@gradio/imageeditor": patch | ||
"gradio": patch | ||
--- | ||
|
||
fix:Fix bug where ImageEditor always sends empty layers list to the backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: image_editor_layers"]}, {"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/image_editor_layers/cheetah.jpg\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_editor_layers/layer1.png"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "dir_ = Path(__file__).parent\n", "\n", "def predict(im):\n", " return im\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " im = gr.ImageEditor(\n", " type=\"numpy\",\n", " interactive=True,\n", " )\n", " im_preview = gr.ImageEditor(\n", " interactive=True,\n", " )\n", "\n", " set_background = gr.Button(\"Set Background\")\n", " set_background.click(\n", " lambda: {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": None,\n", " \"composite\": None,\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " set_layers = gr.Button(\"Set Layers\")\n", " set_layers.click(\n", " lambda: {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": [str(dir_ / \"layer1.png\")],\n", " \"composite\": None,\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " set_composite = gr.Button(\"Set Composite\")\n", " set_composite.click(\n", " lambda: {\n", " \"background\": None,\n", " \"layers\": None,\n", " \"composite\": \"https://nationalzoo.si.edu/sites/default/files/animals/cheetah-003.jpg\",\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", "\n", " im.change(\n", " predict,\n", " outputs=im_preview,\n", " inputs=im,\n", " )\n", "\n", " gr.Examples(\n", " examples=[\n", " \"https://upload.wikimedia.org/wikipedia/commons/0/09/TheCheethcat.jpg\",\n", " {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": [str(dir_ / \"layer1.png\")],\n", " \"composite\": None,\n", " },\n", " ],\n", " inputs=im,\n", " )\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: image_editor_layers"]}, {"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/image_editor_layers/cheetah.jpg\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_editor_layers/layer1.png"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "dir_ = Path(__file__).parent\n", "\n", "def predict(im):\n", " return im, len(im['layers'])\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " im = gr.ImageEditor(\n", " type=\"numpy\",\n", " interactive=True,\n", " )\n", " im_preview = gr.ImageEditor(\n", " interactive=True,\n", " )\n", " \n", " num_layers = gr.Number(value=0, label=\"Num Layers\")\n", "\n", " set_background = gr.Button(\"Set Background\")\n", " set_background.click(\n", " lambda: {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": None,\n", " \"composite\": None,\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " set_layers = gr.Button(\"Set Layers\")\n", " set_layers.click(\n", " lambda: {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": [str(dir_ / \"layer1.png\")],\n", " \"composite\": None,\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " set_composite = gr.Button(\"Set Composite\")\n", " set_composite.click(\n", " lambda: {\n", " \"background\": None,\n", " \"layers\": None,\n", " \"composite\": \"https://nationalzoo.si.edu/sites/default/files/animals/cheetah-003.jpg\",\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", "\n", " im.change(\n", " predict,\n", " outputs=[im_preview, num_layers],\n", " inputs=im,\n", " )\n", "\n", " gr.Examples(\n", " examples=[\n", " \"https://upload.wikimedia.org/wikipedia/commons/0/09/TheCheethcat.jpg\",\n", " {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": [str(dir_ / \"layer1.png\")],\n", " \"composite\": None,\n", " },\n", " ],\n", " inputs=im,\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters