GithubHelp home page GithubHelp logo

Comments (2)

tazztone avatar tazztone commented on September 15, 2024 4

claude 3.5 told me how to fix it

  1. i asked how do i fix this error?.
  2. it told me to mod the file magic_prompt.py.
  3. i pasted the file's content and asked how to modify to fix it.

amazingly it gave me this working code to replace with:

import re
from itertools import zip_longest
import torch
from dynamicprompts.generators.magicprompt import MagicPromptGenerator
from sd_dynamic_prompts.special_syntax import (
    append_chunks,
    remove_a1111_special_syntax_chunks,
)

def massage_prompt(prompt: str) -> str:
    # Coalesce repeated punctuation to a single instance
    prompt = re.sub(r"([.,])\1+", r"\1", prompt)
    # Remove leading/trailing whitespace
    prompt = prompt.strip()
    return prompt

class SpecialSyntaxAwareMagicPromptGenerator(MagicPromptGenerator):

    """
    Magic Prompt generator that is aware of A1111 special syntax (LoRA, hypernet, etc.).
    """
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        self.model.to(self.device)

    def _generate_magic_prompts(self, orig_prompts: list[str]) -> list[str]:
        orig_prompts, chunks = zip(
            *(remove_a1111_special_syntax_chunks(p) for p in orig_prompts),
        )
        
        # Move input to the correct device
        input_ids = self.tokenizer(list(orig_prompts), return_tensors="pt", padding=True).input_ids
        input_ids = input_ids.to(self.device)
        
        # Generate the magic prompts
        with torch.no_grad():
            output = self.model.generate(
                input_ids,
                max_length=100,
                num_return_sequences=1,
                no_repeat_ngram_size=2
            )
        
        # Decode the output
        magic_prompts = self.tokenizer.batch_decode(output, skip_special_tokens=True)
        
        # Massage the prompts
        magic_prompts = [massage_prompt(prompt) for prompt in magic_prompts]
        
        # Append chunks and return
        return [
            append_chunks(prompt, chunk)
            for prompt, chunk in zip_longest(magic_prompts, chunks, fillvalue=None)
        ]

so if anyone has the same error as me and wants to fix it: just overwrite/replace the above code into \stable-diffusion-webui-forge\extensions\sd-dynamic-prompts\sd_dynamic_prompts\magic_prompt.py, save it and restart forge

from sd-dynamic-prompts.

chaewai avatar chaewai commented on September 15, 2024 1

Thanks for sharing the fix, had the same problem!

from sd-dynamic-prompts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.