Skip to content

Commit

Permalink
Fix processing with A1111 hires fix. (#4)
Browse files Browse the repository at this point in the history
# Pull Request

## Description

Fixes processing A1111 hr prompts.

Fixes #3 

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

**Test Configuration**:

- A1111 v1.6
- SD.Next

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
- [x] I have checked my code and corrected any misspellings
  • Loading branch information
acorderob authored Oct 14, 2023
2 parents 5a87292 + 496117e commit f59b3e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion scripts/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self):
self.callbacks_added = True

def title(self):
return f"{SendToNegative.NAME} v{SendToNegative.VERSION}"
return SendToNegative.NAME

def show(self, is_img2img):
return scripts.AlwaysVisible
Expand All @@ -36,6 +36,12 @@ def process(self, p: StableDiffusionProcessing, *args, **kwargs):
p.all_prompts[i], p.all_negative_prompts[i] = stn.process_prompt(
p.all_prompts[i], p.all_negative_prompts[i]
)
# make it compatible with A1111 hires fix
if hasattr(p, "all_hr_prompts") and hasattr(p, "all_hr_negative_prompts"):
for i in range(len(p.all_hr_prompts)): # pylint: disable=consider-using-enumerate
p.all_hr_prompts[i], p.all_hr_negative_prompts[i] = stn.process_prompt(
p.all_hr_prompts[i], p.all_hr_negative_prompts[i]
)

def __on_ui_settings(self):
section = ("send-to-negative", SendToNegative.NAME)
Expand Down
8 changes: 6 additions & 2 deletions sendtonegative.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SendToNegative: # pylint: disable=too-few-public-methods
NAME = "Send to Negative"
VERSION = "2.1.3"
VERSION = "2.1.4"

DEFAULT_SEPARATOR = ", "

Expand Down Expand Up @@ -163,7 +163,11 @@ def negtag(self, tree):
parameters = negtagparameters.children[0].value if negtagparameters is not None else ""
rest = []
for x in tree.children[1::]:
rest.append(self.__prompt[x.meta.start_pos : x.meta.end_pos] if hasattr(x, "meta") and not x.meta.empty else x.value)
rest.append(
self.__prompt[x.meta.start_pos : x.meta.end_pos]
if hasattr(x, "meta") and not x.meta.empty
else x.value
)
content = "".join(rest)
self.__negtags.append(
self.NegTag(tree.meta.start_pos, tree.meta.end_pos, content, parameters, self.__shell.copy())
Expand Down

0 comments on commit f59b3e5

Please sign in to comment.