05.20.24

A quick script for creating prompt permutations for StableDiffusion

So, I enjoy making stuff in StableDiffusion and in the WebUI interface is an option for a prompt list. I like using the Prompt S/R in the scripts but it tends to top out after about 1500 permutations. Here is a script for generating those in as many dimensions as you want.

import itertools

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):
    # Create all combinations of modifiers
    all_combinations = list(itertools.product(*modifiers))
    
    permutations = []
    for combination in all_combinations:
        new_prompt = prompt
        for original, replacement in zip(modifiers, combination):
            new_prompt = replace_first(new_prompt, original[0], replacement)
        permutations.append(new_prompt)
    
    return permutations

def replace_first(text, search, replacement):
    # Helper function to replace only the first occurrence of a term
    if search not in text:
        raise ValueError(f"Term '{search}' not found in the prompt.")
    return text.replace(search, replacement, 1)

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

def main(input_file_path, output_file_path):
    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:]]

    try:
        all_permutations = generate_permutations(prompt, 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__":
    input_file_path = 'testprompt.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
    main(input_file_path, output_file_path)

This Python script will allow you to generate a permutation of a prompt based on the original words that are in the prompt. So, for example, here is the prompt file with the first line being the raw prompt and the following lines being the search and replace terms:

A beautiful flower sitting on a wooden table. in a kitchen
beautiful flower, tall woman, eager beaver, soup can
sitting, jumping, glowering

This will generate the following in output.txt

A beautiful flower sitting on a wooden table. in a kitchen
A beautiful flower jumping on a wooden table. in a kitchen
A beautiful flower glowering on a wooden table. in a kitchen
A tall woman sitting on a wooden table. in a kitchen
A tall woman jumping on a wooden table. in a kitchen
A tall woman glowering on a wooden table. in a kitchen
A eager beaver sitting on a wooden table. in a kitchen
A eager beaver jumping on a wooden table. in a kitchen
A eager beaver glowering on a wooden table. in a kitchen
A soup can sitting on a wooden table. in a kitchen
A soup can jumping on a wooden table. in a kitchen
A soup can glowering on a wooden table. in a kitchen

So, the strings “Beautiful flower” and “sitting” and the following terms are replaced in the original prompt. So, in this case you have 4 terms in the first term line (line 2) and 3 terms in the second term line so, 4 time 3 is 12. All 12 permutations of that prompt are outputted to a file. It will tell you the total number of permutations and throw an error when a term isn’t found.

I make no guarantees about this script, enjoy anyways.

| Posted in Programming | Comments Off on A quick script for creating prompt permutations for StableDiffusion
05.9.24

Some of my AI ‘art’

I’m not stupid enough to consider plugging in some prompts to a diffusion AI to be art but I enjoy it nonetheless. Also, I’m aware of the copyright, moral and overall societal implications of it. That’s not for me to solve. Here are a few of my favorites from December 2023 to February 2024.

| Posted in Uncategorized | Comments Off on Some of my AI ‘art’
05.8.24

An RTJ chart

Here is a chart for RTJ ring groove facings. It’s very specific to my own use case but maybe somebody else will find it useful. I guarantee nothing, if you use it, it’s at your own risk. Bottom width is the size at the bottom of the groove, Largest Ball is the largest ball that will sit tangent at the top of the groove, and well, Smallest is the one that will sit on the bottom and touch the two sides. Obviously you want to be somewhere between, not at, theses sizes. Also, the lists on the bottom denote the Depth, Width sets and the numbers that follow are the R sizes that match that set.

| Posted in Machining, Miscellaneous stuff | Comments Off on An RTJ chart
04.27.24

CMM, a test video

So, I was measuring a plate on our Mitutoyo CMM yesterday and I figured it’d be a good test to see how videos embed on WordPress these days. When I started this site the first time, you could not embed videos very easily and you had to embed with either YouTube or whatever other video service was available. Still, the limit is only 512MB but, hey, good enough. That’s almost enough for a movie.

This was a plate we needed to grind flat withing a few thou. Worked out well.

Tags: , ,
| Posted in Machining | Comments Off on CMM, a test video
04.25.24

A new die/punch housing

Just finished a new die/punch housing for use on an old press. Works well and allows you to index at different distances. The initial drawing was kind of wrong when I drew it but I just shifted it a bit to work given the machine.

| Posted in Design, Machining | Comments Off on A new die/punch housing
04.22.24

A new start

Well, one can always begin anew. The last site had some bugs, stuff accumulated over the course of 15 years. It should be said that I probably could have fixed the issue with a bit of elbow grease but I felt as though it’d be good to start something fresh and start updating again.

Anyways, Thanks for coming!