Extract text and weights from prompts with (text:weight) format
(self, prompt)
| 434 | return (prompt_embeds_dict,) |
| 435 | |
| 436 | def parse_prompt_weights(self, prompt): |
| 437 | """Extract text and weights from prompts with (text:weight) format""" |
| 438 | import re |
| 439 | |
| 440 | # Parse all instances of (text:weight) in the prompt |
| 441 | pattern = r'\((.*?):([\d\.]+)\)' |
| 442 | matches = re.findall(pattern, prompt) |
| 443 | |
| 444 | # Replace each match with just the text part |
| 445 | cleaned_prompt = prompt |
| 446 | weights = {} |
| 447 | |
| 448 | for match in matches: |
| 449 | text, weight = match |
| 450 | orig_text = f"({text}:{weight})" |
| 451 | cleaned_prompt = cleaned_prompt.replace(orig_text, text) |
| 452 | weights[text] = float(weight) |
| 453 | |
| 454 | return cleaned_prompt, weights |
| 455 | |
| 456 | class WanVideoTextEncodeSingle: |
| 457 | @classmethod |