Spaces:
Runtime error
Runtime error
| #### pip install gradio_client | |
| import random | |
| import itertools | |
| import shutil | |
| from gradio_client import Client, handle_file | |
| from tqdm import tqdm | |
| import re | |
| import os | |
| prefix_quick_list = [ | |
| "detailed photo of", | |
| "amateur photo of", | |
| "flicker 2008 photo of", | |
| "fantastic artwork of", | |
| "vintage photograph of", | |
| "Unreal 5 render of", | |
| "surrealist painting of", | |
| "professional advertising design of" | |
| ] | |
| subject_quick_list = [ | |
| "a man", | |
| "a woman", | |
| "a handsome man", | |
| "a beautiful woman", | |
| "a monster", | |
| "a toy", | |
| "a product" | |
| ] | |
| subject_quick_list = [ | |
| "a handsome man" | |
| ] | |
| illumination_environment_quick_list = [ | |
| "sunshine from window", "neon light, city", "sunset over sea", "golden time", "sci-fi RGB glowing, cyberpunk", "natural lighting", | |
| "warm atmosphere, at home, bedroom", "magic lit", "evil, gothic, in a cave", "light and shadow", "shadow from window", "soft studio lighting", | |
| "home atmosphere, cozy bedroom illumination", "neon, Wong Kar-wai, warm", "moonlight through curtains", "stormy sky lighting", | |
| "underwater glow, deep sea", "foggy forest at dawn", "golden hour in a meadow", "rainbow reflections, neon", "cozy candlelight", | |
| "apocalyptic, smoky atmosphere", "red glow, emergency lights", "mystical glow, enchanted forest", "campfire light", "harsh, industrial lighting", | |
| "sunrise in the mountains", "evening glow in the desert", "moonlight in a dark alley", "golden glow at a fairground", | |
| "midnight in the forest", "purple and pink hues at twilight", "foggy morning, muted light", "candle-lit room, rustic vibe", | |
| "fluorescent office lighting", "lightning flash in storm", "night, cozy warm light from fireplace", "ethereal glow, magical forest", | |
| "dusky evening on a beach", "afternoon light filtering through trees", "blue neon light, urban street", "red and blue police lights in rain", | |
| "aurora borealis glow, arctic landscape", "sunrise through foggy mountains", "golden hour on a city skyline", "mysterious twilight, heavy mist", | |
| "early morning rays, forest clearing", "colorful lantern light at festival", "soft glow through stained glass", "harsh spotlight in dark room", | |
| "mellow evening glow on a lake", "crystal reflections in a cave", "vibrant autumn lighting in a forest", "gentle snowfall at dusk", | |
| "hazy light of a winter morning", "soft, diffused foggy glow", "underwater luminescence", "rain-soaked reflections in city lights", | |
| "golden sunlight streaming through trees", "fireflies lighting up a summer night", "glowing embers from a forge", "dim candlelight in a gothic castle", | |
| "midnight sky with bright starlight", "warm sunset in a rural village", "flickering light in a haunted house", "desert sunset with mirage-like glow", | |
| "golden beams piercing through storm clouds" | |
| ] | |
| background_quick_list = [ | |
| "cars and people", "a cozy bed and a lamp", "a forest clearing with mist", "a bustling marketplace", "a quiet beach at dusk", | |
| "an old, cobblestone street", "a futuristic cityscape", "a tranquil lake with mountains", "a mysterious cave entrance", | |
| "bookshelves and plants in the background", "an ancient temple in ruins", "tall skyscrapers and neon signs", "a starry sky over a desert", | |
| "a bustling cafΓ©", "rolling hills and farmland", "a modern living room with a fireplace", "an abandoned warehouse", | |
| "a picturesque mountain range", "a starry night sky", "the interior of a futuristic spaceship", "the cluttered workshop of an inventor", | |
| "the glowing embers of a bonfire", "a misty lake surrounded by trees", "an ornate palace hall", "a busy street market", "a vast desert landscape", | |
| "a peaceful library corner", "bustling train station", "a mystical, enchanted forest", "an underwater reef with colorful fish", "a quiet rural village", | |
| "a sandy beach with palm trees", "a vibrant coral reef, teeming with life", "snow-capped mountains in distance", "a stormy ocean, waves crashing", | |
| "a rustic barn in open fields", "a futuristic lab with glowing screens", "a dark, abandoned castle", "the ruins of an ancient civilization", | |
| "a bustling urban street in rain", "an elegant grand ballroom", "a sprawling field of wildflowers", "a dense jungle with sunlight filtering through", | |
| "a dimly lit, vintage bar", "an ice cave with sparkling crystals", "a serene riverbank at sunset", "a narrow alley with graffiti walls", | |
| "a peaceful zen garden with koi pond", "a high-tech control room", "a quiet mountain village at dawn", "a lighthouse on a rocky coast", | |
| "a rainy street with flickering lights", "a frozen lake with ice formations", "an abandoned theme park", "a small fishing village on a pier", | |
| "rolling sand dunes in a desert", "a dense forest with towering redwoods", "a snowy cabin in the mountains", "a mystical cave with bioluminescent plants", | |
| "a castle courtyard under moonlight", "a bustling open-air night market", "an old train station with steam", "a tranquil waterfall surrounded by trees", | |
| "a vineyard in the countryside", "a quaint medieval village", "a bustling harbor with boats", "a high-tech futuristic mall", | |
| "a lush tropical rainforest" | |
| ] | |
| def clean_filename(prompt): | |
| # Replace spaces with underscores | |
| filename = prompt.replace(' ', '_') | |
| # Remove or replace non-alphanumeric characters (except underscores) | |
| filename = re.sub(r'[^a-zA-Z0-9_]', '', filename) | |
| return filename + '.png' | |
| output_dir = 'iclight_v2_output_images' | |
| if not os.path.exists(output_dir): | |
| os.makedirs(output_dir) | |
| def generate_unique_random_string(used_prompts): | |
| while True: | |
| prefix = random.choice(prefix_quick_list) | |
| subject = random.choice(subject_quick_list) | |
| illumination = random.choice(illumination_environment_quick_list) | |
| background = random.choice(background_quick_list) | |
| prompt = f"{prefix} {subject}. {illumination}. {background} in the background." | |
| if prompt not in used_prompts: | |
| used_prompts.add(prompt) | |
| return prompt | |
| num_images = 10 | |
| used_prompts = set() | |
| for _ in tqdm(range(num_images), desc="Processing prompts"): | |
| p0 = generate_unique_random_string(used_prompts) | |
| client = Client("lllyasviel/iclight-v2") | |
| result = client.predict( | |
| input_fg=handle_file('xiangxiang_IMG.jpeg'), | |
| bg_source="None", | |
| prompt=p0, | |
| image_width=896, | |
| image_height=1152, | |
| num_samples=1, | |
| seed=12345, | |
| steps=25, | |
| n_prompt="", | |
| cfg=1, | |
| gs=5, | |
| rs=1, | |
| init_denoise=0.999, | |
| api_name="/process" | |
| ) | |
| # Copy im0.png and rename it based on the prompt | |
| original_path = result[0][0]["image"] | |
| cleaned_filename = clean_filename(p0) | |
| destination_path = os.path.join(output_dir, cleaned_filename) | |
| shutil.copy2(original_path, destination_path) |