mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-25 15:55:18 +00:00
fixed indentation
This commit is contained in:
parent
a1bcc45da5
commit
19fd53dbb3
@ -232,27 +232,27 @@ class SDClipModel(torch.nn.Module, ClipTokenWeightEncoder):
|
|||||||
return self.transformer.load_state_dict(sd, strict=False)
|
return self.transformer.load_state_dict(sd, strict=False)
|
||||||
|
|
||||||
def parse_parentheses(string):
|
def parse_parentheses(string):
|
||||||
"""
|
"""
|
||||||
Split a string based off top-level nested parentheses.
|
Split a string based off top-level nested parentheses.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
string : str
|
string : str
|
||||||
The string to be split into its top nested groups.
|
The string to be split into its top nested groups.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
result : list
|
result : list
|
||||||
A list of each element in string, split by top-level elements
|
A list of each element in string, split by top-level elements
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
>>> string = "(foo)(bar)"
|
>>> string = "(foo)(bar)"
|
||||||
['(foo)', '(bar)']
|
['(foo)', '(bar)']
|
||||||
|
|
||||||
>>> string = "(foo(bar)(test1))(test2(test3))"
|
>>> string = "(foo(bar)(test1))(test2(test3))"
|
||||||
['(foo(bar)(test1))', '(test2(test3))']
|
['(foo(bar)(test1))', '(test2(test3))']
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
current_item = ""
|
current_item = ""
|
||||||
nesting_level = 0
|
nesting_level = 0
|
||||||
@ -281,75 +281,75 @@ def parse_parentheses(string):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def token_weights(string, current_weight):
|
def token_weights(string, current_weight):
|
||||||
"""
|
"""
|
||||||
Find the requested weight of a token, and multiply it by the current weight. For parentheses groupings with no set weight, multiply by 1.1.
|
Find the requested weight of a token, and multiply it by the current weight. For parentheses groupings with no set weight, multiply by 1.1.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
string : str
|
string : str
|
||||||
The input of tokens to calculate requested weights for
|
The input of tokens to calculate requested weights for
|
||||||
current_weight : float
|
current_weight : float
|
||||||
The current weight of all tokens
|
The current weight of all tokens
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
out : list
|
out : list
|
||||||
A list of each token paired with the calculated weight
|
A list of each token paired with the calculated weight
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
>>> string = "(foo)"
|
>>> string = "(foo)"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 1.1)]
|
[('foo', 1.1)]
|
||||||
|
|
||||||
>>> string = "(foo)(bar)"
|
>>> string = "(foo)(bar)"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 1.1), ('bar', 1.1)]
|
[('foo', 1.1), ('bar', 1.1)]
|
||||||
|
|
||||||
>>> string = "(foo:2.0)"
|
>>> string = "(foo:2.0)"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 2.0)]
|
[('foo', 2.0)]
|
||||||
|
|
||||||
>>> string = "((foo))"
|
>>> string = "((foo))"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 1.21)]
|
[('foo', 1.21)]
|
||||||
|
|
||||||
>>> string = "((foo):1.1)"
|
>>> string = "((foo):1.1)"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 1.21)]
|
[('foo', 1.21)]
|
||||||
|
|
||||||
>>> string = "((foo:1.1))"
|
>>> string = "((foo:1.1))"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 1.1)]
|
[('foo', 1.1)]
|
||||||
|
|
||||||
>>> string = "(foo:0.0)"
|
>>> string = "(foo:0.0)"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 0.0)]
|
[('foo', 0.0)]
|
||||||
|
|
||||||
>>> string = "((foo:1.0):0.0)"
|
>>> string = "((foo:1.0):0.0)"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo', 1.0)]
|
[('foo', 1.0)]
|
||||||
|
|
||||||
>>> string = "foo ((((lol (cat:666) attack:100)))) baz"
|
>>> string = "foo ((((lol (cat:666) attack:100)))) baz"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo ', 1.0), ('lol ', 100.0), ('cat', 666.0), (' attack', 100.0), (' baz', 1.0)]
|
[('foo ', 1.0), ('lol ', 100.0), ('cat', 666.0), (' attack', 100.0), (' baz', 1.0)]
|
||||||
|
|
||||||
>>> string = "foo ((((lol (cat:666) attack):100))) baz"
|
>>> string = "foo ((((lol (cat:666) attack):100))) baz"
|
||||||
>>> current_weight = 1.0
|
>>> current_weight = 1.0
|
||||||
[('foo ', 1.0), ('lol ', 110.0), ('cat', 666.0), (' attack', 110.0), (' baz', 1.0)]
|
[('foo ', 1.0), ('lol ', 110.0), ('cat', 666.0), (' attack', 110.0), (' baz', 1.0)]
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
-----
|
-----
|
||||||
See issue #4610 for more detail. One thing to note is that the default of 1.1 is multiplied
|
See issue #4610 for more detail. One thing to note is that the default of 1.1 is multiplied
|
||||||
when there is no weight defined on the *interior* of the group instead of the exterior. This
|
when there is no weight defined on the *interior* of the group instead of the exterior. This
|
||||||
behavior can be seen in the last two examples (thank you @jart for making these). In the first
|
behavior can be seen in the last two examples (thank you @jart for making these). In the first
|
||||||
example, the weight of 100 is defined inside the same parentheses grouping as both 'lol' and
|
example, the weight of 100 is defined inside the same parentheses grouping as both 'lol' and
|
||||||
'attack'. There is no parentheses between the defined weight and the tokens, so there is no
|
'attack'. There is no parentheses between the defined weight and the tokens, so there is no
|
||||||
multiplication of the weight by 1.1. In the second example, the weight is outside the parentheses
|
multiplication of the weight by 1.1. In the second example, the weight is outside the parentheses
|
||||||
grouping, so the weights inside the grouping are first given a modifier of 1.1, then given a
|
grouping, so the weights inside the grouping are first given a modifier of 1.1, then given a
|
||||||
modifier of 100.
|
modifier of 100.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
a = parse_parentheses(string)
|
a = parse_parentheses(string)
|
||||||
out = []
|
out = []
|
||||||
for x in a:
|
for x in a:
|
||||||
@ -371,55 +371,55 @@ def token_weights(string, current_weight):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def escape_important(text):
|
def escape_important(text):
|
||||||
"""
|
"""
|
||||||
Replace parentheses marked via backslashes with escape characters
|
Replace parentheses marked via backslashes with escape characters
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
text : str
|
text : str
|
||||||
The string to have its important parentheses replaced
|
The string to have its important parentheses replaced
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
text : str
|
text : str
|
||||||
The input string, with important parentheses replaced
|
The input string, with important parentheses replaced
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
>>> text = "\\(foo\\)(bar)"
|
>>> text = "\\(foo\\)(bar)"
|
||||||
"\0\2foo\0\1(bar)"
|
"\0\2foo\0\1(bar)"
|
||||||
|
|
||||||
See Also
|
See Also
|
||||||
--------
|
--------
|
||||||
unescape_important : Replace escape characters with parentheses
|
unescape_important : Replace escape characters with parentheses
|
||||||
"""
|
"""
|
||||||
text = text.replace("\\)", "\0\1")
|
text = text.replace("\\)", "\0\1")
|
||||||
text = text.replace("\\(", "\0\2")
|
text = text.replace("\\(", "\0\2")
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def unescape_important(text):
|
def unescape_important(text):
|
||||||
"""
|
"""
|
||||||
Replace escape characters made via escape_important with parentheses
|
Replace escape characters made via escape_important with parentheses
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
text : str
|
text : str
|
||||||
The string to have its escape characters replaced
|
The string to have its escape characters replaced
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
text : str
|
text : str
|
||||||
The input string, with escape characters replaced
|
The input string, with escape characters replaced
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
>>> text = "\0\2foo\0\1(bar)"
|
>>> text = "\0\2foo\0\1(bar)"
|
||||||
"(foo)(bar)"
|
"(foo)(bar)"
|
||||||
|
|
||||||
See Also
|
See Also
|
||||||
--------
|
--------
|
||||||
escape_important: makes strings with the escape characters this function uses
|
escape_important: makes strings with the escape characters this function uses
|
||||||
"""
|
"""
|
||||||
text = text.replace("\0\1", ")")
|
text = text.replace("\0\1", ")")
|
||||||
text = text.replace("\0\2", "(")
|
text = text.replace("\0\2", "(")
|
||||||
return text
|
return text
|
||||||
@ -444,19 +444,19 @@ def safe_load_embed_zip(embed_path):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def expand_directory_list(directories):
|
def expand_directory_list(directories):
|
||||||
"""
|
"""
|
||||||
For all directories in a list, list all subdirectories beneath them
|
For all directories in a list, list all subdirectories beneath them
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
directories : list
|
directories : list
|
||||||
The list of directories to search for subdirectories with
|
The list of directories to search for subdirectories with
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
dirs : list
|
dirs : list
|
||||||
A list of all subdirectories found underneath the given directories
|
A list of all subdirectories found underneath the given directories
|
||||||
"""
|
"""
|
||||||
dirs = set()
|
dirs = set()
|
||||||
for x in directories:
|
for x in directories:
|
||||||
dirs.add(x)
|
dirs.add(x)
|
||||||
|
Loading…
Reference in New Issue
Block a user