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

Resize images for the UI to improve load times on slow networks #142

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion src/invoke_training/ui/pages/data_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import gradio as gr
from PIL import Image

from invoke_training._shared.data.datasets.image_caption_jsonl_dataset import (
CAPTION_COLUMN_DEFAULT,
Expand Down Expand Up @@ -174,9 +175,16 @@ def _update_state(self, idx: int):
if 0 <= idx and idx < len(self._dataset):
beyond_limits = False
example = self._dataset[idx]
image = example["image"]
image: Image.Image = example["image"]
caption = example["caption"]

# Resize the image to have a max dimension of 1024. On slow connections, sending the full-size image can be
# very slow.
max_dim = 1024
if image.width > max_dim or image.height > max_dim:
scale = max_dim / max(image.width, image.height)
image = image.resize((int(image.width * scale), int(image.height * scale)))

jsonl_str = "\n".join([example.model_dump_json() for example in self._dataset.examples])
return {
self._select_dataset_group: gr.Group(visible=self._dataset is None),
Expand Down
Loading