add output_blank_ratio and temp_override inputs

This commit is contained in:
Raqueebuddin Aziz
2023-12-03 02:05:57 +05:30
parent b338cb4bb2
commit 98ecefe178
2 changed files with 30 additions and 9 deletions
+2
View File
@@ -31,6 +31,8 @@ The files should end in `.txt` and each value should be on it's own line.
- `prefix(STRING)`: The prefix to use
- `suffix(STRING)`: The suffix to use
- `regex(STRING)`: If provided this will be used to filter the input files.
- `temp_override(STRING)`: If not blank then overrides the output.
- `output_blank_ratio(FLOAT)`: A number between 0 and 1 to determine if the output should be blank. Not used if temp_override is set.
### outputs
+28 -9
View File
@@ -56,6 +56,14 @@ class SimpleWildcard:
"STRING",
{"default": ".*"},
),
"temp_override": (
"STRING",
{"default": ""},
),
"output_blank_ratio": (
"FLOAT",
{"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.05},
),
"output_text": (
"STRING",
{"multiline": True, "dynamicPrompts": False, "default": ""},
@@ -69,21 +77,32 @@ class SimpleWildcard:
OUTPUT_NODE = True
def func(self, *args, **kwargs):
if kwargs["temp_override"] != "":
return {
"ui": {"output_text": kwargs["temp_override"]},
"result": (kwargs["temp_override"],),
}
rng = random.Random(kwargs["seed"])
if rng.random() < kwargs["output_blank_ratio"]:
return {
"ui": {"output_text": ""},
"result": ("",),
}
output_text = kwargs["input_text"]
items = get_items_for_wildcard_path(kwargs["input_files"])
if kwargs["regex"] != "*" or kwargs["regex"] != "":
regex = re.compile(kwargs["regex"], re.IGNORECASE)
items = list(items | where(regex.match))
has_items = len(items) > 0
wildcard_mode_enabled = kwargs["input_text"] == "*"
should_apply_weight = kwargs["weight"] != 1
if wildcard_mode_enabled:
items = get_items_for_wildcard_path(kwargs["input_files"])
if kwargs["regex"] != "*" or kwargs["regex"] != "":
regex = re.compile(kwargs["regex"], re.IGNORECASE)
items = list(items | where(regex.match))
has_items = len(items) > 0
if has_items:
random.seed(kwargs["seed"])
output_text = random.choice(items)
output_text = rng.choice(items)
else:
output_text = ""