forked from gradio-app/gradio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve Gallery selected image through updates (gradio-app#3061)
* Fix bug * CHANGELOG demo fix-tabs (gradio-app#3055) * fix-tabs * Reformat changelog Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com> video-bug-demo Another bug Fix video and file events bugs demo.ipynb fix space embeds using `src` attribute (gradio-app#3065) * change ports in dev mode * changelog * correctly detect space embeds * changelog * formatting fix css scoping (gradio-app#3059) Fix auth on spaces (gradio-app#3049) * Add route alias * on button click * Fix config * Do not redirect * Use login to check if other route necessary * Add message about HF spaces * CHANGELOG * Add gif to changelog Fix Sketch clearing bug (gradio-app#3047) * bug fix * changelog * undo fix Release version 3.17.0 (gradio-app#3074) * version 3.17.0 * changelog New Version Docs (gradio-app#3087) Chatbot loader (gradio-app#3079) * changes * chagnes * changes * changes * changes * changes --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Changelog and format front changelog fix Change demo video and image Fix image rotation on iOS (gradio-app#3091) * rotate image based on exif tag * rotate on backend * CHANGELOG * Only rotate if needed * Add image comparison to changelog --------- Co-authored-by: Dawood Khan <dawoodkhan82@gmail.com> Set minimum markdown-it-py version to 2.0.0 (gradio-app#3102) * Bump requirements * CHANGELOG only mount fonts in prod mode (gradio-app#3100) * only mount fonts in prod mode * cleanup --------- Co-authored-by: aliabid94 <aabid94@gmail.com> Fix change event listener (gradio-app#3095) * changes * changes --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: pngwn <hello@pngwn.io> [Minor] Correct link (gradio-app#3109) * Correct link * Update CHANGELOG.md Enable gradio to work on kaggle (gradio-app#3101) * enable share kaggle * Add test * CHANGELOG * Add image to changelog Fix example gallery mode (gradio-app#3090) * Fix example gallery mode * CHANGELOG fix changelog fix changelog
- Loading branch information
1 parent
7fc3e75
commit b786e91
Showing
54 changed files
with
42,546 additions
and
167 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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: event_trigger"]}, {"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('img')\n", "!wget -q -O img/a.jpg https://github.com/gradio-app/gradio/raw/main/demo/event_trigger/img/a.jpg\n", "!wget -q -O img/b.jpg https://github.com/gradio-app/gradio/raw/main/demo/event_trigger/img/b.jpg\n", "os.mkdir('mp4')\n", "!wget -q -O mp4/a.mp4 https://github.com/gradio-app/gradio/raw/main/demo/event_trigger/mp4/a.mp4\n", "!wget -q -O mp4/b.mp4 https://github.com/gradio-app/gradio/raw/main/demo/event_trigger/mp4/b.mp4"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["# %%\n", "import gradio as gr\n", "\n", "\n", "TEST_VIDEO_A = \"mp4/a.mp4\"\n", "TEST_VIDEO_B = \"mp4/b.mp4\"\n", "\n", "TEST_IMAGE_A = \"img/a.jpg\"\n", "TEST_IMAGE_B = \"img/b.jpg\"\n", "\n", "\n", "def alert_change(component, value):\n", " print(f\"Detected {component} change, {type(value)}\")\n", "\n", " if type(value) == list or type(value) == str:\n", " print(value)\n", "\n", "\n", "def change_interactive(state):\n", " return gr.update(interactive=not state), not state\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Tab(label=\"Text change\"):\n", " with gr.Row():\n", " with gr.Column():\n", " textbox1 = gr.Textbox()\n", " textbox2 = gr.Textbox(interactive=True)\n", "\n", " with gr.Column():\n", " btn = gr.Button()\n", "\n", " def btn_click(state):\n", " return state\n", "\n", " def text_change(value):\n", " print(\"text_change\", value)\n", "\n", " btn.click(fn=btn_click, inputs=textbox1, outputs=textbox2)\n", " textbox2.change(fn=alert_change, inputs=[gr.State(\"Text\"), textbox2])\n", "\n", " with gr.Tab(label=\"Video change, play, pause\"):\n", " with gr.Row():\n", " with gr.Column():\n", " radio1 = gr.Radio(\n", " choices=[TEST_VIDEO_A, TEST_VIDEO_B],\n", " interactive=True,\n", " type=\"index\",\n", " )\n", "\n", " video_btn = gr.Button(\"Change interactive\")\n", "\n", " with gr.Column():\n", " video1 = gr.Video(value=TEST_VIDEO_A, interactive=False)\n", " video1_interactive = gr.State(value=False)\n", "\n", " def change_video(index):\n", " if index == 0:\n", " return TEST_VIDEO_A\n", " elif index == 1:\n", " return TEST_VIDEO_B\n", "\n", " def video_play():\n", " print(\"video_play\")\n", "\n", " def video_pause():\n", " print(\"video_pause\")\n", "\n", " def video_stop():\n", " print(\"video_stop\")\n", "\n", " video1.play(fn=video_play)\n", " video1.pause(fn=video_pause)\n", " video1.stop(fn=video_stop)\n", "\n", " radio1.change(fn=change_video, inputs=radio1, outputs=video1)\n", " video1.change(fn=alert_change, inputs=[gr.State(\"Video\"), video1])\n", "\n", " video_btn.click(\n", " fn=change_interactive,\n", " inputs=video1_interactive,\n", " outputs=[video1, video1_interactive],\n", " )\n", "\n", " with gr.Tab(label=\"Image change\"):\n", " with gr.Row():\n", " with gr.Column():\n", " radio2 = gr.Radio(\n", " choices=[TEST_IMAGE_A, TEST_IMAGE_B],\n", " interactive=True,\n", " type=\"index\",\n", " )\n", "\n", " with gr.Column():\n", " image1 = gr.Image(value=TEST_IMAGE_A, interactive=True)\n", "\n", " def change_image(index):\n", " if index == 0:\n", " return TEST_IMAGE_A\n", " elif index == 1:\n", " return TEST_IMAGE_B\n", "\n", " radio2.change(fn=change_image, inputs=radio2, outputs=image1)\n", " image1.change(fn=alert_change, inputs=[gr.State(\"Image\"), image1])\n", "\n", " with gr.Tab(label=\"File\"):\n", " with gr.Row():\n", " with gr.Column():\n", " radio3 = gr.Radio(\n", " choices=[\"A\", \"B\", \"AB\"],\n", " interactive=True,\n", " type=\"index\",\n", " )\n", "\n", " file_btn = gr.Button(\"Change interactive\")\n", "\n", " with gr.Column():\n", " file1 = gr.File(\n", " value=[TEST_IMAGE_A, TEST_IMAGE_B],\n", " interactive=False,\n", " file_count=\"multiple\",\n", " )\n", " file1_interactive = gr.State(value=False)\n", "\n", " def change_file(index):\n", " if index == 0:\n", " return [TEST_IMAGE_A]\n", " elif index == 1:\n", " return [TEST_IMAGE_A]\n", " elif index == 2:\n", " return [TEST_IMAGE_A, TEST_IMAGE_B]\n", "\n", " radio3.change(fn=change_file, inputs=radio3, outputs=file1)\n", " file1.change(fn=alert_change, inputs=[gr.State(\"File\"), file1])\n", "\n", " file_btn.click(\n", " fn=change_interactive,\n", " inputs=file1_interactive,\n", " outputs=[file1, file1_interactive],\n", " )\n", "\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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# %% | ||
import gradio as gr | ||
|
||
|
||
TEST_VIDEO_A = "mp4/a.mp4" | ||
TEST_VIDEO_B = "mp4/b.mp4" | ||
|
||
TEST_IMAGE_A = "img/a.jpg" | ||
TEST_IMAGE_B = "img/b.jpg" | ||
|
||
|
||
def alert_change(component, value): | ||
print(f"Detected {component} change, {type(value)}") | ||
|
||
if type(value) == list or type(value) == str: | ||
print(value) | ||
|
||
|
||
def change_interactive(state): | ||
return gr.update(interactive=not state), not state | ||
|
||
|
||
with gr.Blocks() as demo: | ||
with gr.Tab(label="Text change"): | ||
with gr.Row(): | ||
with gr.Column(): | ||
textbox1 = gr.Textbox() | ||
textbox2 = gr.Textbox(interactive=True) | ||
|
||
with gr.Column(): | ||
btn = gr.Button() | ||
|
||
def btn_click(state): | ||
return state | ||
|
||
def text_change(value): | ||
print("text_change", value) | ||
|
||
btn.click(fn=btn_click, inputs=textbox1, outputs=textbox2) | ||
textbox2.change(fn=alert_change, inputs=[gr.State("Text"), textbox2]) | ||
|
||
with gr.Tab(label="Video change, play, pause"): | ||
with gr.Row(): | ||
with gr.Column(): | ||
radio1 = gr.Radio( | ||
choices=[TEST_VIDEO_A, TEST_VIDEO_B], | ||
interactive=True, | ||
type="index", | ||
) | ||
|
||
video_btn = gr.Button("Change interactive") | ||
|
||
with gr.Column(): | ||
video1 = gr.Video(value=TEST_VIDEO_A, interactive=False) | ||
video1_interactive = gr.State(value=False) | ||
|
||
def change_video(index): | ||
if index == 0: | ||
return TEST_VIDEO_A | ||
elif index == 1: | ||
return TEST_VIDEO_B | ||
|
||
def video_play(): | ||
print("video_play") | ||
|
||
def video_pause(): | ||
print("video_pause") | ||
|
||
def video_stop(): | ||
print("video_stop") | ||
|
||
video1.play(fn=video_play) | ||
video1.pause(fn=video_pause) | ||
video1.stop(fn=video_stop) | ||
|
||
radio1.change(fn=change_video, inputs=radio1, outputs=video1) | ||
video1.change(fn=alert_change, inputs=[gr.State("Video"), video1]) | ||
|
||
video_btn.click( | ||
fn=change_interactive, | ||
inputs=video1_interactive, | ||
outputs=[video1, video1_interactive], | ||
) | ||
|
||
with gr.Tab(label="Image change"): | ||
with gr.Row(): | ||
with gr.Column(): | ||
radio2 = gr.Radio( | ||
choices=[TEST_IMAGE_A, TEST_IMAGE_B], | ||
interactive=True, | ||
type="index", | ||
) | ||
|
||
with gr.Column(): | ||
image1 = gr.Image(value=TEST_IMAGE_A, interactive=True) | ||
|
||
def change_image(index): | ||
if index == 0: | ||
return TEST_IMAGE_A | ||
elif index == 1: | ||
return TEST_IMAGE_B | ||
|
||
radio2.change(fn=change_image, inputs=radio2, outputs=image1) | ||
image1.change(fn=alert_change, inputs=[gr.State("Image"), image1]) | ||
|
||
with gr.Tab(label="File"): | ||
with gr.Row(): | ||
with gr.Column(): | ||
radio3 = gr.Radio( | ||
choices=["A", "B", "AB"], | ||
interactive=True, | ||
type="index", | ||
) | ||
|
||
file_btn = gr.Button("Change interactive") | ||
|
||
with gr.Column(): | ||
file1 = gr.File( | ||
value=[TEST_IMAGE_A, TEST_IMAGE_B], | ||
interactive=False, | ||
file_count="multiple", | ||
) | ||
file1_interactive = gr.State(value=False) | ||
|
||
def change_file(index): | ||
if index == 0: | ||
return [TEST_IMAGE_A] | ||
elif index == 1: | ||
return [TEST_IMAGE_A] | ||
elif index == 2: | ||
return [TEST_IMAGE_A, TEST_IMAGE_B] | ||
|
||
radio3.change(fn=change_file, inputs=radio3, outputs=file1) | ||
file1.change(fn=alert_change, inputs=[gr.State("File"), file1]) | ||
|
||
file_btn.click( | ||
fn=change_interactive, | ||
inputs=file1_interactive, | ||
outputs=[file1, file1_interactive], | ||
) | ||
|
||
demo.launch() |
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.