From af4da762f2673dd9dd3058025037ab2ec6f9033d Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Mon, 24 Jul 2023 19:58:11 -0700 Subject: [PATCH 01/15] increased qr price to 30cr --- recipes/QRCodeGenerator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 8f64b26ad..feaebf9b0 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -365,7 +365,7 @@ def preview_description(self, state: dict) -> str: def get_raw_price(self, state: dict) -> int: selected_model = state.get("selected_model", Text2ImgModels.dream_shaper.name) - total = 5 + total = 30 match selected_model: case Text2ImgModels.deepfloyd_if.name: total += 3 From 3d1093cb066e74e92feb2144b23c590f06284352 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Mon, 24 Jul 2023 20:15:19 -0700 Subject: [PATCH 02/15] more robust qr reader, including inverted qr codes --- recipes/QRCodeGenerator.py | 39 ++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index feaebf9b0..a1120bc7e 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -1,6 +1,7 @@ import typing import numpy as np +from PIL import Image, ImageOps, ImageEnhance import qrcode import requests from django.core.exceptions import ValidationError @@ -432,14 +433,40 @@ def download_qr_code_data(url: str) -> str: return extract_qr_code_data(img) -def extract_qr_code_data(img: np.ndarray) -> str: - decoded = pyzbar.decode(img) - if not (decoded and decoded[0]): +def extract_qr_code_data(image: np.ndarray) -> str: + # cycle through different sizes and sharpnesses, etc. for a more robust qr code extraction + image = Image.fromarray(image) + found_qr_code = False + found_qr_code_data = False + x, y = image.size + for scalar in [0.1, 0.2, 0.5, 1]: + image_scaled = image.resize((int(round(x * scalar)), int(round(y * scalar)))) + for sharpness in [0.1, 0.5, 1, 2]: + image_scaled_sharp = ImageEnhance.Sharpness(image_scaled).enhance(sharpness) + image_autocontrast = ImageOps.autocontrast(image_scaled_sharp) + image_inverted = ImageOps.invert(image_autocontrast) + image_grayscale = ImageOps.grayscale(image_autocontrast) + image_grayscale_inverted = ImageOps.grayscale(image_inverted) + for img in [ + image_autocontrast, + image_inverted, + image_grayscale, + image_grayscale_inverted, + ]: + decoded = pyzbar.decode(img) + if decoded and decoded[0]: + found_qr_code = True + info = decoded[0].data.decode() + if info: + found_qr_code_data = True + print(f"QR code data: {info}") + return info + + if not found_qr_code: raise InvalidQRCode("No QR code found in image") - info = decoded[0].data.decode() - if not info: + + if not found_qr_code_data: raise InvalidQRCode("No data found in QR code") - return info class InvalidQRCode(AssertionError): From 4a0bda901c39286e683bb84016efb1504e3b755e Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Mon, 24 Jul 2023 21:23:55 -0700 Subject: [PATCH 03/15] add qr code monster v2 as controlnet option --- daras_ai_v2/stable_diffusion.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/daras_ai_v2/stable_diffusion.py b/daras_ai_v2/stable_diffusion.py index ce8918f79..ad97bde9a 100644 --- a/daras_ai_v2/stable_diffusion.py +++ b/daras_ai_v2/stable_diffusion.py @@ -106,6 +106,7 @@ class ControlNetModels(Enum): sd_controlnet_seg = "Image Segmentation" sd_controlnet_tile = "Tiling" sd_controlnet_brightness = "Brightness" + sd_controlnet_qrmonster = "QR Monster" controlnet_model_explanations = { @@ -119,6 +120,7 @@ class ControlNetModels(Enum): ControlNetModels.sd_controlnet_seg: "Image segmentation", ControlNetModels.sd_controlnet_tile: "Tiling: to preserve small details", ControlNetModels.sd_controlnet_brightness: "Brightness: to increase contrast naturally", + ControlNetModels.sd_controlnet_qrmonster: "QR Monster: make beautiful QR codes that still scan with a controlnet specifically trained for this purpose", } controlnet_model_ids = { @@ -132,6 +134,7 @@ class ControlNetModels(Enum): ControlNetModels.sd_controlnet_seg: "lllyasviel/sd-controlnet-seg", ControlNetModels.sd_controlnet_tile: "lllyasviel/control_v11f1e_sd15_tile", ControlNetModels.sd_controlnet_brightness: "ioclab/control_v1p_sd15_brightness", + ControlNetModels.sd_controlnet_qrmonster: "monster-labs/control_v1p_sd15_qrcode_monster", } From 6f70b57441666c4399542737a01cc09b7cf674fc Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Mon, 24 Jul 2023 21:52:32 -0700 Subject: [PATCH 04/15] change to v2 --- daras_ai_v2/stable_diffusion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daras_ai_v2/stable_diffusion.py b/daras_ai_v2/stable_diffusion.py index ad97bde9a..0de154094 100644 --- a/daras_ai_v2/stable_diffusion.py +++ b/daras_ai_v2/stable_diffusion.py @@ -134,7 +134,7 @@ class ControlNetModels(Enum): ControlNetModels.sd_controlnet_seg: "lllyasviel/sd-controlnet-seg", ControlNetModels.sd_controlnet_tile: "lllyasviel/control_v11f1e_sd15_tile", ControlNetModels.sd_controlnet_brightness: "ioclab/control_v1p_sd15_brightness", - ControlNetModels.sd_controlnet_qrmonster: "monster-labs/control_v1p_sd15_qrcode_monster", + ControlNetModels.sd_controlnet_qrmonster: "monster-labs/control_v1p_sd15_qrcode_monster/tree/main/v2", } From 2374a2f299c1bbe55d92701982e583b6a6278d0f Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 25 Jul 2023 00:13:11 -0700 Subject: [PATCH 05/15] rename qr monster model id --- daras_ai_v2/stable_diffusion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daras_ai_v2/stable_diffusion.py b/daras_ai_v2/stable_diffusion.py index 0de154094..8db49e382 100644 --- a/daras_ai_v2/stable_diffusion.py +++ b/daras_ai_v2/stable_diffusion.py @@ -134,7 +134,7 @@ class ControlNetModels(Enum): ControlNetModels.sd_controlnet_seg: "lllyasviel/sd-controlnet-seg", ControlNetModels.sd_controlnet_tile: "lllyasviel/control_v11f1e_sd15_tile", ControlNetModels.sd_controlnet_brightness: "ioclab/control_v1p_sd15_brightness", - ControlNetModels.sd_controlnet_qrmonster: "monster-labs/control_v1p_sd15_qrcode_monster/tree/main/v2", + ControlNetModels.sd_controlnet_qrmonster: "monster-labs/control_v1p_sd15_qrcode_monster/v2", } From 2f4cfa053fd333fa3bd80f403d74d40d0f9ece75 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 25 Jul 2023 11:49:17 -0700 Subject: [PATCH 06/15] fix model selection code --- daras_ai_v2/stable_diffusion.py | 10 +++++----- recipes/QRCodeGenerator.py | 11 ++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/daras_ai_v2/stable_diffusion.py b/daras_ai_v2/stable_diffusion.py index 8db49e382..9d3261a6b 100644 --- a/daras_ai_v2/stable_diffusion.py +++ b/daras_ai_v2/stable_diffusion.py @@ -419,7 +419,7 @@ def controlnet( return call_sd_multi( "diffusion.controlnet", pipeline={ - "model_id": text2img_model_ids[Text2ImgModels[selected_model]], + "model_id": img2img_model_ids[Img2ImgModels[selected_model]], "seed": seed, "scheduler": Schedulers[scheduler].label if scheduler @@ -445,13 +445,13 @@ def controlnet( def add_prompt_prefix(prompt: str, selected_model: str) -> str: match selected_model: - case Text2ImgModels.openjourney.name: + case Text2ImgModels.openjourney.name | Img2ImgModels.openjourney.name: prompt = "mdjrny-v4 style " + prompt - case Text2ImgModels.analog_diffusion.name: + case Text2ImgModels.analog_diffusion.name | Img2ImgModels.analog_diffusion.name: prompt = "analog style " + prompt - case Text2ImgModels.protogen_5_3.name: + case Text2ImgModels.protogen_5_3.name | Img2ImgModels.protogen_5_3.name: prompt = "modelshoot style " + prompt - case Text2ImgModels.dreamlike_2.name: + case Text2ImgModels.dreamlike_2.name | Img2ImgModels.dreamlike_2.name: prompt = "photo, " + prompt return prompt diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index a1120bc7e..1d3409af9 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -26,7 +26,6 @@ ) from daras_ai_v2.repositioning import reposition_object, repositioning_preview_widget from daras_ai_v2.stable_diffusion import ( - Text2ImgModels, controlnet, ControlNetModels, Img2ImgModels, @@ -61,7 +60,7 @@ class RequestModel(BaseModel): text_prompt: str negative_prompt: str | None - selected_model: typing.Literal[tuple(e.name for e in Text2ImgModels)] | None + selected_model: typing.Literal[tuple(e.name for e in Img2ImgModels)] | None selected_controlnet_model: list[ typing.Literal[tuple(e.name for e in ControlNetModels)], ... ] | None @@ -329,7 +328,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]: state["raw_images"] = raw_images = [] - yield f"Running {Text2ImgModels[request.selected_model].value}..." + yield f"Running {Img2ImgModels[request.selected_model].value}..." state["output_images"] = controlnet( selected_model=request.selected_model, selected_controlnet_model=request.selected_controlnet_model, @@ -365,12 +364,10 @@ def preview_description(self, state: dict) -> str: """ def get_raw_price(self, state: dict) -> int: - selected_model = state.get("selected_model", Text2ImgModels.dream_shaper.name) + selected_model = state.get("selected_model", Img2ImgModels.dream_shaper.name) total = 30 match selected_model: - case Text2ImgModels.deepfloyd_if.name: - total += 3 - case Text2ImgModels.dall_e.name: + case Img2ImgModels.dall_e.name: total += 10 return total * state.get("num_outputs", 1) From 842c359386f24306667e9423ca1826c459d89f57 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 25 Jul 2023 19:44:06 -0700 Subject: [PATCH 07/15] grayscale background slider --- recipes/QRCodeGenerator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 1d3409af9..02c3cc850 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -45,6 +45,7 @@ class QRCodeGeneratorPage(BasePage): obj_scale=0.65, obj_pos_x=0.5, obj_pos_y=0.5, + color=255, ) def __init__(self, *args, **kwargs): @@ -80,6 +81,7 @@ class RequestModel(BaseModel): obj_scale: float | None obj_pos_x: float | None obj_pos_y: float | None + color: int | None class ResponseModel(BaseModel): output_images: list[str] @@ -265,6 +267,9 @@ def render_settings(self): img_cv2 = mask_cv2 = np.array( qrcode.QRCode(border=0).make_image().convert("RGB") ) + color = st.slider( + "`Grayscale background`", min_value=0, max_value=255, key="color" + ) repositioning_preview_widget( img_cv2=img_cv2, mask_cv2=mask_cv2, @@ -275,7 +280,7 @@ def render_settings(self): st.session_state["output_width"], st.session_state["output_height"], ), - color=255, + color=color, ) def render_output(self): @@ -410,7 +415,7 @@ def generate_and_upload_qr_code( out_obj_scale=request.obj_scale, out_pos_x=request.obj_pos_x, out_pos_y=request.obj_pos_y, - color=255, + color=request.color, ) img_url = upload_file_from_bytes("cleaned_qr.png", cv2_img_to_bytes(img_cv2)) From 67a2be351c3aae46c7c0ab550080f4acd10471a8 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 25 Jul 2023 20:49:13 -0700 Subject: [PATCH 08/15] setting presets --- recipes/QRCodeGenerator.py | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 02c3cc850..e2e9d62df 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -46,6 +46,7 @@ class QRCodeGeneratorPage(BasePage): obj_pos_x=0.5, obj_pos_y=0.5, color=255, + settings="Custom", ) def __init__(self, *args, **kwargs): @@ -214,6 +215,89 @@ def render_settings(self): """ ) + settings_type = st.radio( + "", + key="settings", + options=["Reliable", "Creative", "Beautiful", "Custom"], + ) + if settings_type == "Reliable": + st.caption( + "If you just want something tried and tested, this is our original defaults." + ) + st.session_state.update( + { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words", + "controlnet_conditioning_scale": [0.45, 0.35], + "guidance_scale": 9, + "num_outputs": 2, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.65, + "output_height": 512, + "output_width": 512, + "quality": 70, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_tile.name, + ControlNetModels.sd_controlnet_brightness.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + } + ) + elif settings_type == "Creative": + st.caption( + "Stunning QR Codes with a creative flair that may not always be readable and could end up weird." + ) + st.session_state.update( + { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads", + "controlnet_conditioning_scale": [1.4], + "guidance_scale": 4, + "num_outputs": 4, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.65, + "output_height": 768, + "output_width": 768, + "quality": 40, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_qrmonster.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + } + ) + elif settings_type == "Beautiful": + st.caption( + "The best mix of reliability and creativity. Produces some of the best results for most purposes." + ) + st.session_state.update( + { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads.", + "controlnet_conditioning_scale": [1.4, 0.25], + "guidance_scale": 9, + "num_outputs": 1, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.65, + "output_height": 768, + "output_width": 768, + "quality": 70, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_qrmonster.name, + ControlNetModels.sd_controlnet_brightness.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + } + ) + + if settings_type != "Custom": + return + st.caption( + "For the tech savvy and the curious. Here you can play around with settings to create something truly unique." + ) + img_model_settings( Img2ImgModels, show_scheduler=True, From 98ec7ac012e05ff02c50566b0be6b2168dd1255c Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 25 Jul 2023 21:14:59 -0700 Subject: [PATCH 09/15] tweaked negative prompt --- recipes/QRCodeGenerator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index e2e9d62df..9056a2f17 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -273,7 +273,7 @@ def render_settings(self): ) st.session_state.update( { - "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads.", + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", "controlnet_conditioning_scale": [1.4, 0.25], "guidance_scale": 9, "num_outputs": 1, From 7d72f7e78b73974148d1018a2952375e5d9e68a8 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 25 Jul 2023 23:45:37 -0700 Subject: [PATCH 10/15] correct controlnet order in presets --- recipes/QRCodeGenerator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 9056a2f17..26a393ef2 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -274,7 +274,7 @@ def render_settings(self): st.session_state.update( { "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", - "controlnet_conditioning_scale": [1.4, 0.25], + "controlnet_conditioning_scale": [0.25, 1.4], "guidance_scale": 9, "num_outputs": 1, "obj_pos_x": 0.5, @@ -285,8 +285,8 @@ def render_settings(self): "quality": 70, "scheduler": Schedulers.euler_ancestral.name, "selected_controlnet_model": [ - ControlNetModels.sd_controlnet_qrmonster.name, ControlNetModels.sd_controlnet_brightness.name, + ControlNetModels.sd_controlnet_qrmonster.name, ], "selected_model": Img2ImgModels.dream_shaper.name, } From ee4549370ea8f3ba65e0c229f8f59c9b20a7f6f1 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Wed, 26 Jul 2023 00:07:45 -0700 Subject: [PATCH 11/15] added 3D preset --- daras_ai_v2/img_model_settings_widgets.py | 2 +- recipes/QRCodeGenerator.py | 27 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/daras_ai_v2/img_model_settings_widgets.py b/daras_ai_v2/img_model_settings_widgets.py index c17bc5e2a..3f9a8bd68 100644 --- a/daras_ai_v2/img_model_settings_widgets.py +++ b/daras_ai_v2/img_model_settings_widgets.py @@ -152,7 +152,7 @@ def controlnet_settings( for i, model in enumerate(sorted(models)): key = f"controlnet_conditioning_scale_{model}" try: - st.session_state.setdefault(key, state_values[i]) + st.session_state[key] = state_values[i] except IndexError: pass new_values.append( diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 26a393ef2..01ea8dad2 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -218,7 +218,7 @@ def render_settings(self): settings_type = st.radio( "", key="settings", - options=["Reliable", "Creative", "Beautiful", "Custom"], + options=["Reliable", "Creative", "Beautiful", "3D", "Custom"], ) if settings_type == "Reliable": st.caption( @@ -291,6 +291,31 @@ def render_settings(self): "selected_model": Img2ImgModels.dream_shaper.name, } ) + elif settings_type == "3D": + st.caption( + "Uses depth information to make the QR Code appear more 3D. This is experimental and may not always work." + ) + st.session_state.update( + { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", + "controlnet_conditioning_scale": [0.35, 0.3, 0.3], + "guidance_scale": 8, + "num_outputs": 1, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.8, + "output_height": 512, + "output_width": 512, + "quality": 100, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_brightness.name, + ControlNetModels.sd_controlnet_depth.name, + ControlNetModels.sd_controlnet_tile.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + } + ) if settings_type != "Custom": return From afb27c247901c2b781e7af1803e6535b38437e38 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Wed, 26 Jul 2023 08:28:57 -0700 Subject: [PATCH 12/15] fixed ordering of reliable option --- recipes/QRCodeGenerator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 01ea8dad2..2917d8b18 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -238,8 +238,8 @@ def render_settings(self): "quality": 70, "scheduler": Schedulers.euler_ancestral.name, "selected_controlnet_model": [ - ControlNetModels.sd_controlnet_tile.name, ControlNetModels.sd_controlnet_brightness.name, + ControlNetModels.sd_controlnet_tile.name, ], "selected_model": Img2ImgModels.dream_shaper.name, } From 28541acc9dd50b4350fe905c5e1ac934baf3672e Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Wed, 26 Jul 2023 08:41:13 -0700 Subject: [PATCH 13/15] fixed sorting in controlnet settings --- daras_ai_v2/img_model_settings_widgets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/daras_ai_v2/img_model_settings_widgets.py b/daras_ai_v2/img_model_settings_widgets.py index 3f9a8bd68..2b2ada7fc 100644 --- a/daras_ai_v2/img_model_settings_widgets.py +++ b/daras_ai_v2/img_model_settings_widgets.py @@ -160,6 +160,7 @@ def controlnet_settings( selected_controlnet_model=model, explanations=explanations, key=key ), ) + st.session_state["selected_controlnet_model"] = sorted(models) st.session_state["controlnet_conditioning_scale"] = new_values From bb67a39159c696f57a9caaf85fcbc20186ac65a3 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Sun, 30 Jul 2023 15:17:41 -0700 Subject: [PATCH 14/15] use buttons for presets instead --- daras_ai_v2/img_model_settings_widgets.py | 15 +- gooey_ui/components.py | 2 + recipes/QRCodeGenerator.py | 204 +++++++++++----------- 3 files changed, 112 insertions(+), 109 deletions(-) diff --git a/daras_ai_v2/img_model_settings_widgets.py b/daras_ai_v2/img_model_settings_widgets.py index 2b2ada7fc..e84a0ef3d 100644 --- a/daras_ai_v2/img_model_settings_widgets.py +++ b/daras_ai_v2/img_model_settings_widgets.py @@ -135,6 +135,9 @@ def controlnet_settings( explanations = controlnet_model_explanations | extra_explanations state_values = st.session_state.get("controlnet_conditioning_scale", []) + if len(models) != len(state_values): + state_values = state_values + [1] * len(models) + state_values = state_values[: len(models)] new_values = [] st.write( """ @@ -149,12 +152,11 @@ def controlnet_settings( `{high_explanation.format(high=int(CONTROLNET_CONDITIONING_SCALE_RANGE[1]))}`. """ ) - for i, model in enumerate(sorted(models)): + for model, value in sorted(zip(models, state_values), key=lambda x: x[0]): key = f"controlnet_conditioning_scale_{model}" - try: - st.session_state[key] = state_values[i] - except IndexError: - pass + if st.session_state.get("controlnet_overwrite"): + st.session_state[key] = value + st.session_state.setdefault(key, value) new_values.append( controlnet_weight_setting( selected_controlnet_model=model, explanations=explanations, key=key @@ -179,6 +181,9 @@ def controlnet_weight_setting( min_value=CONTROLNET_CONDITIONING_SCALE_RANGE[0], max_value=CONTROLNET_CONDITIONING_SCALE_RANGE[1], step=0.05, + default_value_attr="value" + if st.session_state.get("controlnet_overwrite") + else "defaultValue", ) diff --git a/gooey_ui/components.py b/gooey_ui/components.py index 21f0db9bb..4ab9b725b 100644 --- a/gooey_ui/components.py +++ b/gooey_ui/components.py @@ -545,6 +545,7 @@ def slider( help: str = None, *, disabled: bool = False, + default_value_attr: str = "defaultValue", ) -> float: value = _input_widget( input_type="range", @@ -556,6 +557,7 @@ def slider( min=min_value, max=max_value, step=_step_value(min_value, max_value, step), + default_value_attr=default_value_attr, ) return value or 0 diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 2917d8b18..59d54fdd6 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -35,6 +35,93 @@ ATTEMPTS = 1 +PRESETS = { + "Reliable": { + "description": "If you just want something tried and tested, this is our original defaults.", + "state_update": { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words", + "controlnet_conditioning_scale": [0.45, 0.35], + "guidance_scale": 9, + "num_outputs": 2, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.65, + "output_height": 512, + "output_width": 512, + "quality": 70, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_brightness.name, + ControlNetModels.sd_controlnet_tile.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + }, + }, + "Creative": { + "description": "Stunning QR Codes with a creative flair that may not always be readable and could end up weird.", + "state_update": { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads", + "controlnet_conditioning_scale": [1.4], + "guidance_scale": 4, + "num_outputs": 4, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.65, + "output_height": 768, + "output_width": 768, + "quality": 40, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_qrmonster.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + }, + }, + "Beautiful": { + "description": "The best mix of reliability and creativity. Produces some of the best results for most purposes.", + "state_update": { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", + "controlnet_conditioning_scale": [0.25, 1.4], + "guidance_scale": 9, + "num_outputs": 1, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.65, + "output_height": 768, + "output_width": 768, + "quality": 70, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_brightness.name, + ControlNetModels.sd_controlnet_qrmonster.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + }, + }, + "3D": { + "description": "Uses depth information to make the QR Code appear more 3D. This is experimental and may not always work.", + "state_update": { + "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", + "controlnet_conditioning_scale": [0.35, 0.3, 0.3], + "guidance_scale": 8, + "num_outputs": 1, + "obj_pos_x": 0.5, + "obj_pos_y": 0.5, + "obj_scale": 0.8, + "output_height": 512, + "output_width": 512, + "quality": 100, + "scheduler": Schedulers.euler_ancestral.name, + "selected_controlnet_model": [ + ControlNetModels.sd_controlnet_brightness.name, + ControlNetModels.sd_controlnet_depth.name, + ControlNetModels.sd_controlnet_tile.name, + ], + "selected_model": Img2ImgModels.dream_shaper.name, + }, + }, +} + class QRCodeGeneratorPage(BasePage): title = "AI Art QR Code" @@ -46,7 +133,6 @@ class QRCodeGeneratorPage(BasePage): obj_pos_x=0.5, obj_pos_y=0.5, color=255, - settings="Custom", ) def __init__(self, *args, **kwargs): @@ -215,114 +301,24 @@ def render_settings(self): """ ) - settings_type = st.radio( - "", - key="settings", - options=["Reliable", "Creative", "Beautiful", "3D", "Custom"], - ) - if settings_type == "Reliable": - st.caption( - "If you just want something tried and tested, this is our original defaults." - ) - st.session_state.update( - { - "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words", - "controlnet_conditioning_scale": [0.45, 0.35], - "guidance_scale": 9, - "num_outputs": 2, - "obj_pos_x": 0.5, - "obj_pos_y": 0.5, - "obj_scale": 0.65, - "output_height": 512, - "output_width": 512, - "quality": 70, - "scheduler": Schedulers.euler_ancestral.name, - "selected_controlnet_model": [ - ControlNetModels.sd_controlnet_brightness.name, - ControlNetModels.sd_controlnet_tile.name, - ], - "selected_model": Img2ImgModels.dream_shaper.name, - } - ) - elif settings_type == "Creative": - st.caption( - "Stunning QR Codes with a creative flair that may not always be readable and could end up weird." - ) - st.session_state.update( - { - "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads", - "controlnet_conditioning_scale": [1.4], - "guidance_scale": 4, - "num_outputs": 4, - "obj_pos_x": 0.5, - "obj_pos_y": 0.5, - "obj_scale": 0.65, - "output_height": 768, - "output_width": 768, - "quality": 40, - "scheduler": Schedulers.euler_ancestral.name, - "selected_controlnet_model": [ - ControlNetModels.sd_controlnet_qrmonster.name, - ], - "selected_model": Img2ImgModels.dream_shaper.name, - } - ) - elif settings_type == "Beautiful": + preset_match = None + st.session_state["controlnet_overwrite"] = False + for preset, preset_value in PRESETS.items(): + key = "preset_" + preset + if st.button(preset, key=key, disabled=st.session_state.get(key, False)): + preset_match = preset_value + st.session_state.update(preset_value["state_update"]) + st.session_state["controlnet_overwrite"] = True + if not preset_match: + st.button("Custom", key="preset_Custom", disabled=True) st.caption( - "The best mix of reliability and creativity. Produces some of the best results for most purposes." - ) - st.session_state.update( - { - "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", - "controlnet_conditioning_scale": [0.25, 1.4], - "guidance_scale": 9, - "num_outputs": 1, - "obj_pos_x": 0.5, - "obj_pos_y": 0.5, - "obj_scale": 0.65, - "output_height": 768, - "output_width": 768, - "quality": 70, - "scheduler": Schedulers.euler_ancestral.name, - "selected_controlnet_model": [ - ControlNetModels.sd_controlnet_brightness.name, - ControlNetModels.sd_controlnet_qrmonster.name, - ], - "selected_model": Img2ImgModels.dream_shaper.name, - } + "For the tech savvy and the curious. Here you can play around with settings to create something truly unique." ) - elif settings_type == "3D": + else: st.caption( - "Uses depth information to make the QR Code appear more 3D. This is experimental and may not always work." - ) - st.session_state.update( - { - "negative_prompt": "ugly, disfigured, low quality, blurry, nsfw, text, words, multiple heads, many", - "controlnet_conditioning_scale": [0.35, 0.3, 0.3], - "guidance_scale": 8, - "num_outputs": 1, - "obj_pos_x": 0.5, - "obj_pos_y": 0.5, - "obj_scale": 0.8, - "output_height": 512, - "output_width": 512, - "quality": 100, - "scheduler": Schedulers.euler_ancestral.name, - "selected_controlnet_model": [ - ControlNetModels.sd_controlnet_brightness.name, - ControlNetModels.sd_controlnet_depth.name, - ControlNetModels.sd_controlnet_tile.name, - ], - "selected_model": Img2ImgModels.dream_shaper.name, - } + preset_match["description"], ) - if settings_type != "Custom": - return - st.caption( - "For the tech savvy and the curious. Here you can play around with settings to create something truly unique." - ) - img_model_settings( Img2ImgModels, show_scheduler=True, From 4afc281db31a8a2b6b6f696d2ed365122f24687c Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Tue, 1 Aug 2023 14:17:34 +0530 Subject: [PATCH 15/15] update dashboard urls --- Home.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Home.py b/Home.py index 2ef396da2..97f2b44fc 100644 --- a/Home.py +++ b/Home.py @@ -5,10 +5,10 @@ """ ## Welcome to Gooey.AI Dashboard -Name|Link ----|--- -Main App | [gooey.ai](https://gooey.ai/explore) -Admin | [admin.gooey.ai](https://admin.gooey.ai) -Test App | [gooey-gui.us-1.gooey.ai](https://gooey-gui.us-1.gooey.ai/explore) -Test Admin | [gooey-admin-test.us-1.gooey.ai](http://gooey-admin-test.us-1.gooey.ai) +_|Prod|Test +---|---|--- +Home | [gooey.ai](https://gooey.ai) | [gooey-gui-test.us-1.gooey.ai](https://gooey-gui-test.us-1.gooey.ai) +App | [gooey.ai/explore](https://gooey.ai/explore) | [gooey-gui-test.us-1.gooey.ai/explore](https://gooey-gui-test.us-1.gooey.ai/explore) +Admin | [admin.gooey.ai](https://admin.gooey.ai) | [gooey-admin-test.us-1.gooey.ai](https://gooey-admin-test.us-1.gooey.ai/) +Dash | [dash.gooey.ai](https://dash.gooey.ai) | [gooey-dash-test.us-1.gooey.ai](https://gooey-dash-test.us-1.gooey.ai/) """