Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 committed May 19, 2024
1 parent a8ef830 commit 101d0d3
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 28 deletions.
51 changes: 48 additions & 3 deletions hordelib/horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class HordeLib:
"stable_cascade_stage_b": {"datatype": str, "default": None}, # Stable Cascade
"stable_cascade_stage_c": {"datatype": str, "default": None}, # Stable Cascade
"extra_source_images": {"datatype": list, "default": []}, # Stable Cascade Remix
"extra_texts": {"datatype": list, "default": []}, # QR Codes (for now)
"workflow": {"datatype": str, "default": "auto_detect"},
}

Expand All @@ -179,6 +180,11 @@ class HordeLib:
"strength": {"datatype": float, "min": 0.0, "max": 5.0, "default": 1.0},
}

EXTRA_TEXTS_SCHEMA = {
"text": {"datatype": str, "default": ""},
"reference": {"datatype": str, "default": None},
}

LORA_SCHEMA = {
"name": {"datatype": str, "default": ""},
"model": {"datatype": float, "min": -10.0, "max": 10.0, "default": 1.0},
Expand Down Expand Up @@ -253,9 +259,14 @@ class HordeLib:
"sampler_fg.cfg": "cfg_scale",
"sampler_fg.denoise": "denoising_strength",
"sampler_fg.seed": "seed",
# Ultimately this should allow the user to customize it, but for that
# I need to allow to send 2+ prompts per gen.
"function_layer_prompt.text": "prompt",
"controlnet_bg.strength": "control_strength",
"solidmask_grey.width": "width",
"solidmask_grey.height": "height",
"solidmask_white.width": "width",
"solidmask_white.height": "height",
"solidmask_black.width": "width",
"solidmask_black.height": "height",
"qr_code_split.max_image_size": "width",
}

_comfyui_callback: Callable[[str, dict, str], None] | None = None
Expand Down Expand Up @@ -369,6 +380,12 @@ def _validate_data_structure(self, data, schema_definition=PAYLOAD_SCHEMA):
data["extra_source_images"][i] = self._validate_data_structure(img, HordeLib.EXTRA_IMAGES_SCHEMA)
data["extra_source_images"] = [x for x in data["extra_source_images"] if x.get("image")]

# Do the same for extra texts, if we have them in this data structure
if data.get("extra_texts"):
for i, img in enumerate(data.get("extra_texts")):
data["extra_texts"][i] = self._validate_data_structure(img, HordeLib.EXTRA_TEXTS_SCHEMA)
data["extra_texts"] = [x for x in data["extra_texts"] if x.get("text")]

return data

def _apply_aihorde_compatibility_hacks(self, payload: dict) -> tuple[dict, list[GenMetadataEntry]]:
Expand Down Expand Up @@ -513,6 +530,11 @@ def _apply_aihorde_compatibility_hacks(self, payload: dict) -> tuple[dict, list[
if not payload.get("hires_fix_denoising_strength"):
payload["hires_fix_denoising_strength"] = payload.get("denoising_strength")

if payload.get("workflow") == "qr_code":
if payload.get("source_processing") and payload.get("source_processing") != "txt2img":
if not payload.get("hires_fix_denoising_strength"):
payload["hires_fix_denoising_strength"] = payload.get("denoising_strength")

# # Remap "denoising" to "controlnet strength", historical hack
# if payload.get("control_type"):
# if payload.get("denoising_strength"):
Expand Down Expand Up @@ -915,6 +937,29 @@ def _final_pipeline_adjustments(self, payload, pipeline_data) -> tuple[dict, lis
f"unclip_conditioning_{node_index}",
)

# If we have a qr code request, we check for extra texts such as the generation url
if payload.get("workflow") == "qr_code":
for text in payload.get("extra_texts"):
if text["reference"] == "qr_text":
pipeline_params["qr_code_split.text"] = text["text"]
if text["reference"] == "protocol" and text["text"].lower() in ["https", "http"]:
pipeline_params["qr_code_split.protocol"] = text["text"].capitalize()
if text["reference"] == "module_drawer" and text["text"].lower() in [
"square",
"gapped square",
"circle",
"rounded",
"vertical bars",
"horizontal bars",
]:
pipeline_params["qr_code_split.module_drawer"] = text["text"].capitalize()
if text["reference"] == "function_layer_prompt":
pipeline_params["function_layer_prompt.text"] = text["text"]
if not pipeline_params.get("qr_code_split.protocol"):
pipeline_params["qr_code_split.protocol"] = "None"
if not pipeline_params.get("function_layer_prompt.text"):
pipeline_params["function_layer_prompt.text"] = payload["prompt"]

return pipeline_params, faults

def _get_appropriate_pipeline(self, params):
Expand Down
30 changes: 15 additions & 15 deletions hordelib/pipelines/pipeline_qr_code.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"17": {
"inputs": {
"strength": 0.5999999999999994,
"strength": 1,
"start_percent": 0,
"end_percent": 1,
"positive": [
Expand Down Expand Up @@ -116,7 +116,7 @@
"24": {
"inputs": {
"add_noise": "enable",
"noise_seed": 1045659087938662,
"noise_seed": 1312,
"steps": 25,
"cfg": 8,
"sampler_name": "euler_ancestral",
Expand Down Expand Up @@ -149,7 +149,7 @@
"27": {
"inputs": {
"add_noise": "enable",
"noise_seed": 697498602843513,
"noise_seed": 974190433170716,
"steps": 25,
"cfg": 8,
"sampler_name": "euler",
Expand Down Expand Up @@ -205,7 +205,7 @@
"30": {
"inputs": {
"add_noise": "disable",
"noise_seed": 1108729881120626,
"noise_seed": 1312,
"steps": 25,
"cfg": 8,
"sampler_name": "euler_ancestral",
Expand Down Expand Up @@ -280,10 +280,10 @@
},
"39": {
"inputs": {
"protocol": "Https",
"protocol": "None",
"text": "aihorde.net",
"module_size": 16,
"max_image_size": 768,
"max_image_size": 1024,
"fill_hexcolor": "#000000",
"back_hexcolor": "#FFFFFF",
"error_correction": "High",
Expand All @@ -299,11 +299,11 @@
"inputs": {
"value": 0.5,
"width": 768,
"height": 768
"height": 1024
},
"class_type": "SolidMask",
"_meta": {
"title": "SolidMask (Grey)"
"title": "solidmask_grey"
}
},
"41": {
Expand Down Expand Up @@ -410,16 +410,16 @@
"inputs": {
"value": 0,
"width": 768,
"height": 768
"height": 1024
},
"class_type": "SolidMask",
"_meta": {
"title": "SolidMask (Black)"
"title": "solidmask_black"
}
},
"57": {
"inputs": {
"text": "Spirits flying around, sepia colors",
"text": "drawing of two a hydra with many heads. Wispy and Ethereal, sepia colors",
"clip": [
"6",
1
Expand Down Expand Up @@ -449,12 +449,12 @@
"64": {
"inputs": {
"value": 1,
"width": 768,
"height": 768
"width": 1024,
"height": 1024
},
"class_type": "SolidMask",
"_meta": {
"title": "SolidMask (White)"
"title": "solidmask_white"
}
},
"65": {
Expand Down Expand Up @@ -553,7 +553,7 @@
},
"90": {
"inputs": {
"text": "drawing of two witches performing a seanse around a cauldron. Wispy and Ethereal, sepia colors",
"text": "drawing of two a hydra with many heads. Wispy and Ethereal, sepia colors",
"clip": [
"6",
1
Expand Down
Loading

0 comments on commit 101d0d3

Please sign in to comment.