Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to display gallery in preview mode #3345

Merged
merged 2 commits into from Feb 28, 2023

Conversation

freddyaboulton
Copy link
Collaborator

@freddyaboulton freddyaboulton commented Feb 28, 2023

Description

Fixes #3311

  • If style=True and the gallery is in a "Cleared State", i.e. value is [] or None, then the next update should display the gallery in preview mode.
  • Otherwise, the behavior should be the same compared to main

To test,

import random

import gradio as gr
from PIL import Image


def create_images(n_images):

    a = Image.new("RGB", (512, 512), "red")
    b = Image.new("RGB", (512, 512), "green")
    c = Image.new("RGB", (512, 512), "blue")

    res = [a, b, c][:n_images]
    random.shuffle(res)
    return res

gr.Interface(create_images,
             inputs=[gr.Slider(value=3, minimum=1, maximum=3, step=1)],
             outputs=[gr.Gallery().style(grid=2, preview=True)]).launch()

gallery_preview

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

A note about the CHANGELOG

Hello 馃憢 and thank you for contributing to Gradio!

All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.

Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by [@myusername](link-to-your-github-profile) in [PR 11111](https://github.com/gradio-app/gradio/pull/11111)".

If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.

@gradio-pr-bot
Copy link
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-3345-all-demos

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks @freddyaboulton!

@freddyaboulton freddyaboulton force-pushed the 3311-display-gallery-in-preview-mode branch from cd8417b to 6d7cc20 Compare February 28, 2023 17:28
@freddyaboulton freddyaboulton marked this pull request as ready for review February 28, 2023 17:40
@freddyaboulton
Copy link
Collaborator Author

Thank you for the review @pngwn ! 馃惂

@freddyaboulton freddyaboulton merged commit 9fbe7a0 into main Feb 28, 2023
@freddyaboulton freddyaboulton deleted the 3311-display-gallery-in-preview-mode branch February 28, 2023 17:41
dawoodkhan82 pushed a commit that referenced this pull request Mar 1, 2023
dawoodkhan82 added a commit that referenced this pull request Mar 9, 2023
* hub telemetry

* more analytics

* format

* changelog

* Gradio Status Page  (#3331)

* add status page to error message

* changelog

* link to status page on website

* move link to the right

* merge

* merge

* Add option to display gallery in preview mode (#3345)

* Add code + api

* CHANGELOG

* dropdown (#3338)

* fix

* fixes

* format

* changelog

* Update gradio/components.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* fix clear case

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Some improvements to Flag (#3289)

* Fixes to button disable

* button

* formatting

* flagging fix

* fixes

* formatter

* changelog

* ormatting

* tests

* saving

* adding optionality for flagging

* updatest

* error catching

* updates

* changelog

* tests

* typing

* flag button

* formatting

* tests

* tests

* tests

* increased latency

* queue fix

* clear

* formatting

* fix

* fix tests

* Fix flaky external test (#3348)

* Fix flaky external test

* CHANGELOG

* Undo accidental diff

* Fix flaky external test

* CHANGELOG

* Undo accidental diff

* Remove from changelog

* Use bunny file

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* updates

* format

* more updates

* threading

* fixes

* Fix error when using backen_fn and custom js at the same time (#3358)

* Fix error when using backen_fn and custom js at the same time

* generate notebooks

* update changelog

* changes

---------

Co-authored-by: Ali Abid <aabid94@gmail.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>

* Fix File updating (#3375)

* Fix

* Remove line

* Add unit test

* CHANGELOG

* Remove comment

* Updated chat ui (#3370)

* test

* changes

* chagnes

* changes

* changes

* changes

* changes

* Update CHANGELOG.md

* changes

* Update demo/chatbot_multimodal/run.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Update demo/chatbot_simple_demo/run.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* changes

* changes

* changes

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* fixes

* New Version Docs (#3376)

* [create-pull-request] automated change

* empty commit

* [create-pull-request] automated change

* empty commit

---------

Co-authored-by: abidlabs <abidlabs@users.noreply.github.com>
Co-authored-by: aliabd <ali.si3luwa@gmail.com>

* requirements

* test requirements

* Release 3.20.1 (#3390)

* release 3.20.1

* changelog

* merge

* New Version Docs (#3392)

* [create-pull-request] automated change

* trigger ci

---------

Co-authored-by: abidlabs <abidlabs@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* merge

* Remove everything related to encryption (#3396)

* remove requirements

* deprecate encrypt

* remove flagging

* deprecate

* formatting

* lint

* Adds a Chinese translation for the `README` (#3394)

* add chinese readme

* add chinese readme

* update changelog

* fix render_readme and english readme

* generate readme

* remove template and quickstart files

* link to chinese from english

* fix assets paths

* link to english from chinese

* change file location

* fix link

* fix link

* fix link

---------

Co-authored-by: aliabd <ali.si3luwa@gmail.com>

* fix bad codeblock (#3401)

* Always set queue=False if every is None for load events (#3391)

* Always set queue=False if every is None

* CHANGELOG + linting

* Move to latest release section

* changelog

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* JS client take 2 (#3388)

* start

* change api

* integrate into gradio

* log

* try this

* format

* changes

* format

* fix css

* fix file

* fix #3282 avoid in-place dict updates (#3405)

* fix #3282 avoid in-place dict updates

* add tests and changelog for PR3405

* Fix markdown embedded component in docs (#3410)

* revert to old md component demo

* changelog

* Added a section on security (#3408)

* security

* added section on security

* security

* changes from review

* Fix local tests (#3411)

* document embed params

* fix tests

* cleanup

* cleanup

* cleanup

* revert

* changelog

* Document web component parameters (#3407)

* document embed params

* changelog

* iframe

* fixed review changes

* requirements

* fixes

* format

* format

* requirements

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: Jialei <3217223+jialeicui@users.noreply.github.com>
Co-authored-by: Ali Abid <aabid94@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: abidlabs <abidlabs@users.noreply.github.com>
Co-authored-by: Uanu <92366232+uanu2002@users.noreply.github.com>
Co-authored-by: gitgithan <hanqi11991@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have option to display gallery in preview state
3 participants