diff --git a/CHANGES.md b/CHANGES.md index 6e80fbbe..201a0249 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,16 @@ Our focus continues to remain on an easy installation experience, and an easy user-interface. While still remaining pretty powerful, in terms of features and speed. ### Detailed changelog +* 2.5.30 - 1 Apr 2023 - Slider to control the strength of the LoRA model. +* 2.5.30 - 28 Mar 2023 - Refactor task entry config to use a generating method. Added ability for plugins to easily add to this. Removed confusing sentence from `contributing.md` +* 2.5.30 - 28 Mar 2023 - Allow the user to undo the deletion of tasks or images, instead of showing a pop-up each time. The new `Undo` button will be present at the top of the UI. Thanks @JeLuf. +* 2.5.30 - 28 Mar 2023 - Support saving lossless WEBP images. Thanks @ogmaresca. +* 2.5.30 - 28 Mar 2023 - Lots of bug fixes for the UI (Read LoRA flag in metadata files, new prompt weight format with scrollwheel, fix overflow with lots of tabs, clear button in image editor, shorter filenames in download). Thanks @patriceac, @JeLuf and @ogmaresca. +* 2.5.29 - 27 Mar 2023 - Fix a bug where some non-square images would fail while inpainting with a `The size of tensor a must match size of tensor b` error. +* 2.5.29 - 27 Mar 2023 - Fix the `incorrect number of channels` error, when given a PNG image with an alpha channel in `Test Diffusers`. +* 2.5.29 - 27 Mar 2023 - Fix broken inpainting in `Test Diffusers` (beta). +* 2.5.28 - 24 Mar 2023 - Support for weighted prompts and long prompt lengths (not limited to 77 tokens). This change requires enabling the `Test Diffusers` setting in beta (in the Settings tab), and restarting the program. +* 2.5.27 - 21 Mar 2023 - LoRA support, accessible by enabling the `Test Diffusers` setting (in the Settings tab in the UI). This change switches the internal engine to diffusers (if the `Test Diffusers` setting is enabled). If the `Test Diffusers` flag is disabled, it'll have no impact for the user. * 2.5.26 - 15 Mar 2023 - Allow styling the buttons displayed on an image. Update the API to allow multiple buttons and text labels in a single row. Thanks @ogmaresca. * 2.5.26 - 15 Mar 2023 - View images in full-screen, by either clicking on the image, or clicking the "Full screen" icon next to the Seed number on the image. Thanks @ogmaresca for the internal API. * 2.5.25 - 14 Mar 2023 - Button to download all the images, and all the metadata as a zip file. This is available at the top of the UI, as well as on each image. Thanks @JeLuf. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 02ce6fc6..c01d489a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,8 +42,6 @@ or for Windows 10) Congrats, now any changes you make in your repo `ui` folder are linked to this running archive of the app and can be previewed in the browser. 11) Please update CHANGES.md in your pull requests. -Check the `ui/frontend/build/README.md` for instructions on running and building the React code. - ## Development environment for Installer changes Build the Windows installer using Windows, and the Linux installer using Linux. Don't mix the two, and don't use WSL. An Ubuntu VM is fine for building the Linux installer on a Windows host. diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index b742c17c..1b9ec588 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -95,7 +95,7 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install --upgrade sdkit==1.0.48 -q || ( + call python -m pip install --upgrade sdkit==1.0.63 -q || ( echo "Error updating sdkit" ) ) @@ -106,7 +106,7 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install sdkit==1.0.48 || ( + call python -m pip install sdkit==1.0.63 || ( echo "Error installing sdkit. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" pause exit /b diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index b62a2fc2..cf74349c 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -103,7 +103,7 @@ if python ../scripts/check_modules.py sdkit sdkit.models ldm transformers numpy export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - python -m pip install --upgrade sdkit==1.0.48 -q + python -m pip install --upgrade sdkit==1.0.63 -q fi else echo "Installing sdkit: https://pypi.org/project/sdkit/" @@ -111,7 +111,7 @@ else export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - if python -m pip install sdkit==1.0.48 ; then + if python -m pip install sdkit==1.0.63 ; then echo "Installed." else fail "sdkit install failed" diff --git a/ui/easydiffusion/model_manager.py b/ui/easydiffusion/model_manager.py index 116edf33..a06c56cf 100644 --- a/ui/easydiffusion/model_manager.py +++ b/ui/easydiffusion/model_manager.py @@ -7,13 +7,14 @@ from easydiffusion.utils import log from sdkit import Context from sdkit.models import load_model, unload_model, scan_model -KNOWN_MODEL_TYPES = ["stable-diffusion", "vae", "hypernetwork", "gfpgan", "realesrgan"] +KNOWN_MODEL_TYPES = ["stable-diffusion", "vae", "hypernetwork", "gfpgan", "realesrgan", "lora"] MODEL_EXTENSIONS = { "stable-diffusion": [".ckpt", ".safetensors"], "vae": [".vae.pt", ".ckpt", ".safetensors"], "hypernetwork": [".pt", ".safetensors"], "gfpgan": [".pth"], "realesrgan": [".pth"], + "lora": [".ckpt", ".safetensors"], } DEFAULT_MODELS = { "stable-diffusion": [ # needed to support the legacy installations @@ -23,7 +24,7 @@ DEFAULT_MODELS = { "gfpgan": ["GFPGANv1.3"], "realesrgan": ["RealESRGAN_x4plus"], } -MODELS_TO_LOAD_ON_START = ["stable-diffusion", "vae", "hypernetwork"] +MODELS_TO_LOAD_ON_START = ["stable-diffusion", "vae", "hypernetwork", "lora"] known_models = {} @@ -102,6 +103,7 @@ def reload_models_if_necessary(context: Context, task_data: TaskData): "gfpgan": task_data.use_face_correction, "realesrgan": task_data.use_upscale, "nsfw_checker": True if task_data.block_nsfw else None, + "lora": task_data.use_lora_model, } models_to_reload = { model_type: path @@ -125,6 +127,7 @@ def resolve_model_paths(task_data: TaskData): ) task_data.use_vae_model = resolve_model_to_use(task_data.use_vae_model, model_type="vae") task_data.use_hypernetwork_model = resolve_model_to_use(task_data.use_hypernetwork_model, model_type="hypernetwork") + task_data.use_lora_model = resolve_model_to_use(task_data.use_lora_model, model_type="lora") if task_data.use_face_correction: task_data.use_face_correction = resolve_model_to_use(task_data.use_face_correction, "gfpgan") @@ -184,11 +187,13 @@ def getModels(): "stable-diffusion": "sd-v1-4", "vae": "", "hypernetwork": "", + "lora": "", }, "options": { "stable-diffusion": ["sd-v1-4"], "vae": [], "hypernetwork": [], + "lora": [], }, } @@ -243,6 +248,7 @@ def getModels(): listModels(model_type="vae") listModels(model_type="hypernetwork") listModels(model_type="gfpgan") + listModels(model_type="lora") if models_scanned > 0: log.info(f"[green]Scanned {models_scanned} models. Nothing infected[/]") diff --git a/ui/easydiffusion/renderer.py b/ui/easydiffusion/renderer.py index c5dc88b4..c8004fee 100644 --- a/ui/easydiffusion/renderer.py +++ b/ui/easydiffusion/renderer.py @@ -10,7 +10,7 @@ from easydiffusion.utils import get_printable_request, save_images_to_disk, log from sdkit import Context from sdkit.generate import generate_images from sdkit.filter import apply_filters -from sdkit.utils import img_to_buffer, img_to_base64_str, latent_samples_to_images, gc +from sdkit.utils import img_to_buffer, img_to_base64_str, latent_samples_to_images, diffusers_latent_samples_to_images context = Context() # thread-local """ @@ -26,6 +26,13 @@ def init(device): context.temp_images = {} context.partial_x_samples = None + from easydiffusion import app + + app_config = app.getConfig() + context.test_diffusers = ( + app_config.get("test_diffusers", False) and app_config.get("update_branch", "main") != "main" + ) + device_manager.device_init(context, device) @@ -57,7 +64,13 @@ def make_images_internal( ): images, user_stopped = generate_images_internal( - req, task_data, data_queue, task_temp_images, step_callback, task_data.stream_image_progress, task_data.stream_image_progress_interval + req, + task_data, + data_queue, + task_temp_images, + step_callback, + task_data.stream_image_progress, + task_data.stream_image_progress_interval, ) filtered_images = filter_images(task_data, images, user_stopped) @@ -82,10 +95,18 @@ def generate_images_internal( ): context.temp_images.clear() - callback = make_step_callback(req, task_data, data_queue, task_temp_images, step_callback, stream_image_progress, stream_image_progress_interval) + callback = make_step_callback( + req, + task_data, + data_queue, + task_temp_images, + step_callback, + stream_image_progress, + stream_image_progress_interval, + ) try: - if req.init_image is not None: + if req.init_image is not None and not context.test_diffusers: req.sampler_name = "ddim" images = generate_images(context, callback=callback, **req.dict()) @@ -94,10 +115,14 @@ def generate_images_internal( images = [] user_stopped = True if context.partial_x_samples is not None: - images = latent_samples_to_images(context, context.partial_x_samples) + if context.test_diffusers: + images = diffusers_latent_samples_to_images(context, context.partial_x_samples) + else: + images = latent_samples_to_images(context, context.partial_x_samples) finally: if hasattr(context, "partial_x_samples") and context.partial_x_samples is not None: - del context.partial_x_samples + if not context.test_diffusers: + del context.partial_x_samples context.partial_x_samples = None return images, user_stopped @@ -124,7 +149,7 @@ def filter_images(task_data: TaskData, images: list, user_stopped): def construct_response(images: list, seeds: list, task_data: TaskData, base_seed: int): return [ ResponseImage( - data=img_to_base64_str(img, task_data.output_format, task_data.output_quality), + data=img_to_base64_str(img, task_data.output_format, task_data.output_quality, task_data.output_lossless), seed=seed, ) for img, seed in zip(images, seeds) @@ -145,7 +170,12 @@ def make_step_callback( def update_temp_img(x_samples, task_temp_images: list): partial_images = [] - images = latent_samples_to_images(context, x_samples) + + if context.test_diffusers: + images = diffusers_latent_samples_to_images(context, x_samples) + else: + images = latent_samples_to_images(context, x_samples) + if task_data.block_nsfw: images = apply_filters(context, "nsfw_checker", images) @@ -158,17 +188,21 @@ def make_step_callback( del images return partial_images - def on_image_step(x_samples, i): + def on_image_step(x_samples, i, *args): nonlocal last_callback_time - context.partial_x_samples = x_samples + if context.test_diffusers: + context.partial_x_samples = (x_samples, args[0]) + else: + context.partial_x_samples = x_samples + step_time = time.time() - last_callback_time if last_callback_time != -1 else -1 last_callback_time = time.time() progress = {"step": i, "step_time": step_time, "total_steps": n_steps} if stream_image_progress and stream_image_progress_interval > 0 and i % stream_image_progress_interval == 0: - progress["output"] = update_temp_img(x_samples, task_temp_images) + progress["output"] = update_temp_img(context.partial_x_samples, task_temp_images) data_queue.put(json.dumps(progress)) diff --git a/ui/easydiffusion/server.py b/ui/easydiffusion/server.py index 1d05a1f0..e27f9c5b 100644 --- a/ui/easydiffusion/server.py +++ b/ui/easydiffusion/server.py @@ -29,10 +29,10 @@ NOCACHE_HEADERS = {"Cache-Control": "no-cache, no-store, must-revalidate", "Prag class NoCacheStaticFiles(StaticFiles): def __init__(self, directory: str): # follow_symlink is only available on fastapi >= 0.92.0 - if (os.path.islink(directory)): - super().__init__(directory = os.path.realpath(directory)) + if os.path.islink(directory): + super().__init__(directory=os.path.realpath(directory)) else: - super().__init__(directory = directory) + super().__init__(directory=directory) def is_not_modified(self, response_headers, request_headers) -> bool: if "content-type" in response_headers and ( @@ -51,11 +51,12 @@ class SetAppConfigRequest(BaseModel): ui_open_browser_on_start: bool = None listen_to_network: bool = None listen_port: int = None + test_diffusers: bool = False def init(): mimetypes.init() - mimetypes.add_type('text/css', '.css') + mimetypes.add_type("text/css", ".css") if os.path.isdir(app.CUSTOM_MODIFIERS_DIR): server_api.mount( @@ -132,6 +133,9 @@ def set_app_config_internal(req: SetAppConfigRequest): if "net" not in config: config["net"] = {} config["net"]["listen_port"] = int(req.listen_port) + + config["test_diffusers"] = req.test_diffusers + try: app.setConfig(config) diff --git a/ui/easydiffusion/types.py b/ui/easydiffusion/types.py index 8e7044f3..bbec0afa 100644 --- a/ui/easydiffusion/types.py +++ b/ui/easydiffusion/types.py @@ -21,6 +21,7 @@ class GenerateImageRequest(BaseModel): sampler_name: str = None # "ddim", "plms", "heun", "euler", "euler_a", "dpm2", "dpm2_a", "lms" hypernetwork_strength: float = 0 + lora_alpha: float = 0 class TaskData(BaseModel): @@ -36,11 +37,13 @@ class TaskData(BaseModel): # use_stable_diffusion_config: str = "v1-inference" use_vae_model: str = None use_hypernetwork_model: str = None + use_lora_model: str = None show_only_filtered_image: bool = False block_nsfw: bool = False output_format: str = "jpeg" # or "png" or "webp" output_quality: int = 75 + output_lossless: bool = False metadata_output_format: str = "txt" # or "json" stream_image_progress: bool = False stream_image_progress_interval: int = 5 diff --git a/ui/easydiffusion/utils/save_utils.py b/ui/easydiffusion/utils/save_utils.py index 6012bc44..950f04b0 100644 --- a/ui/easydiffusion/utils/save_utils.py +++ b/ui/easydiffusion/utils/save_utils.py @@ -27,6 +27,8 @@ TASK_TEXT_MAPPING = { "use_vae_model": "VAE model", "use_hypernetwork_model": "Hypernetwork model", "hypernetwork_strength": "Hypernetwork Strength", + "use_lora_model": "LoRA model", + # "lora_alpha": "LoRA Strength", } @@ -43,15 +45,18 @@ def save_images_to_disk(images: list, filtered_images: list, req: GenerateImageR file_name=make_filename, output_format=task_data.output_format, output_quality=task_data.output_quality, + output_lossless=task_data.output_lossless, ) - if task_data.metadata_output_format.lower() in ["json", "txt", "embed"]: - save_dicts( - metadata_entries, - save_dir_path, - file_name=make_filename, - output_format=task_data.metadata_output_format, - file_format=task_data.output_format, - ) + if task_data.metadata_output_format: + for metadata_output_format in task_data.metadata_output_format.split(','): + if metadata_output_format.lower() in ["json", "txt", "embed"]: + save_dicts( + metadata_entries, + save_dir_path, + file_name=make_filename, + output_format=metadata_output_format, + file_format=task_data.output_format, + ) else: make_filter_filename = make_filename_callback(req, now=now, suffix="filtered") @@ -61,6 +66,7 @@ def save_images_to_disk(images: list, filtered_images: list, req: GenerateImageR file_name=make_filename, output_format=task_data.output_format, output_quality=task_data.output_quality, + output_lossless=task_data.output_lossless, ) save_images( filtered_images, @@ -68,6 +74,7 @@ def save_images_to_disk(images: list, filtered_images: list, req: GenerateImageR file_name=make_filter_filename, output_format=task_data.output_format, output_quality=task_data.output_quality, + output_lossless=task_data.output_lossless, ) if task_data.metadata_output_format.lower() in ["json", "txt", "embed"]: save_dicts( @@ -86,6 +93,7 @@ def get_metadata_entries_for_request(req: GenerateImageRequest, task_data: TaskD "use_stable_diffusion_model": task_data.use_stable_diffusion_model, "use_vae_model": task_data.use_vae_model, "use_hypernetwork_model": task_data.use_hypernetwork_model, + "use_lora_model": task_data.use_lora_model, "use_face_correction": task_data.use_face_correction, "use_upscale": task_data.use_upscale, } @@ -94,6 +102,15 @@ def get_metadata_entries_for_request(req: GenerateImageRequest, task_data: TaskD metadata["upscale_amount"] = task_data.upscale_amount if task_data.use_hypernetwork_model is None: del metadata["hypernetwork_strength"] + if task_data.use_lora_model is None: + if "lora_alpha" in metadata: + del metadata["lora_alpha"] + + from easydiffusion import app + + app_config = app.getConfig() + if not app_config.get("test_diffusers", False) and "use_lora_model" in metadata: + del metadata["use_lora_model"] # if text, format it in the text format expected by the UI is_txt_format = task_data.metadata_output_format.lower() == "txt" diff --git a/ui/index.html b/ui/index.html index d2b836b1..fed2b3b9 100644 --- a/ui/index.html +++ b/ui/index.html @@ -30,7 +30,7 @@