From ee86eedf0145ed11fb6359ba99277f5b8ab8251e Mon Sep 17 00:00:00 2001 From: creachec <46060787+creachec@users.noreply.github.com> Date: Fri, 31 Mar 2023 17:22:00 -0300 Subject: [PATCH 1/3] Right link on pytorch installer for linux rocm Right link on pytorch installer for linux rocm --- installer/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/lib/installer.py b/installer/lib/installer.py index 8ab512eee8..42079cd90c 100644 --- a/installer/lib/installer.py +++ b/installer/lib/installer.py @@ -456,7 +456,7 @@ def get_torch_source() -> (Union[str, None],str): optional_modules = None if OS == "Linux": if device == "rocm": - url = "https://download.pytorch.org/whl/rocm5.2" + url = "https://download.pytorch.org/whl/rocm5.4.2" elif device == "cpu": url = "https://download.pytorch.org/whl/cpu" From ecdfa136a0ce5fcd219dacf0b17f7b71e401aa96 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 4 Apr 2023 00:18:11 +1000 Subject: [PATCH 2/3] fix(nodes): fix typo in `list_sessions` handler --- invokeai/app/api/routers/sessions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/invokeai/app/api/routers/sessions.py b/invokeai/app/api/routers/sessions.py index dc8fa03fc4..0316398088 100644 --- a/invokeai/app/api/routers/sessions.py +++ b/invokeai/app/api/routers/sessions.py @@ -51,7 +51,7 @@ async def list_sessions( query: str = Query(default="", description="The query string to search for"), ) -> PaginatedResults[GraphExecutionState]: """Gets a list of sessions, optionally searching""" - if filter == "": + if query == "": result = ApiDependencies.invoker.services.graph_execution_manager.list( page, per_page ) From aed9ecef2a85d5a9a86e58e16dc76ff875ccc559 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 3 Apr 2023 14:34:07 +1000 Subject: [PATCH 3/3] feat(nodes): add thumbnail generation to DiskImageStorage --- invokeai/app/api/routers/images.py | 10 ++++++++++ invokeai/app/services/image_storage.py | 10 +++++++++- invokeai/app/util/save_thumbnail.py | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 invokeai/app/util/save_thumbnail.py diff --git a/invokeai/app/api/routers/images.py b/invokeai/app/api/routers/images.py index 55f1a2f036..453c114a28 100644 --- a/invokeai/app/api/routers/images.py +++ b/invokeai/app/api/routers/images.py @@ -23,6 +23,16 @@ async def get_image( filename = ApiDependencies.invoker.services.images.get_path(image_type, image_name) return FileResponse(filename) +@images_router.get("/{image_type}/thumbnails/{image_name}", operation_id="get_thumbnail") +async def get_thumbnail( + image_type: ImageType = Path(description="The type of image to get"), + image_name: str = Path(description="The name of the image to get"), +): + """Gets a thumbnail""" + # TODO: This is not really secure at all. At least make sure only output results are served + filename = ApiDependencies.invoker.services.images.get_path(image_type, 'thumbnails/' + image_name) + return FileResponse(filename) + @images_router.post( "/uploads/", diff --git a/invokeai/app/services/image_storage.py b/invokeai/app/services/image_storage.py index ad0ff23f14..c80a4bfb31 100644 --- a/invokeai/app/services/image_storage.py +++ b/invokeai/app/services/image_storage.py @@ -9,6 +9,7 @@ from queue import Queue from typing import Dict from PIL.Image import Image +from invokeai.app.util.save_thumbnail import save_thumbnail from invokeai.backend.image_util import PngWriter @@ -66,6 +67,9 @@ class DiskImageStorage(ImageStorageBase): Path(os.path.join(output_folder, image_type)).mkdir( parents=True, exist_ok=True ) + Path(os.path.join(output_folder, image_type, "thumbnails")).mkdir( + parents=True, exist_ok=True + ) def get(self, image_type: ImageType, image_name: str) -> Image: image_path = self.get_path(image_type, image_name) @@ -87,7 +91,11 @@ class DiskImageStorage(ImageStorageBase): self.__pngWriter.save_image_and_prompt_to_png( image, "", image_subpath, None ) # TODO: just pass full path to png writer - + save_thumbnail( + image=image, + filename=image_name, + path=os.path.join(self.__output_folder, image_type, "thumbnails"), + ) image_path = self.get_path(image_type, image_name) self.__set_cache(image_path, image) diff --git a/invokeai/app/util/save_thumbnail.py b/invokeai/app/util/save_thumbnail.py new file mode 100644 index 0000000000..86fdbe7ef6 --- /dev/null +++ b/invokeai/app/util/save_thumbnail.py @@ -0,0 +1,25 @@ +import os +from PIL import Image + + +def save_thumbnail( + image: Image.Image, + filename: str, + path: str, + size: int = 256, +) -> str: + """ + Saves a thumbnail of an image, returning its path. + """ + base_filename = os.path.splitext(filename)[0] + thumbnail_path = os.path.join(path, base_filename + ".webp") + + if os.path.exists(thumbnail_path): + return thumbnail_path + + image_copy = image.copy() + image_copy.thumbnail(size=(size, size)) + + image_copy.save(thumbnail_path, "WEBP") + + return thumbnail_path