Skip to content

Commit

Permalink
Preserve Gallery selected image through updates (gradio-app#3061)
Browse files Browse the repository at this point in the history
* 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
freddyaboulton authored and tomchang25 committed Feb 2, 2023
1 parent 7fc3e75 commit b786e91
Show file tree
Hide file tree
Showing 54 changed files with 42,546 additions and 167 deletions.
84 changes: 81 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,67 @@
# Upcoming Release
# Upcoming Release

## New Features:

### iOS image rotation fixed 🔄

Previously photos uploaded via iOS would be rotated after processing. This has been fixed by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3091)

#### Before
![image](https://user-images.githubusercontent.com/41651716/215846507-a36e9d05-1ac2-4867-8ab3-ce045a9415d9.png)

#### After
![image](https://user-images.githubusercontent.com/41651716/215846554-e41773ed-70f0-491a-9952-6a18babf91ef.png)

<<<<<<< HEAD
=======
### Run on Kaggle kernels 🧪

A share link will automatically be created when running on Kaggle kernels (notebooks) so that
the front-end is properly displayed.

![image](https://user-images.githubusercontent.com/41651716/216104254-2cf55599-449c-436c-b57e-40f6a83f9eee.png)

By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3101](https://github.com/gradio-app/gradio/pull/3101)

>>>>>>> 42ad0cbe (Enable gradio to work on kaggle (#3101))
## Bug Fixes:
<<<<<<< HEAD
<<<<<<< HEAD

=======
* Fix bug where examples were not rendered correctly for demos created with Blocks api that had multiple input compinents by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3090](https://github.com/gradio-app/gradio/pull/3090)
>>>>>>> 792289cd (Fix example gallery mode (#3090))
- Fix change event listener for JSON, HighlightedText, Chatbot by [@aliabid94](https://github.com/aliabid94) in [PR 3095](https://github.com/gradio-app/gradio/pull/3095)

## Documentation Changes:
<<<<<<< HEAD

No changes to highlight.
=======
=======
* Fix bug where examples were not rendered correctly for demos created with Blocks api that had multiple input compinents by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3090](https://github.com/gradio-app/gradio/pull/3090)
- Fix change event listener for JSON, HighlightedText, Chatbot by [@aliabid94](https://github.com/aliabid94) in [PR 3095](https://github.com/gradio-app/gradio/pull/3095)
- Fixes bug where video and file change event not working [@tomchang25](https://github.com/tomchang25) in [PR 3098](https://github.com/gradio-app/gradio/pull/3098)
- Fixes bug where static_video play and pause event not working [@tomchang25](https://github.com/tomchang25) in [PR 3098](https://github.com/gradio-app/gradio/pull/3098)

## Documentation Changes:
>>>>>>> 2cf3e25c (fix changelog)
- Fix a broken link in the Quick Start guide, by [@cakiki](https://github.com/cakiki) in [PR 3109](https://github.com/gradio-app/gradio/pull/3109)
>>>>>>> 4d94d4b3 ([Minor] Correct link (#3109))
## Testing and Infrastructure Changes:
No changes to highlight.

## Breaking Changes:
No changes to highlight.

## Full Changelog:
* Set minimum `markdown-it-py` version to `2.0.0` so that the dollar math plugin is compatible by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3102](https://github.com/gradio-app/gradio/pull/3102)

## Contributors Shoutout:
No changes to highlight.

# Version 3.17.0

## New Features:

Expand All @@ -25,14 +88,22 @@ chatbot.launch()

By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3011](https://github.com/gradio-app/gradio/pull/3011)

### Download Button added to Model3D Output Component
### Download Button added to Model3D Output Component 📥

No need for an additional file output component to enable model3d file downloads anymore. We now added a download button to the model3d component itself.

<img width="739" alt="Screenshot 2023-01-18 at 3 52 45 PM" src="https://user-images.githubusercontent.com/12725292/213294198-5f4fda35-bde7-450c-864f-d5683e7fa29a.png">

By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3014](https://github.com/gradio-app/gradio/pull/3014)

### Fixing Auth on Spaces 🔑

Authentication on spaces works now! Third party cookies must be enabled on your browser to be able
to log in. Some browsers disable third party cookies by default (Safari, Chrome Incognito).

![auth_spaces](https://user-images.githubusercontent.com/41651716/215528417-09538933-0576-4d1d-b3b9-1e877ab01905.gif)


## Bug Fixes:
* Fixes bug where interpretation event was not configured correctly by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2993](https://github.com/gradio-app/gradio/pull/2993)
* Fix relative import bug in reload mode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2992](https://github.com/gradio-app/gradio/pull/2992)
Expand All @@ -55,7 +126,14 @@ By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3014](https://github.
* Fix bug where the queue was not properly restarted after launching a `closed` app by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3022](https://github.com/gradio-app/gradio/pull/3022)
* Adding missing embedded components on docs by [@aliabd](https://github.com/aliabd) in [PR 3027](https://github.com/gradio-app/gradio/pull/3027)
* Fixes bug where app would crash if the `file_types` parameter of `gr.File` or `gr.UploadButton` was not a list by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3048](https://github.com/gradio-app/gradio/pull/3048)
* Ensure CSS mounts correctly regardless of how many Gradio instances are on the page [@pngwn](https://github.com/pngwn) in [PR 3059](https://github.com/gradio-app/gradio/pull/3059).
* Fix bug where input component was not hidden in the frontend for `UploadButton` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3053](https://github.com/gradio-app/gradio/pull/3053)
* Fixes issue where after clicking submit or undo, the sketch output wouldn't clear. [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3047](https://github.com/gradio-app/gradio/pull/3047)
* Ensure spaces embedded via the web component always use the correct URLs for server requests and change ports for testing to avoid strange collisions when users are working with embedded apps locally by [@pngwn](https://github.com/pngwn) in [PR 3065](https://github.com/gradio-app/gradio/pull/3065)
* Preserve selected image of Gallery through updated by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3061](https://github.com/gradio-app/gradio/pull/3061)
* Fix bug where auth was not respected on HF spaces by [@freddyaboulton](https://github.com/freddyaboulton) and [@aliabid94](https://github.com/aliabid94) in [PR 3049](https://github.com/gradio-app/gradio/pull/3049)
* Fixes bug where tabs selected attribute not working if manually change tab by [@tomchang25](https://github.com/tomchang25) in [3055](https://github.com/gradio-app/gradio/pull/3055)
* Change chatbot to show dots on progress, and fix bug where chatbot would not stick to bottom in the case of images by [@aliabid94](https://github.com/aliabid94) in [PR 3067](https://github.com/gradio-app/gradio/pull/3079)

## Documentation Changes:
* SEO improvements to guides by[@aliabd](https://github.com/aliabd) in [PR 2915](https://github.com/gradio-app/gradio/pull/2915)
Expand Down Expand Up @@ -1895,4 +1973,4 @@ We've introduced a lot of new components in `3.0`, including `Model3D`, `Dataset
* [@NimaBoscarino](https://github.com/NimaBoscarino) made their first contribution in [PR 1000](https://github.com/gradio-app/gradio/pull/1000)
* [@ronvoluted](https://github.com/ronvoluted) made their first contribution in [PR 1050](https://github.com/gradio-app/gradio/pull/1050)
* [@radames](https://github.com/radames) made their first contribution in [PR 1074](https://github.com/gradio-app/gradio/pull/1074)
* [@freddyaboulton](https://github.com/freddyaboulton) made their first contribution in [PR 1085](https://github.com/gradio-app/gradio/pull/1085)
* [@freddyaboulton](https://github.com/freddyaboulton) made their first contribution in [PR 1085](https://github.com/gradio-app/gradio/pull/1085)
Binary file added demo/event_trigger/img/a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/event_trigger/img/b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/event_trigger/mp4/a.mp4
Binary file not shown.
Binary file added demo/event_trigger/mp4/b.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions demo/event_trigger/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: 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}
142 changes: 142 additions & 0 deletions demo/event_trigger/run.py
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()
3 changes: 2 additions & 1 deletion gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,7 @@ def reverse(text):
self.server = server
self.is_running = True
self.is_colab = utils.colab_check()
self.is_kaggle = utils.kaggle_check()
self.protocol = (
"https"
if self.local_url.startswith("https") or self.is_colab
Expand All @@ -1405,7 +1406,7 @@ def reverse(text):
share
if share is not None
else True
if self.is_colab and self.enable_queue
if (self.is_colab and self.enable_queue) or self.is_kaggle
else False
)

Expand Down
7 changes: 6 additions & 1 deletion gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def to_binary(x: str | Dict) -> bytes:
def decode_base64_to_image(encoding: str) -> Image.Image:
content = encoding.split(";")[1]
image_encoded = content.split(",")[1]
return Image.open(BytesIO(base64.b64decode(image_encoded)))
img = Image.open(BytesIO(base64.b64decode(image_encoded)))
exif = img.getexif()
# 274 is the code for image rotation and 1 means "correct orientation"
if exif.get(274, 1) != 1 and hasattr(ImageOps, "exif_transpose"):
img = ImageOps.exif_transpose(img)
return img


def encode_url_or_file_to_base64(path: str | Path, encryption_key: bytes | None = None):
Expand Down
Loading

0 comments on commit b786e91

Please sign in to comment.