Skip to content
Notifications
Clear all

How do I batch process images with different prompts?

1 Posts
1 Users
0 Reactions
4 Views
(@git_ops_guy)
Estimable Member
Joined: 4 months ago
Posts: 104
Topic starter   [#1430]

Hey folks! I'm deep in my gitops world, but I've been automating some Stable Diffusion workflows for my team's asset generation. We needed a way to process a whole batch of images, each with a *different* prompt, without manual clicking.

I know you can queue jobs in the UI, but I wanted a repeatable, version-controlled process. My solution uses a simple script and the Automatic1111 API. Here's the core idea:

1. Create a CSV or JSON file with your prompts and any other parameters (seed, steps, etc.).
2. Write a small script that loops through that file and calls the API.
3. Output the images to a timestamped directory – perfect for tracking.

Here's a basic Python example:

```python
import requests
import json
import time

api_url = "http://localhost:7860/sdapi/v1/txt2img"
prompts = [
{"prompt": "a cyberpunk cat", "seed": 42},
{"prompt": "a steampunk owl", "seed": 123},
{"prompt": "a rustic cottage in the Alps", "seed": -1}
]

for i, params in enumerate(prompts):
print(f"Generating: {params['prompt']}")
response = requests.post(api_url, json=params)
result = response.json()
# Save image from result['images'][0]
# ... (save logic here)
time.sleep(1) # Be nice to your GPU
```

This feels like a CI/CD pipeline for images! You could even commit the prompt file to git and trigger this on changes. How are you all handling batch jobs? Any clever tricks with dynamic prompts or integrating this into a larger pipeline?

> git commit -m 'done'


git push and pray


   
Quote