Skip to content

Commit

Permalink
feat: supports transparent image generation (#427)
Browse files Browse the repository at this point in the history
* feat: supports transparent image generation

* feat: moved checking for worker transparency compat to db:
  • Loading branch information
db0 authored Jun 30, 2024
1 parent 6695fe5 commit 276def2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 4.39.0

* Adds generating transparent images

# 4.38.0

* Add waitress / db metrics to heartbeat
Expand Down
4 changes: 4 additions & 0 deletions horde/apis/models/stable_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ def __init__(self, api):
enum=list(KNOWN_WORKFLOWS),
description="Explicitly specify the horde-engine workflow to use.",
),
"transparent": fields.Boolean(
default=False,
description="Set to True to generate the image using Layer Diffuse, creating an image with a transparent background.",
),
},
)
self.response_model_generation_payload = api.inherit(
Expand Down
9 changes: 8 additions & 1 deletion horde/apis/v2/stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ def validate(self):
raise e.BadRequest("explicit LoRa version requests have to be a version ID (i.e integer).", rc="BadLoraVersion")
if "tis" in self.params and len(self.params["tis"]) > 20:
raise e.BadRequest("You cannot request more than 20 Textual Inversions per generation.", rc="TooManyTIs")
if self.params.get("transparent", False) is True and any(
model_reference.get_model_baseline(model_name) not in ["stable_diffusion_xl", "stable diffusion 1"]
for model_name in self.args.models
):
raise e.BadRequest(
"Generating Transparent images is is only possible for Stable Diffusion 1.5 and XL models.", rc="InvalidTransparency",
)
if self.args.source_processing == "remix" and any(
not model_reference.get_model_baseline(model_name).startswith("stable_cascade") for model_name in self.args.models
):
Expand Down Expand Up @@ -573,7 +580,7 @@ def post(self):
if "blacklist" in post_ret.get("skipped", {}):
db_skipped["blacklist"] = post_ret["skipped"]["blacklist"]
post_ret["skipped"] = db_skipped

# logger.debug(post_ret)
return post_ret, retcode

def check_in(self):
Expand Down
1 change: 1 addition & 0 deletions horde/bridge_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

BRIDGE_CAPABILITIES = {
"AI Horde Worker reGen": {
8: {"layer_diffuse"},
7: {"qr_code", "extra_texts", "workflow"},
6: {"stable_cascade_2pass"},
5: {"extra_source_images"},
Expand Down
2 changes: 1 addition & 1 deletion horde/consts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HORDE_VERSION = "4.38.1"
HORDE_VERSION = "4.39.0"

WHITELISTED_SERVICE_IPS = {
"212.227.227.178", # Turing Bot
Expand Down
11 changes: 11 additions & 0 deletions horde/database/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@ def get_sorted_wp_filtered_to_worker(worker, models_list=None, blacklist=None, p
worker.speed >= 500000, # 0.5 MPS/s
ImageWaitingPrompt.slow_workers == True, # noqa E712
),
or_(
ImageWaitingPrompt.params["transparent"].astext.cast(Boolean).is_(False),
and_(
check_bridge_capability("layer_diffuse", worker.bridge_agent),
worker.allow_sdxl_controlnet == True, # noqa E712
)
),
)
)
# logger.debug(final_wp_list)
Expand Down Expand Up @@ -1067,6 +1074,10 @@ def count_skipped_image_wp(worker, models_list=None, blacklist=None, priority_us
not check_bridge_capability("tiling", worker.bridge_agent),
ImageWaitingPrompt.params["tiling"].astext.cast(Boolean).is_(True),
),
and_(
not check_bridge_capability("layer_diffuse", worker.bridge_agent),
ImageWaitingPrompt.params["transparent"].astext.cast(Boolean).is_(True),
),
),
).count()
if skipped_bv > 0:
Expand Down
1 change: 1 addition & 0 deletions horde/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"MoreThanMinExtraSourceImage",
"InvalidExtraTexts",
"MissingExtraTexts",
"InvalidTransparency",
]


Expand Down

0 comments on commit 276def2

Please sign in to comment.