svjack commited on
Commit
f8006fb
Β·
verified Β·
1 Parent(s): 3f10d5c

Upload run_iclight_v2.py

Browse files
Files changed (1) hide show
  1. run_iclight_v2.py +125 -0
run_iclight_v2.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### pip install gradio_client
2
+ import random
3
+ import itertools
4
+ import shutil
5
+ from gradio_client import Client, handle_file
6
+ from tqdm import tqdm
7
+ import re
8
+ import os
9
+
10
+ prefix_quick_list = [
11
+ "detailed photo of",
12
+ "amateur photo of",
13
+ "flicker 2008 photo of",
14
+ "fantastic artwork of",
15
+ "vintage photograph of",
16
+ "Unreal 5 render of",
17
+ "surrealist painting of",
18
+ "professional advertising design of"
19
+ ]
20
+
21
+ subject_quick_list = [
22
+ "a man",
23
+ "a woman",
24
+ "a handsome man",
25
+ "a beautiful woman",
26
+ "a monster",
27
+ "a toy",
28
+ "a product"
29
+ ]
30
+
31
+ subject_quick_list = [
32
+ "a handsome man"
33
+ ]
34
+
35
+ illumination_environment_quick_list = [
36
+ "sunshine from window", "neon light, city", "sunset over sea", "golden time", "sci-fi RGB glowing, cyberpunk", "natural lighting",
37
+ "warm atmosphere, at home, bedroom", "magic lit", "evil, gothic, in a cave", "light and shadow", "shadow from window", "soft studio lighting",
38
+ "home atmosphere, cozy bedroom illumination", "neon, Wong Kar-wai, warm", "moonlight through curtains", "stormy sky lighting",
39
+ "underwater glow, deep sea", "foggy forest at dawn", "golden hour in a meadow", "rainbow reflections, neon", "cozy candlelight",
40
+ "apocalyptic, smoky atmosphere", "red glow, emergency lights", "mystical glow, enchanted forest", "campfire light", "harsh, industrial lighting",
41
+ "sunrise in the mountains", "evening glow in the desert", "moonlight in a dark alley", "golden glow at a fairground",
42
+ "midnight in the forest", "purple and pink hues at twilight", "foggy morning, muted light", "candle-lit room, rustic vibe",
43
+ "fluorescent office lighting", "lightning flash in storm", "night, cozy warm light from fireplace", "ethereal glow, magical forest",
44
+ "dusky evening on a beach", "afternoon light filtering through trees", "blue neon light, urban street", "red and blue police lights in rain",
45
+ "aurora borealis glow, arctic landscape", "sunrise through foggy mountains", "golden hour on a city skyline", "mysterious twilight, heavy mist",
46
+ "early morning rays, forest clearing", "colorful lantern light at festival", "soft glow through stained glass", "harsh spotlight in dark room",
47
+ "mellow evening glow on a lake", "crystal reflections in a cave", "vibrant autumn lighting in a forest", "gentle snowfall at dusk",
48
+ "hazy light of a winter morning", "soft, diffused foggy glow", "underwater luminescence", "rain-soaked reflections in city lights",
49
+ "golden sunlight streaming through trees", "fireflies lighting up a summer night", "glowing embers from a forge", "dim candlelight in a gothic castle",
50
+ "midnight sky with bright starlight", "warm sunset in a rural village", "flickering light in a haunted house", "desert sunset with mirage-like glow",
51
+ "golden beams piercing through storm clouds"
52
+ ]
53
+
54
+ background_quick_list = [
55
+ "cars and people", "a cozy bed and a lamp", "a forest clearing with mist", "a bustling marketplace", "a quiet beach at dusk",
56
+ "an old, cobblestone street", "a futuristic cityscape", "a tranquil lake with mountains", "a mysterious cave entrance",
57
+ "bookshelves and plants in the background", "an ancient temple in ruins", "tall skyscrapers and neon signs", "a starry sky over a desert",
58
+ "a bustling cafΓ©", "rolling hills and farmland", "a modern living room with a fireplace", "an abandoned warehouse",
59
+ "a picturesque mountain range", "a starry night sky", "the interior of a futuristic spaceship", "the cluttered workshop of an inventor",
60
+ "the glowing embers of a bonfire", "a misty lake surrounded by trees", "an ornate palace hall", "a busy street market", "a vast desert landscape",
61
+ "a peaceful library corner", "bustling train station", "a mystical, enchanted forest", "an underwater reef with colorful fish", "a quiet rural village",
62
+ "a sandy beach with palm trees", "a vibrant coral reef, teeming with life", "snow-capped mountains in distance", "a stormy ocean, waves crashing",
63
+ "a rustic barn in open fields", "a futuristic lab with glowing screens", "a dark, abandoned castle", "the ruins of an ancient civilization",
64
+ "a bustling urban street in rain", "an elegant grand ballroom", "a sprawling field of wildflowers", "a dense jungle with sunlight filtering through",
65
+ "a dimly lit, vintage bar", "an ice cave with sparkling crystals", "a serene riverbank at sunset", "a narrow alley with graffiti walls",
66
+ "a peaceful zen garden with koi pond", "a high-tech control room", "a quiet mountain village at dawn", "a lighthouse on a rocky coast",
67
+ "a rainy street with flickering lights", "a frozen lake with ice formations", "an abandoned theme park", "a small fishing village on a pier",
68
+ "rolling sand dunes in a desert", "a dense forest with towering redwoods", "a snowy cabin in the mountains", "a mystical cave with bioluminescent plants",
69
+ "a castle courtyard under moonlight", "a bustling open-air night market", "an old train station with steam", "a tranquil waterfall surrounded by trees",
70
+ "a vineyard in the countryside", "a quaint medieval village", "a bustling harbor with boats", "a high-tech futuristic mall",
71
+ "a lush tropical rainforest"
72
+ ]
73
+
74
+ def clean_filename(prompt):
75
+ # Replace spaces with underscores
76
+ filename = prompt.replace(' ', '_')
77
+ # Remove or replace non-alphanumeric characters (except underscores)
78
+ filename = re.sub(r'[^a-zA-Z0-9_]', '', filename)
79
+ return filename + '.png'
80
+
81
+ output_dir = 'iclight_v2_output_images'
82
+ if not os.path.exists(output_dir):
83
+ os.makedirs(output_dir)
84
+
85
+ def generate_unique_random_string(used_prompts):
86
+ while True:
87
+ prefix = random.choice(prefix_quick_list)
88
+ subject = random.choice(subject_quick_list)
89
+ illumination = random.choice(illumination_environment_quick_list)
90
+ background = random.choice(background_quick_list)
91
+
92
+ prompt = f"{prefix} {subject}. {illumination}. {background} in the background."
93
+ if prompt not in used_prompts:
94
+ used_prompts.add(prompt)
95
+ return prompt
96
+
97
+ num_images = 10
98
+ used_prompts = set()
99
+
100
+ for _ in tqdm(range(num_images), desc="Processing prompts"):
101
+ p0 = generate_unique_random_string(used_prompts)
102
+
103
+ client = Client("lllyasviel/iclight-v2")
104
+ result = client.predict(
105
+ input_fg=handle_file('xiangxiang_IMG.jpeg'),
106
+ bg_source="None",
107
+ prompt=p0,
108
+ image_width=896,
109
+ image_height=1152,
110
+ num_samples=1,
111
+ seed=12345,
112
+ steps=25,
113
+ n_prompt="",
114
+ cfg=1,
115
+ gs=5,
116
+ rs=1,
117
+ init_denoise=0.999,
118
+ api_name="/process"
119
+ )
120
+
121
+ # Copy im0.png and rename it based on the prompt
122
+ original_path = result[0][0]["image"]
123
+ cleaned_filename = clean_filename(p0)
124
+ destination_path = os.path.join(output_dir, cleaned_filename)
125
+ shutil.copy2(original_path, destination_path)