08.25.24

New prompt permutation script

A while back I made a prompt permutation script for generating large numbers of image prompts for use in automatic1111. I updated it with a new operator, the incremental operator ‘&’ so it will cycle through the list items instead of choosing random ones. Here is a sample prompt and output. Basically a fancy search and replace but I use it quite often.

photo, a %SIZE brutalist &BUILDING on a sunny day (this is the base prompt)
photo, painting
brutalist, post-modern, deconstructivism
sunny day, night time
%SIZE, small, medium, large, huge
&BUILDING, house, tower, factory, school
Output:
photo, a small brutalist house on a sunny day
photo, a huge brutalist tower on a night time
photo, a medium post-modern factory on a sunny day
photo, a medium post-modern school on a night time
photo, a medium deconstructivism house on a sunny day
photo, a large deconstructivism tower on a night time
painting, a medium brutalist factory on a sunny day
painting, a small brutalist school on a night time
painting, a huge post-modern house on a sunny day
painting, a small post-modern tower on a night time
painting, a large deconstructivism factory on a sunny day
painting, a medium deconstructivism school on a night time

Anyways, here is the python script along with an html version so you can use it with an interface of sorts.

http://smackaay.com/files/ppermute/ppermute.html The little webpage for it.

Here is the python script.

import itertools
import random

# File path assignments
INPUT_FILE_PATH = 'img5.txt'  # Change this to the path of your input file
OUTPUT_FILE_PATH = 'output.txt'  # Change this to the desired path for the output file

def load_file(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()
    return [line.strip() for line in lines]

def generate_permutations(prompt, modifiers, random_modifiers, increment_modifiers):
    all_combinations = list(itertools.product(*modifiers))
    
    permutations = []
    increment_counters = {key: 0 for key in increment_modifiers.keys()}
    
    for combination in all_combinations:
        new_prompt = prompt
        for original, replacement in zip(modifiers, combination):
            new_prompt = replace_first(new_prompt, original[0], replacement)
        
        # Handle random modifiers
        for placeholder, values in random_modifiers.items():
            if placeholder in new_prompt:
                replacement = random.choice(values)
                new_prompt = new_prompt.replace(placeholder, replacement, 1)
        
        # Handle increment modifiers
        for placeholder, values in increment_modifiers.items():
            if placeholder in new_prompt:
                replacement = values[increment_counters[placeholder] % len(values)]
                new_prompt = new_prompt.replace(placeholder, replacement, 1)
                increment_counters[placeholder] += 1
        
        # Remove placeholders from the final prompt
        new_prompt = remove_placeholders(new_prompt, random_modifiers.keys() | increment_modifiers.keys())
        
        permutations.append(new_prompt)
    
    return permutations

def replace_first(text, search, replacement):
    if search not in text:
        raise ValueError(f"Term '{search}' not found in the prompt.")
    return text.replace(search, replacement, 1)

def remove_placeholders(text, placeholders):
    for placeholder in placeholders:
        text = text.replace(placeholder, "")
    return text

def save_to_file(output_path, permutations):
    with open(output_path, 'w') as file:
        for permutation in permutations:
            file.write(permutation + '\n')

def main():
    lines = load_file(INPUT_FILE_PATH)
    if not lines:
        print("The input file is empty.")
        return

    prompt = lines[0]
    modifiers = [line.split(', ') for line in lines[1:] if not line.startswith('%') and not line.startswith('&')]
    random_modifiers = {}
    increment_modifiers = {}
    
    for line in lines[1:]:
        if line.startswith('%'):
            parts = line.split(', ')
            key = parts[0]
            values = parts[1:]
            random_modifiers[key] = values
        elif line.startswith('&'):
            parts = line.split(', ')
            key = parts[0]
            values = parts[1:]
            increment_modifiers[key] = values

    try:
        all_permutations = generate_permutations(prompt, modifiers, random_modifiers, increment_modifiers)
        save_to_file(OUTPUT_FILE_PATH, all_permutations)
        print(f"Generated prompts have been saved to {OUTPUT_FILE_PATH}")
        print(f"Total number of permutations: {len(all_permutations)}")
    except ValueError as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

Tags: , , , ,
| Posted in Personal stuff, Programming | Comments Off on New prompt permutation script
08.5.24

The YouTube Recycle Bin

I was watching a video from a youtuber KVN AUST. The video: https://youtu.be/8uHFm6LK6PE?si=SLIaCEzNBx_iL97V It featured a map for looking at and searching for odd videos across YouTube. It’s pretty fun just to see little slices of life or weird things people would bother uploading so I made a little JS proggy to generate the most common search terms.

Select the prefix and the type of random term you want to find, click on Generate Search Term and then click Search on YouTube. You can select No Spaces or With Quotes if certain things don’t work. The random date is anything in the last 20 years. Enjoy!

YouTube Recycle Bin Search Generator




Tags: , ,
| Posted in Personal stuff, Programming | Comments Off on The YouTube Recycle Bin
05.25.24

Calgary Zoo and Torrington Gopher Museum

Last weekend we decided to go with my parents for a quick trip to our neighbors to the south and visit the Calgary Zoo, It was a big place. Lots of cool animals, nice facilities. everything was pretty good.

Here’s a few images as well from the zoo. It was overcast for the most part so it wasn’t great for photography but it was ok.

So, we went to Crossiron Mills and New Horizons Mall. I quite liked New Horizons. If I want to go to one of the 3 quintillion trash stores, I can find them at CrossIron Mills. If I want to see some smaller businesses where they sell things the owners know and give a crap about, I’ll go to New Horizons. Unfortunately it doesn’t seem to be terribly successful even a few years later from opening. Oddly enough, I think the location is wrong for that kind of business style. But whatever.

We took a detour to Torrington where the have the WORLD FAMOUS GOPHER HOLE MUSEUM!!! It’s a charming little museum with dioramas of taxidermy gophers in various settings. Cute in it’s own way. It was surprisingly busy and they seem to really care about their museum and town proper. very cool.

Anyways, http://worldfamousgopherholemuseum.ca/ is a fun little place. go check it out!

Tags: , , , , ,
| Posted in Personal stuff | Comments Off on Calgary Zoo and Torrington Gopher Museum