Skip to content

Commit

Permalink
fix: style reward
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 committed Nov 7, 2024
1 parent 0737c27 commit df46f0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later

* Allow trusted users to also create styles
* Fix styles always returning 1 image
* Fix style reward not being taken from the requesting user

# 4.44.1

Expand Down
7 changes: 6 additions & 1 deletion horde/apis/v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def post(self):
# It causes them to be a shared object from the parsers class
self.params = {}
self.warnings = set()
self.style_kudos = False
if self.args.params:
self.params = self.args.params
self.models = []
Expand Down Expand Up @@ -349,7 +350,11 @@ def activate_waiting_prompt(self):
_,
_,
) = ensure_source_image_uploaded(eimg["image"], f"{self.wp.id}_exra_src_{iiter}", force_r2=True)
self.wp.activate(self.downgrade_wp_priority, extra_source_images=self.args.extra_source_images)
self.wp.activate(
self.downgrade_wp_priority,
extra_source_images=self.args.extra_source_images,
kudos_adjustment=2 if self.style_kudos is True else 0,
)


class SyncGenerate(GenerateTemplate):
Expand Down
5 changes: 3 additions & 2 deletions horde/apis/v2/kobold.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def apply_style(self):
self.existing_style = database.get_style_by_uuid(self.args.style)
if not self.existing_style:
self.existing_style = database.get_style_by_name(self.args.style)
logger.debug(self.existing_style)
if not self.existing_style:
raise e.ThingNotFound("Style", self.args.style)
if self.existing_style.style_type != "text":
Expand All @@ -209,7 +208,9 @@ def apply_style(self):
self.params["n"] = requested_n
self.nsfw = self.existing_style.nsfw
self.existing_style.use_count += 1
self.existing_style.user.record_style(2, "text")
if self.existing_style.user != self.user:
self.existing_style.user.record_style(2, "text")
self.style_kudos = True
db.session.commit()
logger.debug(f"Style '{self.args.style}' applied.")

Expand Down
8 changes: 6 additions & 2 deletions horde/apis/v2/stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def activate_waiting_prompt(self):
source_image=self.source_image,
source_mask=self.source_mask,
extra_source_images=self.args.extra_source_images,
kudos_adjustment=2 if self.existing_style is not None else 0,
)

def apply_style(self):
Expand All @@ -372,8 +373,8 @@ def apply_style(self):
if isinstance(self.existing_style, StyleCollection):
colstyles = self.existing_style.styles
random.shuffle(colstyles)
self.existing_style.use_count += 1
self.existing_style = colstyles[0]
self.existing_style.use_count += 1
self.models = self.existing_style.get_model_names()
self.negprompt = ""
if "###" in self.args.prompt:
Expand All @@ -388,7 +389,10 @@ def apply_style(self):
self.params["n"] = requested_n
self.nsfw = self.existing_style.nsfw
self.existing_style.use_count += 1
self.existing_style.user.record_style(2, "image")
# We don't reward kudos to ourselves
if self.existing_style.user != self.user:
self.existing_style.user.record_style(2, "image")
self.style_kudos = True
db.session.commit()
logger.debug(f"Style '{self.args.style}' applied.")

Expand Down

0 comments on commit df46f0c

Please sign in to comment.