import requests import json import base64 import os import time import re # For sanitizing filenames API_BASE_URL = "http://127.0.0.1:7860" TXT2IMG_URL = f"{API_BASE_URL}/sdapi/v1/txt2img" OUTPUT_DIR = "generated_images" FILE_EXTENSION = "png"# Changing this here does NOT change what type of file reforge gens, just the saved filename CHARACTERS = { "Remilia Scarlet": "1girl, remilia scarlet",# consider adding character traits here if they're inconsistent "Flandre Scarlet": "1girl, flandre scarlet", "Sakuya Izayoi": "1girl, izayoi sakuya", "Hong Meiling": "1girl, hong meiling", "Patchouli Knowledge": "1girl, patchouli knowledge", "Koakuma": "1girl, koakuma", } EXPRESSIONS = { "worried": "cowboy shot, hands up, index fingers together, worried, looking at viewer, parted lips, white background", "thinking": "cowboy shot, hand on own chin, thinking, looking to the side, ?, white background", "suspicious": "cowboy shot, crossed arms, looking at viewer, pursed lips, raised eyebrow, white background", "surprised": "cowboy shot, hands up, palms, surprised, !, looking at viewer, white background", "spacey": "cowboy shot, arms at sides, @_@, mouth drool, looking at viewer, parted lips, white background", "sniggering": "cowboy shot, covering own mouth, smug, :t, closed mouth, puff of air, laughing, looking at viewer, white background", "smug": "cowboy shot, smug, smirk, looking at viewer, leaning forward, hand on own chin, white background", "smiling": "cowboy shot, smile, closed eyes, facing viewer, own hands together, white background", "sleepy": "cowboy shot, hand over own mouth, arm at side, yawning, one eye closed, looking at viewer, white background", "shocked": "cowboy shot, hands up, palms, shaded face, wide-eyed, looking at viewer, !, surprised, white background", "serious": "cowboy shot, crossed arms, jitome, :|, looking at viewer, white background", "scared": "cowboy shot, hands on own legs, clenched hands, shaded face, scared, wavy mouth, @_@, averting eyes, sweatdrop, white background", "sad": "cowboy shot, own hands together, tearing up, pout, averting eyes, white background", "relieved": "cowboy shot, hand on own chest, arm at side, closed eyes, parted lips, puff of air, white background", "proud": "cowboy shot, hand on own chest, arm at side, closed eyes, smile, smug, head back, blush, white background", "pouting": "cowboy shot, hand on own hip, arm at side, from behind, facing to the side, looking at viewer, pout, blush, white background", "pleading": "cowboy shot, leaning forward, palms together, looking at viewer, looking up, tearing up, blush, white background", "playful winking": "cowboy shot, leaning forward, own hands clasped, one eye closed, smile, blush, embarrassed, looking at viewer, head tilt, white background", "overwhelmed": "cowboy shot, own hands clasped, @_@, full-face blush, open mouth, steam, looking at viewer, !, white background", "neutral": "cowboy shot, arms at sides, light smile, looking at viewer, white background", "nervous": "cowboy shot, arm at side, finger to mouth, open mouth, nervous, averting eyes, blush, flying sweatdrops, white background", "nervous pouting": "cowboy shot, arms at sides, clenched hands, looking at viewer, pout, blush, white background", "lustful": "cowboy shot, leaning to the side, arms behind back, head tilt, looking at viewer, smug, smile, blush, heart-shaped pupils", "lovestruck": "cowboy shot, hand on own chest, arm at side, heartbeat, heart-shaped pupils, open mouth, heavy breathing, looking at viewer, white background", "looking away shyly": "cowboy shot, own hands clasped, averting eyes, blush, facing viewer, white background", "joyful": "cowboy shot, hands clasped in delight, looking at viewer, wide-eyed, sparkling eyes, grin, white background", "jealous": "cowboy shot, arms at sides, jitome, :|, shaded face, looking at viewer, jealous, anger vein, white background", "indifferent": "cowboy shot, crossed arms, open mouth, upper teeth only, jitome, averting eyes, white background", "happy tears": "cowboy shot, finger to eye, arm at side, closed eyes, tears, facing viewer, smile, white background", "happy smiling": "cowboy shot, arms at sides, closed eyes, grin, facing viewer, white background", "guilty": "cowboy shot, finger to mouth, shaded face, averting eyes, embarrassed, jitome, sweatdrop, white background", "giggling": "cowboy shot, covering own mouth, arm at side, laughing, closed eyes, puff of air, facing viewer, white background", "full-face blush": "cowboy shot, leaning back, covering own mouth, full-face blush, @_@, looking at viewer, steam, white background", "forced smiling": "cowboy shot, arms at sides, closed eyes, facing viewer, awkward, false smile, sweatdrop, white background", "flustered": "cowboy shot, ><, arms at sides, clenched hands, embarrassed, blush stickers, facing viewer, white background", "fidgeting shyly": "cowboy shot, leaning forward, fidgeting, index fingers together, blush, looking at viewer, white background", "exhausted": "cowboy shot, arms at sides, bags under eyes, open mouth, giving up the ghost, looking up, facing viewer, white background", "excited": "cowboy shot, fist pump, sparkling eyes, looking at viewer, grin, white background", "evil smiling": "cowboy shot, hand on own arm, hand on own chin, shaded face, looking at viewer, evil smile, white background", "embarrassed": "cowboy shot, ><, arms at sides, clenched hands, embarrassed, blush stickers, facing viewer, white background", "disgusted": "cowboy shot, self hug, head back, shaded face, clenched teeth, disgust, looking at viewer, white background", "disappointed": "cowboy shot, arms at sides, jitome, shaded face, :|, sweatdrop, looking at viewer, disappointed, white background", "determined": "cowboy shot, arms at sides, narrowed eyes, looking at viewer, looking up, serious, white background", "depressed": "cowboy shot, arms at sides, looking down, jitome, open mouth, upper teeth only, depressed, sad, white background", "curious": "cowboy shot, leaning to the side, head tilt, finger to own chin, holding own arm, looking at viewer, curious, parted lips, white background", "crying with eyes open": "cowboy shot, arms at sides, clenched hands, crying with eyes open, streaming tears, open mouth, looking at viewer, white background", "crying with eyes closed": "cowboy shot, arms at sides, clenched hands, head back, ><, streaming tears, open mouth, looking at viewer, white background", "crazy smiling": "cowboy shot, arms behind back, leaning to the side, head tilt, @_@, crazy smile, looking at viewer, white background", "coughing": "cowboy shot, arm at side, covering own mouth, coughing, closed eyes, facing viewer, white background", "contemptuous": "cowboy shot, crossed arms, shaded face, jitome, open mouth, upper teeth only, looking at viewer, looking down, white background", "confused": "cowboy shot, crossed arms, looking at viewer, @_@, open mouth, upper teeth only, blush, confused, ?, white background", "comforted": "cowboy shot, arms behind head, closed eyes, blush stickers, smile, open mouth, puff of air, white background", "childlike whining": "cowboy shot, arms at sides, clenched hands, ><, open mouth, :o, tearing up, facing viewer, white background", "bored": "cowboy shot, hand on own chin, blinking, yawning, facing viewer, white background", "blushing shyly": "cowboy shot, leaning forward, arms behind back, blush, embarrassed, sweat, open mouth, looking at viewer, white background", "aroused": "cowboy shot, fidgeting, blush, heart-shaped pupils, looking at viewer, sweat, open mouth, embarrassed, steam, white background", "annoyed": "cowboy shot, facepalm, jitome, :|, looking at viewer, white background", "angry": "cowboy shot, arms at sides, clenched hands, angry, anger vein, open mouth, shouting, looking at viewer, white background", "admiring": "cowboy shot, palms together, looking at viewer, looking up, raised eyebrows, smile, open mouth, white background", } QUALITY_TAGS = "newest, masterpiece" ARTIST_TAGS = "hata4564, bollzzalguy" PAYLOAD = { "prompt": "", # "{ARTIST_TAGS}, {QUALITY_TAGS}\nBREAK\n solo, {CHARACTERS[character], {EXPRESSIONS[expression]}" "negative_prompt": "worst quality, low quality, old, watermark, signature", "seed": -1, "subseed": -1, "sampler_name": "Euler Ancestral CFG++", "scheduler": "SGM Uniform", "batch_size": 1,# do not change "n_iter": 1,# do not change "steps": 26, "cfg_scale": 1.8, "width": 896, "height": 1152, "restore_faces": False, "tiling": False, "do_not_save_samples": False, "do_not_save_grid": True, "eta": 0, "denoising_strength": 0.4, "s_min_uncond": 0, "s_churn": 0, "s_tmax": 0, "s_tmin": 0, "s_noise": 1, "override_settings": {}, "override_settings_restore_afterwards": True, "refiner_checkpoint": "", "refiner_switch_at": 0, "disable_extra_networks": False, "comments": {}, "enable_hr": True, "hr_scale": 2, "hr_upscaler": "R-ESRGAN 4x+ Anime6B", "hr_second_pass_steps": 12, "hr_cfg": 1.8, "send_images": True,# do not change "save_images": False, "alwayson_scripts": {}, } def sanitize_filename(name): """Removes or replaces characters invalid for filenames.""" name = re.sub(r'[\\/*?:"<>|]', '', name) return name def generate_and_save_image(character, expression, current_payload): print(f"Generating: {character} - {expression}") prompt = f"{ARTIST_TAGS}, {QUALITY_TAGS}\nBREAK\nsolo, {CHARACTERS[character]}, {EXPRESSIONS[expression]}" target_filename = f"{sanitize_filename(character)}.{sanitize_filename(expression)}.{FILE_EXTENSION}" output_path = os.path.join(OUTPUT_DIR, target_filename) print(f"Output: {output_path}") current_payload["prompt"] = prompt print(f"Payload: {json.dumps(current_payload)}") if os.path.exists(output_path): print(f"Skipping, file already exists: {output_path}") return try: response = requests.post(url=TXT2IMG_URL, json=current_payload) response.raise_for_status() r = response.json() if 'images' in r and len(r['images']) > 0: img_data = base64.b64decode(r['images'][0]) with open(output_path, 'wb') as f: f.write(img_data) print(f" Successfully saved: {output_path}") else: print("Error: No images found in the response.") print("Response:", r) except requests.exceptions.RequestException as e: print(f"Error during API request: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == "__main__": os.makedirs(OUTPUT_DIR, exist_ok=True) print(f"Output directory: {os.path.abspath(OUTPUT_DIR)}") start_time = time.time() for char in CHARACTERS.keys(): for expr in EXPRESSIONS.keys(): generate_and_save_image(char, expr, PAYLOAD.copy()) print("---") end_time = time.time() print(f"\nGeneration finished in {end_time - start_time:.2f} seconds.")