Alvi-alvarez / sd-Img2img-batch-interrogator

Img2img batch interrogator for AUTOMATIC1111's Stable Diffusion web UI
MIT License
18 stars 3 forks source link

Filtering Patch 1 #6

Closed SmirkingKitsune closed 4 months ago

SmirkingKitsune commented 4 months ago

Two new toggles to filter prompt content from interrogator prompt output.

  1. Negative prompt content filtered from the interrogator prompt output (Removes contradictions from the prompt)
  2. Prompt content filtered from the interrogator prompt output (Removes duplicates from the prompt)

Both toggles are toggled disabled by default to maintain normal vanilla operation.

Additional housekeeping change, Script.interrogator changed to interrogator, as Script.interrogator no longer exists.

So I thought it would be nice if the interrogator did not produce content that contradicted the negative prompt. Such as in the case when you put an image with flowers but you have flowers in the negative prompt. This will ensure that the interrogator prompt does not add contradictory keywords to the prompt. This should not remove keywords from the negative prompt. Note, that this should only remove exact keywords from the interrogation prompt.

I reused the code for negative prompt removal for duplicate prompt content removal. Such as in the case where the interrogator prompt says flowers but the raw prompt already has flowers. I think this might assist with memory footprint while SD is running.

There are a lot of regex substitutions to remove the attention annotation that might be in the prompt or negative prompt. I think that there might be a more efficient way to perform these regex substitutions, but I was unable to achieve a more efficient method. However, I also think that any inefficiency here would still improve SD efficiency, and since it is disabled by default, any potential inefficiency could be opted out of. Technically optimizing the regex to one or two lines would still get O(n), so it would probably be the same big-O time, so optimization of the regex might not do anything. I will include test cases for regex substitution if anyone wants to attempt to improve the regex substitution.

Test cases: "man, (beard, happy), fishing:404, (moon, stars:4.04)" "((boy, girl)), (lily \(flower\)), rose \(flower\)"

Expected output: "man, beard, happy, fishing, moon, stars" "boy, girl, lily \(flower\), rose \(flower\)"

Alvi-alvarez commented 4 months ago

Merged. I added it under Deepbooru tools in case more modifiers for the prompt are added in the future.

SmirkingKitsune commented 4 months ago

Alright, awesome!