From 4837e578b27d781077cdb193d9eee5daea5b13a8 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Mon, 12 Aug 2024 12:00:14 -0400 Subject: [PATCH] api: update dir path for style preset images, update payload for create/update formdata --- invokeai/app/api/dependencies.py | 4 ++-- invokeai/app/api/routers/style_presets.py | 22 ++++++++++++++----- .../app/services/config/config_default.py | 8 +++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/invokeai/app/api/dependencies.py b/invokeai/app/api/dependencies.py index f81b7122f5..c7981e6f5a 100644 --- a/invokeai/app/api/dependencies.py +++ b/invokeai/app/api/dependencies.py @@ -76,7 +76,7 @@ class ApiDependencies: image_files = DiskImageFileStorage(f"{output_folder}/images") model_images_folder = config.models_path - style_preset_images_folder = config.style_preset_images_path + style_presets_folder = config.style_presets_path db = init_db(config=config, logger=logger, image_files=image_files) @@ -113,7 +113,7 @@ class ApiDependencies: urls = LocalUrlService() workflow_records = SqliteWorkflowRecordsStorage(db=db) style_preset_records = SqliteStylePresetRecordsStorage(db=db) - style_preset_image_files = StylePresetImageFileStorageDisk(style_preset_images_folder / "style_preset_images") + style_preset_image_files = StylePresetImageFileStorageDisk(style_presets_folder / "images") services = InvocationServices( board_image_records=board_image_records, diff --git a/invokeai/app/api/routers/style_presets.py b/invokeai/app/api/routers/style_presets.py index 8f377d72a3..c71174bba7 100644 --- a/invokeai/app/api/routers/style_presets.py +++ b/invokeai/app/api/routers/style_presets.py @@ -1,4 +1,5 @@ import io +import json import traceback from typing import Optional @@ -49,9 +50,7 @@ async def get_style_preset( async def update_style_preset( image: Optional[UploadFile] = File(description="The image file to upload", default=None), style_preset_id: str = Path(description="The id of the style preset to update"), - name: str = Form(description="The name of the style preset to create"), - positive_prompt: str = Form(description="The positive prompt of the style preset"), - negative_prompt: str = Form(description="The negative prompt of the style preset"), + data: str = Form(description="The data of the style preset to update"), ) -> StylePresetRecordWithImage: """Updates a style preset""" if image is not None: @@ -76,6 +75,12 @@ async def update_style_preset( except StylePresetImageFileNotFoundException: pass + parsed_data = json.loads(data) + + name = parsed_data.get("name", "") + positive_prompt = parsed_data.get("positive_prompt", "") + negative_prompt = parsed_data.get("negative_prompt", "") + preset_data = PresetData(positive_prompt=positive_prompt, negative_prompt=negative_prompt) changes = StylePresetChanges(name=name, preset_data=preset_data) @@ -110,12 +115,17 @@ async def delete_style_preset( }, ) async def create_style_preset( - name: str = Form(description="The name of the style preset to create"), - positive_prompt: str = Form(description="The positive prompt of the style preset"), - negative_prompt: str = Form(description="The negative prompt of the style preset"), image: Optional[UploadFile] = File(description="The image file to upload", default=None), + data: str = Form(description="The data of the style preset to create"), ) -> StylePresetRecordWithImage: """Creates a style preset""" + + parsed_data = json.loads(data) + + name = parsed_data.get("name", "") + positive_prompt = parsed_data.get("positive_prompt", "") + negative_prompt = parsed_data.get("negative_prompt", "") + preset_data = PresetData(positive_prompt=positive_prompt, negative_prompt=negative_prompt) style_preset = StylePresetWithoutId(name=name, preset_data=preset_data) new_style_preset = ApiDependencies.invoker.services.style_preset_records.create(style_preset=style_preset) diff --git a/invokeai/app/services/config/config_default.py b/invokeai/app/services/config/config_default.py index 650f02a088..0327efa55a 100644 --- a/invokeai/app/services/config/config_default.py +++ b/invokeai/app/services/config/config_default.py @@ -154,7 +154,7 @@ class InvokeAIAppConfig(BaseSettings): db_dir: Path = Field(default=Path("databases"), description="Path to InvokeAI databases directory.") outputs_dir: Path = Field(default=Path("outputs"), description="Path to directory for outputs.") custom_nodes_dir: Path = Field(default=Path("nodes"), description="Path to directory for custom nodes.") - style_preset_images_dir: Path = Field(default=Path("style_preset_images"), description="Path to directory for style preset images.") + style_presets_dir: Path = Field(default=Path("style_presets"), description="Path to directory for style presets.") # LOGGING log_handlers: list[str] = Field(default=["console"], description='Log handler. Valid options are "console", "file=", "syslog=path|address:host:port", "http=".') @@ -303,9 +303,9 @@ class InvokeAIAppConfig(BaseSettings): return self._resolve(self.models_dir) @property - def style_preset_images_path(self) -> Path: - """Path to the style preset images directory, resolved to an absolute path..""" - return self._resolve(self.style_preset_images_dir) + def style_presets_path(self) -> Path: + """Path to the style presets directory, resolved to an absolute path..""" + return self._resolve(self.style_presets_dir) @property def convert_cache_path(self) -> Path: