-
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.
Add more ImageEditor js tests (#10446)
* code * Try * add storybook story * add changeset * empty * use local file * add changeset * fix * Revert "fix" This reverts commit 42750f3. * fix * add code * add code * code * Fix * Fix * code * fix * delete cheetah * code * code * empty --------- Co-authored-by: Freddy Boulton <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]>
- Loading branch information
1 parent
b7b96e6
commit 2cf449a
Showing
13 changed files
with
152 additions
and
163 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,7 @@ | ||
--- | ||
"@gradio/imageeditor": patch | ||
"@self/storybook": patch | ||
"gradio": patch | ||
--- | ||
|
||
feat:Add more ImageEditor js tests |
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
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_canvas_size"]}, {"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", " with gr.Row():\n", " with gr.Column():\n", " image = gr.ImageEditor(label=\"Default Canvas. Not fixed\", elem_id=\"default\")\n", " with gr.Column():\n", " custom_canvas = gr.ImageEditor(label=\"Custom Canvas, not fixed\", canvas_size=(300, 300),\n", " elem_id=\"small\")\n", " with gr.Column():\n", " custom_canvas_fixed = gr.ImageEditor(label=\"Custom Canvas,fixed\", canvas_size=(500, 500), fixed_canvas=True,\n", " elem_id=\"fixed\")\n", " with gr.Column():\n", " width = gr.Number(label=\"Width\")\n", " height = gr.Number(label=\"Height\")\n", "\n", " image.change(lambda x: x[\"composite\"].shape, outputs=[height, width], inputs=image)\n", " custom_canvas.change(lambda x: x[\"composite\"].shape, outputs=[height, width], inputs=custom_canvas)\n", " custom_canvas_fixed.change(lambda x: x[\"composite\"].shape, outputs=[height, width], inputs=custom_canvas_fixed)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: image_editor_canvas_size"]}, {"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", " with gr.Row():\n", " with gr.Column():\n", " image = gr.ImageEditor(label=\"Default Canvas. Not fixed\", elem_id=\"default\")\n", " get_image = gr.Button(\"Get Default\")\n", " with gr.Column():\n", " custom_canvas = gr.ImageEditor(label=\"Custom Canvas, not fixed\", canvas_size=(300, 300),\n", " elem_id=\"small\")\n", " get_small = gr.Button(\"Get Small\")\n", " with gr.Column():\n", " custom_canvas_fixed = gr.ImageEditor(label=\"Custom Canvas,fixed\", canvas_size=(500, 500), fixed_canvas=True,\n", " elem_id=\"fixed\")\n", " get_fixed = gr.Button(\"Get Fixed\")\n", " with gr.Column():\n", " width = gr.Number(label=\"Width\")\n", " height = gr.Number(label=\"Height\")\n", "\n", " get_image.click(lambda x: x[\"composite\"].shape, outputs=[height, width], inputs=image)\n", " get_small.click(lambda x: x[\"composite\"].shape, outputs=[height, width], inputs=custom_canvas)\n", " get_fixed.click(lambda x: x[\"composite\"].shape, outputs=[height, width], inputs=custom_canvas_fixed)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: image_editor_story"]}, {"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", "from pathlib import Path\n", "import subprocess\n", "\n", "\n", "def predict(im):\n", " path = str(Path(__file__).parent / \"output-image.png\")\n", " with open(path, \"wb\") as f:\n", " f.write(Path(im[\"composite\"]).read_bytes())\n", " print(\"Writing to \", path)\n", " return path\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " im = gr.ImageEditor(interactive=True, elem_id=\"image_editor\",\n", " canvas_size=(800, 600),\n", " brush=gr.Brush(colors=[\"#ff0000\", \"#00ff00\", \"#0000ff\"]),\n", " type=\"filepath\",\n", " value={\"background\": \"https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg\",\n", " \"layers\": [],\n", " \"composite\": None})\n", " get = gr.Button(\"Get\")\n", "\n", " with gr.Column():\n", " output = gr.Image(value=None, elem_id=\"output\")\n", "\n", " get.click(predict, inputs=im, outputs=output)\n", "\n", "if __name__ == \"__main__\":\n", " app, _, _ = demo.launch(prevent_thread_lock=True)\n", " subprocess.call([\"node\", \"js/storybook/ie_automation.js\"])\n", " demo.close()\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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import gradio as gr | ||
from pathlib import Path | ||
import subprocess | ||
|
||
|
||
def predict(im): | ||
path = str(Path(__file__).parent / "output-image.png") | ||
with open(path, "wb") as f: | ||
f.write(Path(im["composite"]).read_bytes()) | ||
print("Writing to ", path) | ||
return path | ||
|
||
|
||
with gr.Blocks() as demo: | ||
with gr.Row(): | ||
with gr.Column(): | ||
im = gr.ImageEditor(interactive=True, elem_id="image_editor", | ||
canvas_size=(800, 600), | ||
brush=gr.Brush(colors=["#ff0000", "#00ff00", "#0000ff"]), | ||
type="filepath", | ||
value={"background": "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg", | ||
"layers": [], | ||
"composite": None}) | ||
get = gr.Button("Get") | ||
|
||
with gr.Column(): | ||
output = gr.Image(value=None, elem_id="output") | ||
|
||
get.click(predict, inputs=im, outputs=output) | ||
|
||
if __name__ == "__main__": | ||
app, _, _ = demo.launch(prevent_thread_lock=True) | ||
subprocess.call(["node", "js/storybook/ie_automation.js"]) | ||
demo.close() |
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
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
Oops, something went wrong.