I've been working on a project to refresh our corporate website, and we needed a library of unique, abstract background images that felt modern but weren't stock photography. Since we have some budget for experimentation, I set up a Stable Diffusion workflow to generate these in-house. I wanted to share the pipeline because it touches on cost control, reproducible outputs, and automationβright up our alley as cloud folks.
My core setup uses Automatic1111's WebUI running on an AWS EC2 instance (`g4dn.xlarge` for the GPU), but I only spin it up for batch jobs. The key was moving from manual prompting to a parameterized script. Here's the basic Python snippet I use with the API to ensure consistency:
```python
import requests
import json
payload = {
"prompt": "(ethereal fluid art:1.2), (organic shapes, blending colors, soft gradients), high detail, 4k, abstract background",
"negative_prompt": "text, human, face, animal, logo, sharp edges",
"steps": 30,
"cfg_scale": 7,
"width": 1024,
"height": 576, # 16:9 aspect for hero sections
"sampler_name": "DPM++ 2M Karras",
"seed": -1,
}
response = requests.post(url=f'http://localhost:7860/sdapi/v1/txt2img', json=payload)
```
I generate 50-100 images per batch, then use a second script to filter and upscale the top 10% using the `R-ESRGAN 4x+` upscaler. The whole process costs about $4-5 per batch in compute, which is fantastic compared to licensing fees.
A few practical lessons learned:
* **Model Matters:** I found `dreamshaper_8.safetensors` worked better for soft abstracts than the more photorealistic models.
* **Seed Logging:** I now log the seed and all parameters for every selected output in a simple DynamoDB table. This lets us recreate a style later if we need more variations.
* **Cost Watch:** I have a CloudWatch alarm that triggers an instance stop if the API run goes over 1 hour, just in case a script hangs.
The results have been great for section dividers and hero image backgrounds. Itβs a neat example of applying our infrastructure mindset to a creative task. Has anyone else built a similar automated pipeline for asset generation? I'm curious how you're handling version control for your prompts and model configurations.
-- Amy
Cloud cost nerd. No, I don't use Reserved Instances.
Spinning up a GPU instance for batch jobs is smart. But you're trusting a single EC2 instance with a seed of -1? That's chaos. 😄
At least bake the seed into the payload after the first good generation and commit it with the script. Makes it reproducible. I'd also dump the full generation params as a yaml sidecar file for each image batch. You're halfway to GitOps for art.
What's your rollback strategy when marketing says the gradient is "too 2023"?
Seeds are the least of their problems. If they're committing the seed but not the exact model checkpoint hash, reproducibility is still a guess. That g4dn.xlarge probably doesn't have ECC memory either, so good luck getting bit-for-bit matches over multiple batch runs.
YAML sidecars are fine, but without an immutable artifact store, they're just documentation for a process that's fundamentally non-deterministic on commodity cloud hardware. Where's the checksum validation for the output?
And rollback? If they're generating these on-demand, they've already lost. Version your static assets properly.
- Nina