This tool allows you to generate hundreds of dress design variations using Stable Diffusion's image-to-image capabilities running locally on your PC.
This setup uses the Automatic1111 WebUI for Stable Diffusion, which provides an easy-to-use API that our Python script will call to generate dress variations based on your input images.
- Windows 10/11, macOS, or Linux
- NVIDIA GPU with at least 4GB VRAM (strongly recommended)
- 16GB RAM recommended
- Python 3.8 or newer
- ~10GB free disk space for models and generated images
-
Clone the Automatic1111 WebUI repository:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git cd stable-diffusion-webui
-
Download a Stable Diffusion model:
- Create a folder named
models/Stable-diffusion
inside the repository folder - Download one of these recommended models:
- Realistic Vision V5.1 (Realistic)
- dreamshaper-8 (All-purpose)
- Place the downloaded model file in the
models/Stable-diffusion
folder
- Create a folder named
-
Launch the WebUI with API enabled:
- Windows: Double-click
webui-user.bat
, then close it and edit the file to add--api
to the COMMANDLINE_ARGS - macOS/Linux: Run
./webui.sh --api
- The first launch will take some time as it downloads additional components
- Windows: Double-click
-
Verify the WebUI is running:
- Open your browser and go to http://127.0.0.1:7860
- You should see the Stable Diffusion WebUI interface
-
Create a project folder for the dress generator:
mkdir dress_generator cd dress_generator
-
Install required Python packages:
pip install requests pillow
-
Create the Python script:
- Create a file named
generate_dress_variations.py
with the content from the script below
- Create a file named
-
Prepare your input image:
- Place a high-quality image of a dress in the same folder
- Name it
dress_image.jpg
- Ideally use fashion runway images with clear lighting and neutral backgrounds
-
Make sure the Stable Diffusion WebUI is running with the API enabled
-
Run the script:
python generate_dress_variations.py
-
Monitor progress:
- The script will show generation progress in the console
- Generated images will be saved in the
dress_variations
folder
import requests
import json
import base64
import io
import os
from PIL import Image
import time
import random
# Configuration
sd_url = "http://127.0.0.1:7860" # Default local WebUI address
input_image_path = "dress_image.jpg" # Your reference dress image
output_folder = "dress_variations"
num_variations = 100 # Number of variations to generate
# Create output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# Load and encode the input image
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
input_image = encode_image(input_image_path)
# Parameters for image generation
params = {
"init_images": [input_image],
"prompt": "a beautiful dress on runway model, fashion show, high quality, detailed fabric",
"negative_prompt": "low quality, blurry, distorted, deformed, bad anatomy, unrealistic proportions",
"denoising_strength": 0.75, # Adjust for more variation (higher) or closer to original (lower)
"seed": -1, # Random seed each time
"batch_size": 1,
"n_iter": 1,
"steps": 30,
"cfg_scale": 7.5,
"width": 512,
"height": 768,
"sampler_name": "DPM++ 2M Karras"
}
# Style and color modifiers for variety
style_modifiers = [
"floral pattern", "polka dot", "striped", "elegant", "vintage",
"modern", "summer", "formal", "casual", "couture", "embroidered",
"lace", "silk", "satin", "cotton", "tulle", "sequined", "minimalist"
]
color_modifiers = [
"red", "blue", "green", "yellow", "purple", "pink", "black", "white",
"teal", "orange", "navy", "burgundy", "emerald", "gold", "silver",
"pastel", "multicolored", "ombre", "monochrome"
]
# Design elements for more variety
design_elements = [
"sleeveless", "short sleeve", "long sleeve", "off-shoulder", "strapless",
"v-neck", "high neck", "halter", "A-line", "fitted", "pleated", "tiered",
"asymmetrical", "midi length", "maxi length", "mini length", "belted"
]
# Generate variations
for i in range(num_variations):
print(f"Generating variation {i+1}/{num_variations}")
# Randomize seed for variety
params["seed"] = random.randint(-1, 2147483647)
# Randomize denoising strength (how much to vary from original)
params["denoising_strength"] = random.uniform(0.65, 0.85)
# Choose random modifiers
style = random.choice(style_modifiers)
color = random.choice(color_modifiers)
design = random.choice(design_elements)
# Build varied prompt
params["prompt"] = f"a beautiful {style} {color} {design} dress on runway model, fashion show, high quality, detailed fabric, professional fashion photography"
# Occasionally add seasonal or occasion-specific modifiers
if random.random() < 0.3:
seasons = ["spring", "summer", "fall", "winter"]
occasions = ["evening", "cocktail", "wedding", "casual", "office", "party"]
extra = random.choice(seasons + occasions)
params["prompt"] += f", {extra} wear"
# Make API request
try:
response = requests.post(url=f'{sd_url}/sdapi/v1/img2img', json=params, timeout=120)
if response.status_code == 200:
r = response.json()
# Save the generated image
for j, image_data in enumerate(r['images']):
image = Image.open(io.BytesIO(base64.b64decode(image_data)))
image_filename = os.path.join(output_folder, f"dress_variation_{i+1}_{j+1}.png")
image.save(image_filename)
print(f"Saved: {image_filename}")
else:
print(f"Error: {response.status_code}")
print(response.text)
except Exception as e:
print(f"Request error: {e}")
# Add a small delay to prevent overwhelming the API
time.sleep(1)
print("All variations generated!")
-
WebUI not starting:
- Check Python version (must be 3.8+)
- For NVIDIA GPUs, ensure you have the latest graphics drivers
- Try running with
--skip-torch-cuda-test
flag
-
API connection refused:
- Ensure WebUI is running with
--api
flag - Check that the URL in the script matches your WebUI address (default: http://127.0.0.1:7860)
- Ensure WebUI is running with
-
Out of memory errors:
- Reduce image dimensions in the script (e.g., 512x512)
- Reduce the steps parameter (20-30 is usually sufficient)
- Use
--medvram
or--lowvram
flags when starting the WebUI
-
Slow generation:
- Normal for CPU-only systems (consider using Google Colab instead)
- Reduce steps parameter
- Use faster samplers like "Euler a"
- Stable Diffusion WebUI Documentation
- Prompt Engineering Guide
- Additional Models - CivitAI for more specialized models
You can modify the script parameters to:
- Change the number of variations
- Adjust how different each variation will be from the original
- Modify the style, color, and design prompts
- Change the output image dimensions and quality
For more advanced customization, explore ControlNet extensions in the WebUI, which allow for more precise control over pose, layout, and design elements.