Skip to content

Commit

Permalink
Merge pull request #12177 from rubberbaron/prompt-parse-whitespace-ar…
Browse files Browse the repository at this point in the history
…ound-numbers

add support for whitespace after the number in constructions like [fo…
  • Loading branch information
AUTOMATIC1111 authored Jul 30, 2023
2 parents f60d9fb + 8a40e30 commit a1eb496
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions modules/prompt_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
!emphasized: "(" prompt ")"
| "(" prompt ":" prompt ")"
| "[" prompt "]"
scheduled: "[" [prompt ":"] prompt ":" [WHITESPACE] NUMBER "]"
scheduled: "[" [prompt ":"] prompt ":" [WHITESPACE] NUMBER [WHITESPACE] "]"
alternate: "[" prompt ("|" prompt)+ "]"
WHITESPACE: /\s+/
plain: /([^\\\[\]():|]|\\.)+/
Expand Down Expand Up @@ -60,11 +60,11 @@ def collect_steps(steps, tree):

class CollectSteps(lark.Visitor):
def scheduled(self, tree):
tree.children[-1] = float(tree.children[-1])
if tree.children[-1] < 1:
tree.children[-1] *= steps
tree.children[-1] = min(steps, int(tree.children[-1]))
res.append(tree.children[-1])
tree.children[-2] = float(tree.children[-2])
if tree.children[-2] < 1:
tree.children[-2] *= steps
tree.children[-2] = min(steps, int(tree.children[-2]))
res.append(tree.children[-2])

def alternate(self, tree):
res.extend(range(1, steps+1))
Expand All @@ -75,7 +75,7 @@ def alternate(self, tree):
def at_step(step, tree):
class AtStep(lark.Transformer):
def scheduled(self, args):
before, after, _, when = args
before, after, _, when, _ = args
yield before or () if step <= when else after
def alternate(self, args):
yield next(args[(step - 1)%len(args)])
Expand Down Expand Up @@ -333,7 +333,7 @@ def reconstruct_multicond_batch(c: MulticondLearnedConditioning, current_step):
\\|
\(|
\[|
:([+-]?[.\d]+)\)|
:\s*([+-]?[.\d]+)\s*\)|
\)|
]|
[^\\()\[\]:]+|
Expand Down

0 comments on commit a1eb496

Please sign in to comment.