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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add styles to gallery component #3586

Merged
merged 67 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5c00a30
update gallery styles
dawoodkhan82 Mar 22, 2023
1c0a71b
Merge branch 'main' into gallery-style
dawoodkhan82 Mar 22, 2023
40433fa
Merge branch 'main' into gallery-style
dawoodkhan82 Mar 23, 2023
b3a06e5
Set theme name from load (#3595)
freddyaboulton Mar 23, 2023
d306d52
Trigger event when Slider number input is released (#3589)
freddyaboulton Mar 23, 2023
c59a4c1
Sets up the Python `gradio` client (#3300)
abidlabs Mar 23, 2023
d2ccec2
Translate "or" for i18n (#3599)
freddyaboulton Mar 24, 2023
4c0e56e
Fixes Blocks exit issue (#3600)
abidlabs Mar 24, 2023
632ab4f
Use gradio-api-server for telemetry (#3488)
dawoodkhan82 Mar 24, 2023
674bb02
Simplify tests (#3608)
abidlabs Mar 24, 2023
c8f7cdf
fix wc error in dev mode (#3572)
pngwn Mar 24, 2023
27abab5
A few small fixes to docs / demos (#3611)
abidlabs Mar 24, 2023
80b00af
Add docs for HF Json saver (#3604)
osanseviero Mar 27, 2023
c520985
ensure css loads before mounting app (#3573)
pngwn Mar 27, 2023
3406e5b
fix issue with missing version (#3632)
aliabd Mar 27, 2023
a4b048c
Fixes chatbot autoscroll + Textbox lines > 20 issue (#3637)
dawoodkhan82 Mar 27, 2023
1dc651f
Fix embedded demos (#3638)
freddyaboulton Mar 27, 2023
d63f180
Add Windows CI (#3628)
space-nuko Mar 27, 2023
46b7bd0
move files (#3605)
pngwn Mar 27, 2023
ac740a9
Support empty lists being used in `gr.Dataframe` (#3646)
space-nuko Mar 27, 2023
3962904
Fix windows flake (#3650)
abidlabs Mar 28, 2023
393dc46
Raise errror if event queued but queue is not enabled (#3640)
freddyaboulton Mar 28, 2023
1735515
Copy everything in website Dockerfile, fix build issues (#3659)
aliabd Mar 28, 2023
d0fde4a
Correct the documentation of `gr.File` component (#3660)
RussellLuo Mar 28, 2023
36974b8
Nit in ValueError (#3669)
osanseviero Mar 28, 2023
9c29653
Load upstream theme (#3641)
abidlabs Mar 28, 2023
3c50d84
Add job for python client ci (#3674)
freddyaboulton Mar 28, 2023
a4f039d
Hide dropdown if in single-select mode (#3678)
space-nuko Mar 29, 2023
6f4da1c
Fix default parameters value and gr.Progress in same function (#3671)
space-nuko Mar 29, 2023
057c29d
warning
dawoodkhan82 Mar 29, 2023
1a877ac
Merge branch 'main' into gallery-style
dawoodkhan82 Mar 29, 2023
4f6c709
changelog
dawoodkhan82 Mar 29, 2023
166e310
ghangelog
dawoodkhan82 Mar 29, 2023
9d4d489
changelog
dawoodkhan82 Mar 29, 2023
7ce9a71
object fit optional
dawoodkhan82 Mar 29, 2023
60675d0
Merge branch 'main' into gallery-style
pngwn Mar 29, 2023
15fce3c
Add status for Python Client Jobs (#3645)
freddyaboulton Mar 29, 2023
b9db510
Fix broken spaces in docs (#3698)
aliabd Mar 29, 2023
015bf3e
Add download button for video (#3581)
freddyaboulton Mar 29, 2023
d987699
Fix outdated sharing your app guide (#3699)
aliabd Mar 29, 2023
e9c6fcd
Add orig_name field to video outputs (#3700)
freddyaboulton Mar 30, 2023
76fbd36
Theme builder (#3664)
aliabid94 Mar 30, 2023
a0a198d
fix dropdowns, release 3.24 (#3713)
aliabid94 Mar 30, 2023
4368296
New Version Docs (#3715)
github-actions[bot] Mar 30, 2023
a7b9434
Fix chatbot newline issue (#3717)
aliabid94 Mar 31, 2023
b43a318
New Version Docs (#3720)
github-actions[bot] Mar 31, 2023
e9c8994
Fix Serializer Mapping (#3722)
freddyaboulton Apr 1, 2023
64181c3
Fix some bugs related to Python client (#3721)
abidlabs Apr 2, 2023
090da90
node support for js client (#3692)
pngwn Apr 3, 2023
b146382
Support IPv6 addresses for --server-name (#3695)
dsully Apr 3, 2023
8795665
Increase timeout for analytics request + remove exception print (#3647)
dawoodkhan82 Apr 3, 2023
a3048e0
Switch linting to Ruff (#3710)
akx Apr 3, 2023
15e9207
Fix missing docstrings (new PR) (#3740)
abidlabs Apr 3, 2023
b82e6e0
import (#3742)
abidlabs Apr 4, 2023
117ae1d
Import Literal from typing extensions in client (#3741)
freddyaboulton Apr 4, 2023
3c6c621
Access http token for ws connection (#3735)
freddyaboulton Apr 4, 2023
b90e052
Add root_url to serializers in gradio_client (#3736)
freddyaboulton Apr 4, 2023
8e93f8a
CI tweaks (#3752)
freddyaboulton Apr 4, 2023
b41335a
Adds a pypi release action for the gradio python client (#3743)
abidlabs Apr 4, 2023
3cb4b3f
Get Intermediate Results from Python Client (#3694)
freddyaboulton Apr 4, 2023
a900ca4
changes (#3760)
abidlabs Apr 4, 2023
e5356a5
Make Client Jobs Iterable (#3762)
freddyaboulton Apr 5, 2023
ca0ca00
changelog
dawoodkhan82 Apr 5, 2023
356327e
merge
dawoodkhan82 Apr 5, 2023
b66a8ed
notebooks
dawoodkhan82 Apr 5, 2023
692ce39
Merge branch 'main' into gallery-style
dawoodkhan82 Apr 5, 2023
4621c58
Merge branch 'main' into gallery-style
dawoodkhan82 Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ No changes to highlight.

- Increase timeout for sending analytics data by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3647](https://github.com/gradio-app/gradio/pull/3647)
- Fix bug where http token was not accessed over websocket connections by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3735](https://github.com/gradio-app/gradio/pull/3735)
- Add ability to specify `rows`, `columns` and `object-fit` in `style()` for `gr.Gallery()` component by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3586](https://github.com/gradio-app/gradio/pull/3586)
- Fix bug where recording an audio file through the microphone resulted in a corrupted file name by [@abidlabs](https://github.com/abidlabs) in [PR 3770](https://github.com/gradio-app/gradio/pull/3770)

## Documentation Changes:
Expand Down
2 changes: 1 addition & 1 deletion demo/fake_gan/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: fake_gan\n", "### This is a fake GAN that shows how to create a text-to-image interface for image generation. Check out the Stable Diffusion demo for more: https://hf.co/spaces/stabilityai/stable-diffusion/\n", " "]}, {"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('files')\n", "!wget -q -O files/cheetah1.jpg https://github.com/gradio-app/gradio/raw/main/demo/fake_gan/files/cheetah1.jpg"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["# This demo needs to be run from the repo folder.\n", "# python demo/fake_gan/run.py\n", "import random\n", "\n", "import gradio as gr\n", "\n", "\n", "def fake_gan():\n", " images = [\n", " (random.choice(\n", " [\n", " \"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80\",\n", " \"https://images.unsplash.com/photo-1554151228-14d9def656e4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=386&q=80\",\n", " \"https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW4lMjBmYWNlfGVufDB8fDB8fA%3D%3D&w=1000&q=80\",\n", " \"https://images.unsplash.com/photo-1546456073-92b9f0a8d413?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80\",\n", " \"https://images.unsplash.com/photo-1601412436009-d964bd02edbc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80\",\n", " ]\n", " ), f\"label {i}\" if i != 0 else \"label\" * 50)\n", " for i in range(3)\n", " ]\n", " return images\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Column(variant=\"panel\"):\n", " with gr.Row(variant=\"compact\"):\n", " text = gr.Textbox(\n", " label=\"Enter your prompt\",\n", " show_label=False,\n", " max_lines=1,\n", " placeholder=\"Enter your prompt\",\n", " ).style(\n", " container=False,\n", " )\n", " btn = gr.Button(\"Generate image\").style(full_width=False)\n", "\n", " gallery = gr.Gallery(\n", " label=\"Generated images\", show_label=False, elem_id=\"gallery\"\n", " ).style(grid=[2], height=\"auto\")\n", "\n", " btn.click(fake_gan, None, gallery)\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: fake_gan\n", "### This is a fake GAN that shows how to create a text-to-image interface for image generation. Check out the Stable Diffusion demo for more: https://hf.co/spaces/stabilityai/stable-diffusion/\n", " "]}, {"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('files')\n", "!wget -q -O files/cheetah1.jpg https://github.com/gradio-app/gradio/raw/main/demo/fake_gan/files/cheetah1.jpg"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["# This demo needs to be run from the repo folder.\n", "# python demo/fake_gan/run.py\n", "import random\n", "\n", "import gradio as gr\n", "\n", "\n", "def fake_gan():\n", " images = [\n", " (random.choice(\n", " [\n", " \"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80\",\n", " \"https://images.unsplash.com/photo-1554151228-14d9def656e4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=386&q=80\",\n", " \"https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW4lMjBmYWNlfGVufDB8fDB8fA%3D%3D&w=1000&q=80\",\n", " \"https://images.unsplash.com/photo-1546456073-92b9f0a8d413?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80\",\n", " \"https://images.unsplash.com/photo-1601412436009-d964bd02edbc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80\",\n", " ]\n", " ), f\"label {i}\" if i != 0 else \"label\" * 50)\n", " for i in range(3)\n", " ]\n", " return images\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Column(variant=\"panel\"):\n", " with gr.Row(variant=\"compact\"):\n", " text = gr.Textbox(\n", " label=\"Enter your prompt\",\n", " show_label=False,\n", " max_lines=1,\n", " placeholder=\"Enter your prompt\",\n", " ).style(\n", " container=False,\n", " )\n", " btn = gr.Button(\"Generate image\").style(full_width=False)\n", "\n", " gallery = gr.Gallery(\n", " label=\"Generated images\", show_label=False, elem_id=\"gallery\"\n", " ).style(columns=[2], rows=[2], object_fit=\"contain\", height=\"auto\")\n", "\n", " btn.click(fake_gan, None, gallery)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
2 changes: 1 addition & 1 deletion demo/fake_gan/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def fake_gan():

gallery = gr.Gallery(
label="Generated images", show_label=False, elem_id="gallery"
).style(grid=[2], height="auto")
).style(columns=[2], rows=[2], object_fit="contain", height="auto")

btn.click(fake_gan, None, gallery)

Expand Down
18 changes: 16 additions & 2 deletions gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4060,25 +4060,39 @@ def style(
self,
*,
grid: int | Tuple | None = None,
columns: int | Tuple | None = None,
rows: int | Tuple | None = None,
height: str | None = None,
container: bool | None = None,
preview: bool | None = None,
object_fit: str | None = None,
**kwargs,
):
"""
This method can be used to change the appearance of the gallery component.
Parameters:
grid: Represents the number of images that should be shown in one row, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). if fewer that 6 are given then the last will be used for all subsequent breakpoints
grid: ('grid' has been renamed to 'columns') Represents the number of images that should be shown in one row, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). if fewer that 6 are given then the last will be used for all subsequent breakpoints columns: Represents the number of columns in the image grid, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). if fewer that 6 are given then the last will be used for all subsequent breakpoints
rows: Represents the number of rows in the image grid, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). if fewer that 6 are given then the last will be used for all subsequent breakpoints
height: Height of the gallery.
container: If True, will place gallery in a container - providing some extra padding around the border.
preview: If True, will display the Gallery in preview mode, which shows all of the images as thumbnails and allows the user to click on them to view them in full size.
object_fit: CSS object-fit property for the thumbnail images in the gallery. Can be "contain", "cover", "fill", "none", or "scale-down".
"""
if grid is not None:
self._style["grid"] = grid
warnings.warn(
"The 'grid' parameter will be deprecated. Please use 'columns' instead.",
)
self._style["grid_cols"] = grid
if columns is not None:
self._style["grid_cols"] = columns
if rows is not None:
self._style["grid_rows"] = rows
if height is not None:
self._style["height"] = height
if preview is not None:
self._style["preview"] = preview
if object_fit is not None:
self._style["object_fit"] = object_fit

Component.style(self, container=container, **kwargs)
return self
Expand Down
14 changes: 9 additions & 5 deletions js/gallery/src/Gallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
export let root: string = "";
export let root_url: null | string = null;
export let value: Array<string> | Array<FileData> | null = null;
export let style: Styles = { grid: [2], height: "auto" };
export let style: Styles = {
grid_cols: [2],
object_fit: "cover",
height: "auto"
};

const dispatch = createEventDispatcher<{
select: SelectData;
Expand Down Expand Up @@ -123,8 +127,7 @@
$: can_zoom = window_height >= height;

function add_height_to_styles(style: Styles): string {
styles = get_styles(style, ["grid"]).styles;

styles = get_styles(style, ["grid_cols", "grid_rows", "object_fit"]).styles;
return styles + ` height: ${style.height}`;
}

Expand Down Expand Up @@ -312,7 +315,7 @@
width: var(--size-full);
height: var(--size-full);
overflow: hidden;
object-fit: cover;
object-fit: var(--object-fit);
}

.grid-wrap {
Expand All @@ -323,6 +326,7 @@

.grid-container {
display: grid;
grid-template-rows: var(--grid-rows);
grid-template-columns: var(--grid-cols);
gap: var(--spacing-lg);
}
Expand Down Expand Up @@ -356,7 +360,7 @@
width: var(--size-full);
height: var(--size-full);
overflow: hidden;
object-fit: cover;
object-fit: var(--object-fit);
}

.thumbnail-lg:hover .caption-label {
Expand Down
30 changes: 24 additions & 6 deletions js/utils/src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Styles {
container?: boolean;
grid?: number | Array<number>;
grid_cols?: number | Array<number>;
grid_rows?: number | Array<number>;
height?: "auto" | string | number;
width?: "auto" | string | number;
full_width?: boolean;
Expand All @@ -12,6 +13,7 @@ export interface Styles {
gap?: boolean;
size?: "sm" | "lg";
preview?: boolean;
object_fit?: "contain" | "cover" | "fill" | "none" | "scale-down";
show_copy_button?: boolean;
}

Expand Down Expand Up @@ -63,15 +65,28 @@ const style_handlers: StyleHandlers = {
? ""
: `border-width: 0; box-shadow: none; overflow: visible; background: transparent;`;
},
grid(grid) {
let grid_map = ["", "sm-", "md-", "lg-", "xl-", "2xl-"];
let _grid = Array.isArray(grid) ? grid : [grid];
grid_cols(grid_cols) {
let grid_cols_map = ["", "sm-", "md-", "lg-", "xl-", "2xl-"];
let _grid_cols = Array.isArray(grid_cols) ? grid_cols : [grid_cols];

return [0, 0, 0, 0, 0, 0]
.map(
(_, i) =>
`--${grid_map[i]}grid-cols: var(--grid-${
_grid?.[i] || _grid?.[_grid?.length - 1]
`--${grid_cols_map[i]}grid-cols: var(--grid-${
_grid_cols?.[i] || _grid_cols?.[_grid_cols?.length - 1]
});`
)
.join(" ");
},
grid_rows(grid_rows) {
let grid_rows_map = ["", "sm-", "md-", "lg-", "xl-", "2xl-"];
let _grid_rows = Array.isArray(grid_rows) ? grid_rows : [grid_rows];

return [0, 0, 0, 0, 0, 0]
.map(
(_, i) =>
`--${grid_rows_map[i]}grid-rows: var(--grid-${
_grid_rows?.[i] || _grid_rows?.[_grid_rows?.length - 1]
});`
)
.join(" ");
Expand All @@ -92,6 +107,9 @@ const style_handlers: StyleHandlers = {
},
item_container(visible) {
return visible ? "" : "border-width:0;";
},
object_fit(object_fit) {
return `--object-fit: ${object_fit};`;
}
} as const;

Expand Down