api: update dir path for style preset images, update payload for create/update formdata

This commit is contained in:
Mary Hipp 2024-08-12 12:00:14 -04:00
parent 1e547ef912
commit 4837e578b2
3 changed files with 22 additions and 12 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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=<path>", "syslog=path|address:host:port", "http=<url>".')
@ -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: