Skip to content

Commit

Permalink
fix: normalise file
Browse files Browse the repository at this point in the history
  • Loading branch information
Col0ring committed Mar 1, 2024
1 parent f00f646 commit 59e76ea
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/components/WaterfallGallery/demos/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def resolve_assets(relative_path):
with gr.Blocks() as demo:
mgr.WaterfallGallery(
value=[
resolve_assets('bot.jpeg'),
resolve_assets('modelscope.svg'),
# pass a tuple
[resolve_assets('bot2.jpeg'), 'bot2'],
[resolve_assets('bot.jpeg'), 'bot'],
# pass a dict
{
"image": resolve_assets('user.jpeg'),
Expand Down
4 changes: 2 additions & 2 deletions docs/components/WaterfallGallery/demos/like_click_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def fn(data: gr.EventData):
with gr.Blocks() as demo:
gallery = mgr.WaterfallGallery(
value=[
resolve_assets('bot.jpeg'),
resolve_assets('modelscope.svg'),
# pass a tuple
[resolve_assets('bot2.jpeg'), 'bot2'],
[resolve_assets('bot.jpeg'), 'bot'],
# pass a dict
{
"image": resolve_assets('user.jpeg'),
Expand Down
6 changes: 3 additions & 3 deletions docs/components/WaterfallGallery/demos/load_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def resolve_assets(relative_path):

def load_more(_gallery):
time.sleep(1)
_gallery.append(resolve_assets('modelscope.svg'))
_gallery.append(resolve_assets('bot.jpeg'))
_gallery.append(resolve_assets('bot2.jpeg'))
_gallery.append(resolve_assets('user.jpeg'))
_gallery.append(resolve_assets('screen.jpeg'))
has_more = True
Expand All @@ -26,9 +26,9 @@ def load_more(_gallery):
with gr.Blocks() as demo:
gallery = mgr.WaterfallGallery(
value=[
resolve_assets('bot.jpeg'),
resolve_assets('modelscope.svg'),
# pass a tuple
[resolve_assets('bot2.jpeg'), 'bot2'],
[resolve_assets('bot.jpeg'), 'bot'],
# pass a dict
{
"image": resolve_assets('user.jpeg'),
Expand Down
4 changes: 2 additions & 2 deletions docs/components/WaterfallGallery/demos/responsive_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def fn():
with gr.Blocks() as demo:
gallery = mgr.WaterfallGallery(
value=[
resolve_assets('bot.jpeg'),
resolve_assets('modelscope.svg'),
# pass a tuple
[resolve_assets('bot2.jpeg'), 'bot2'],
[resolve_assets('bot.jpeg'), 'bot'],
# pass a dict
{
"image": resolve_assets('user.jpeg'),
Expand Down
Binary file removed docs/components/resources/bot2.jpeg
Binary file not shown.
1 change: 1 addition & 0 deletions docs/components/resources/modelscope.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/WaterfallGallery/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
export let object_fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down' =
'cover';
export let show_download_button = false;
export let root: string;
export let proxy_url: string;
export let gradio: Gradio<{
change: typeof value;
select: SelectData;
Expand Down Expand Up @@ -102,6 +104,8 @@
{label}
{action_label}
{value}
{root}
{proxy_url}
{show_label}
{object_fit}
load_more_button_props={_load_more_button_props}
Expand Down
11 changes: 10 additions & 1 deletion frontend/WaterfallGallery/shared/Gallery.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { BlockLabel, Empty, IconButton, ShareButton } from '@gradio/atoms';
import { BaseButton } from '@gradio/button';
import { type FileData, normalise_file } from '@gradio/client';
import { Download, Image as ImageIcon } from '@gradio/icons';
import { Loader } from '@gradio/statustracker';
import { ModifyUpload } from '@gradio/upload';
Expand Down Expand Up @@ -34,6 +35,8 @@
export let columns: number | number[] | Breakpoints | undefined = [2];
export let height: number | 'auto' = 'auto';
export let preview: boolean;
export let root: string;
export let proxy_url: string;
export let allow_preview = true;
export let show_share_button = false;
export let likeable: boolean;
Expand Down Expand Up @@ -100,7 +103,13 @@
$: was_reset = value == null || value.length === 0 ? true : was_reset;
let resolved_value: GalleryData | null = null;
$: resolved_value = value == null ? null : value;
$: resolved_value =
value == null
? null
: value.map((item) => {
item.image = normalise_file(item.image, root, proxy_url) as FileData;
return item;
});
let prev_value: GalleryData | null = value;
if (selected_index == null && preview && value?.length) {
selected_index = 0;
Expand Down

0 comments on commit 59e76ea

Please sign in to comment.