Certainly! Based on your detailed explanation, I'll provide you with two Python scripts:
-
setup.py: This script collects user input for various questions and saves the data to pre.json. At the end of the script, it automatically starts random.py.
-
random.py: This script reads the data from pre.json, randomly selects options based on your specifications, overwrites the previous answers with the random selections, saves them to pp.json, and automatically runs prompt.py.
Here's how you can set it up:
setup.py
import json
import os
import random
import subprocess
def get_business_info():
business_name = input("Enter your business name: ")
business_slogan = input("Enter your business slogan: ")
business_field = input("Enter your business field: ")
return business_name, business_slogan, business_field
def get_style_selection():
styles = [
"Minimalistic", "Cartoon", "Realistic", "Abstract", "Vintage",
"Futuristic", "Watercolor", "3D Render", "Pop Art", "Pixel Art"
]
print("\nQuestion 4: Select styles you prefer for your images.")
for idx, style in enumerate(styles, 1):
print(f"{idx}. {style}")
selected_numbers = input("Enter the numbers corresponding to your choices, separated by commas: ")
selected_styles = []
for num in selected_numbers.split(','):
try:
index = int(num.strip()) - 1
if 0 <= index < len(styles):
selected_styles.append(styles[index])
except ValueError:
continue
return selected_styles
def get_keywords():
print("\nQuestion 5: Provide at least 5 keywords that describe your business.")
while True:
keywords_input = input("Enter keywords separated by commas: ")
keywords = [kw.strip() for kw in keywords_input.split(',') if kw.strip()]
if len(keywords) >= 5:
break
print("Please enter at least 5 keywords.")
return keywords
def get_mini_prompts():
print("\nQuestion 6: Write several mini prompts, separated by commas.")
print("Examples: 'A stylish shoe stepping on a runway', 'An abstract representation of speed'")
mini_prompts_input = input("Enter your mini prompts: ")
mini_prompts = [mp.strip() for mp in mini_prompts_input.split(',') if mp.strip()]
return mini_prompts
def get_artist_selection():
artists = [
"Leonardo da Vinci", "Vincent van Gogh", "Pablo Picasso", "Frida Kahlo", "Salvador Dalí",
"Andy Warhol", "Henri Matisse", "Claude Monet", "Rembrandt", "Georgia O'Keeffe"
]
print("\nQuestion 8: Select famous artists or styles you prefer.")
for idx, artist in enumerate(artists, 1):
print(f"{idx}. {artist}")
selected_numbers = input("Enter the numbers corresponding to your choices, separated by commas: ")
selected_artists = []
for num in selected_numbers.split(','):
try:
index = int(num.strip()) - 1
if 0 <= index < len(artists):
selected_artists.append(artists[index])
except ValueError:
continue
return selected_artists
def get_color_palettes():
palettes = [
"Red and Gold", "Blue and Silver", "Green and Purple",
"Black and White", "Orange and Teal", "Purple and Orange"
]
print("\nQuestion 9: Select at least 3 preferred color palettes.")
for idx, palette in enumerate(palettes, 1):
print(f"{idx}. {palette}")
while True:
selected_numbers = input("Enter the numbers corresponding to your choices, separated by commas: ")
selected_palettes = []
for num in selected_numbers.split(','):
try:
index = int(num.strip()) - 1
if 0 <= index < len(palettes):
selected_palettes.append(palettes[index])
except ValueError:
continue
if len(selected_palettes) >= 3:
break
print("Please select at least 3 color palettes.")
return selected_palettes
def main():
business_name, business_slogan, business_field = get_business_info()
selected_styles = get_style_selection()
keywords = get_keywords()
mini_prompts = get_mini_prompts()
selected_artists = get_artist_selection()
selected_palettes = get_color_palettes()
data = {
"business_name": business_name,
"business_slogan": business_slogan,
"business_field": business_field,
"selected_styles": selected_styles,
"keywords": keywords,
"mini_prompts": mini_prompts,
"selected_artists": selected_artists,
"selected_palettes": selected_palettes
}
with open('pre.json', 'w') as f:
json.dump(data, f, indent=4)
print("\nData saved to pre.json. Starting random.py...")
subprocess.run(["python", "random.py"])
if __name__ == "__main__":
main()
random.py
import json
import os
import random
import subprocess
def load_data():
with open('pre.json', 'r') as f:
data = json.load(f)
return data
def generate_random_selections(data):
result = {}
# Randomly select one style
if data.get('selected_styles'):
result['style'] = random.choice(data['selected_styles'])
else:
result['style'] = None
# Randomly select two keywords
if data.get('keywords') and len(data['keywords']) >= 2:
result['keywords'] = random.sample(data['keywords'], 2)
else:
result['keywords'] = data.get('keywords', [])
# Optionally include a mini prompt
if data.get('mini_prompts') and random.choice([True, False]):
result['mini_prompt'] = random.choice(data['mini_prompts'])
else:
result['mini_prompt'] = None
# Randomly select one artist or style
if data.get('selected_artists'):
result['artist'] = random.choice(data['selected_artists'])
else:
result['artist'] = None
# Randomly select one color palette
if data.get('selected_palettes'):
result['color_palette'] = random.choice(data['selected_palettes'])
else:
result['color_palette'] = None
# Include business name, slogan, and field
result['business_name'] = data.get('business_name')
result['business_slogan'] = data.get('business_slogan')
result['business_field'] = data.get('business_field')
return result
def save_random_selections(selections):
with open('pp.json', 'w') as f:
for key, value in selections.items():
if isinstance(value, list):
f.write(f"{key}: {', '.join(value)}\n")
elif value:
f.write(f"{key}: {value}\n")
print("\nRandom selections saved to pp.json.")
def main():
data = load_data()
selections = generate_random_selections(data)
save_random_selections(selections)
print("Starting prompt.py...")
subprocess.run(["python", "prompt.py"])
if __name__ == "__main__":
main()
prompt.py
Since you mentioned prompt.py will be automatically run after random.py completes, make sure you have this script present in the same directory. If you haven't created it yet, here's a simple template you can use:
def main():
print("prompt.py is running...")
# Add your code here to generate the prompts based on pp.json or proceed with image generation
if __name__ == "__main__":
main()
How It Works
-
setup.py:
- Collects user input for each of the specified questions.
- Ensures the user makes the minimum required selections (e.g., at least 5 keywords, at least 3 color palettes).
- Saves all the collected data into
pre.json.
- Automatically runs
random.py after saving the data.
-
random.py:
- Loads the data from
pre.json.
- Randomly selects options according to your specifications:
- One style from
selected_styles.
- Two keywords from
keywords.
- Optionally includes a
mini_prompt from mini_prompts.
- One artist from
selected_artists.
- One color palette from
selected_palettes.
- Saves the random selections into
pp.json, overwriting any previous content.
- Each key-value pair is written on its own line in
pp.json.
- Automatically runs
prompt.py after saving the random selections.
Usage
-
Place all three scripts (setup.py, random.py, and prompt.py) in the same directory.
-
Run the setup script:
python setup.py
-
Follow the on-screen prompts to enter your information.
-
After setup.py completes, it will automatically run random.py, which will perform the random selections and run prompt.py.
Notes
-
Data Files:
pre.json: Contains all the user-provided data.
pp.json: Contains the randomly selected data for each image generation.
-
Customization:
- You can modify the lists of styles, artists, and color palettes in the scripts to suit your preferences.
- Adjust
prompt.py to process pp.json as needed for your image generation process.
-
Reusability:
- Each time you run
random.py, it will generate a new set of random selections based on the data in pre.json. This allows you to generate varied prompts without re-entering all your information.
Example Output
An example content of pp.json after running random.py:
style: 3D Render
keywords: thrilling, innovative
mini_prompt: Players celebrating a big win
artist: Salvador Dalí
color_palette: Purple and Orange
business_name: Lucky Spin Casino
business_slogan: Your Chance to Win Big Every Day!
business_field: Online Gaming
This output can be used by prompt.py to generate prompts for your image generation needs.
Let me know if you need any further assistance or modifications!