dragon-bot/app/stable_diffusion.py
Luke R 8f3b95f69f
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 2s
Build and push / Build-and-Push-Docker (push) Successful in 19s
Build and push / post-status-to-discord (push) Successful in 2s
Build and push / sync-argocd-app (push) Successful in 2s
Convert stable diffusion post to use fstrings
2025-04-18 09:44:50 -07:00

36 lines
1003 B
Python
Executable File

import base64
import httpx
import tempfile
async def generate_image(
ip, port, positives, negatives, steps, enable_upscale, model_name
):
url = f"http://{ip}:{port}/sdapi/v1/txt2img"
json_data = {
"prompt": positives,
"negative_prompt": negatives,
"sampler_name": "DPM++ 2M SDE Karras",
"steps": steps,
"enable_hr": enable_upscale,
"hr_upscaler": "Latent",
"hr_second_pass_steps": 20,
"denoising_strength": 0.5,
"hr_resize_x": 1024,
"hr_resize_y": 1024,
"alwayson_scripts": {"ADetailer": {"args": [{"ad_model": "face_yolov8n.pt"}]}},
"override_settings": {"sd_model_checkpoint": model_name},
}
client = httpx.AsyncClient()
response = await client.post(url, json=json_data, timeout=1200)
b64_image = response.json()["images"][0]
file, file_path = tempfile.mkstemp()
with open(file_path, "wb") as f:
f.write(base64.b64decode(b64_image))
return file_path