Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,6 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
21 |
ILLUMINATION_OPTIONS = {
|
22 |
"sunset over sea": "add warm sunset light reflecting off water, creating a peaceful atmosphere with soft, diffused lighting and gentle color gradients",
|
23 |
"sunshine from window": "Add directional sunlight from window source. Increase brightness on lit areas. Create hard shadows with sharp edges. Set warm white color temperature. Add visible light rays and dust particles in beams.",
|
24 |
-
"sunset over sea": "Set warm orange-red color temperature. Increase warm tones substantially. Add horizontal light source from background. Create soft gradient lighting. Add water reflections if visible.",
|
25 |
"golden time": "Set golden color temperature. Increase contrast moderately. Add rim lighting on subjects. Enhance warm colors. Create soft directional shadows. Reduce blue tones.",
|
26 |
"sci-fi RGB glowing, cyberpunk": "add futuristic RGB lighting with electric blues, hot pinks, and neon greens creating a high-tech atmosphere with dramatic color separation and glowing effects",
|
27 |
"neon night, city":"add vibrant neon lights in electric blues, magentas, and greens casting colorful reflections on surfaces, creating a cyberpunk urban atmosphere with dramatic color contrasts",
|
@@ -78,7 +77,6 @@ ILLUMINATION_OPTIONS = {
|
|
78 |
"soft, diffused foggy glow": "Add volumetric fog throughout scene. Reduce contrast substantially. Create soft lighting with no harsh shadows. Set neutral color temperature.",
|
79 |
"underwater luminescence": "Set blue-green color temperature. Add bioluminescent glowing effects. Create caustic light patterns. Add particle effects in water.",
|
80 |
"rain-soaked reflections in city lights": "Add reflections on wet surfaces. Create light streaking effects. Set urban lighting with multiple colored sources. Add rain particle effects.",
|
81 |
-
"golden time": "add warm golden hour lighting with soft, diffused sunlight creating a magical glow, enhanced contrast, and rich warm tones throughout the scene",
|
82 |
"golden sunlight streaming through trees": "Add god rays effect. Set golden color temperature. Create dappled light patterns. Add atmospheric particles in light beams.",
|
83 |
"fireflies lighting up a summer night": "Add small glowing points of light. Set warm color temperature. Create subtle animated glow effects. Maintain dark ambient lighting.",
|
84 |
"glowing embers from a forge": "Add orange-red glowing particle effects. Set very warm color temperature. Create intense heat glow. Add sparking effects.",
|
@@ -90,15 +88,34 @@ ILLUMINATION_OPTIONS = {
|
|
90 |
"golden beams piercing through storm clouds": "Add dramatic god rays through clouds. Set golden color temperature. Create high contrast between light and shadow areas."
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
@spaces.GPU
|
94 |
-
def infer(input_image, prompt, illumination_dropdown, seed=42, randomize_seed=False, guidance_scale=2.5, progress=gr.Progress(track_tqdm=True)):
|
95 |
|
96 |
if randomize_seed:
|
97 |
seed = random.randint(0, MAX_SEED)
|
98 |
|
99 |
input_image = input_image.convert("RGB")
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
image = pipe(
|
104 |
image=input_image,
|
@@ -112,7 +129,7 @@ def infer(input_image, prompt, illumination_dropdown, seed=42, randomize_seed=Fa
|
|
112 |
|
113 |
def update_prompt_from_dropdown(illumination_option):
|
114 |
"""Update the prompt textbox based on dropdown selection"""
|
115 |
-
if illumination_option == "
|
116 |
return "" # Clear the prompt for custom input
|
117 |
else:
|
118 |
return ILLUMINATION_OPTIONS[illumination_option]
|
@@ -135,23 +152,32 @@ with gr.Blocks(css=css) as demo:
|
|
135 |
with gr.Row():
|
136 |
with gr.Column():
|
137 |
input_image = gr.Image(label="Upload the image for relighting", type="pil")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
prompt = gr.Textbox(
|
139 |
-
label="
|
140 |
show_label=True,
|
141 |
max_lines=3,
|
142 |
placeholder="Select an illumination style above or enter your custom description...",
|
143 |
-
value="
|
144 |
container=True
|
145 |
)
|
146 |
-
|
147 |
-
illumination_dropdown = gr.Dropdown(
|
148 |
-
choices=list(ILLUMINATION_OPTIONS.keys()) + ["Custom"],
|
149 |
-
value="sunshine from window",
|
150 |
-
label="Choose Illumination Style",
|
151 |
-
info="Select a predefined lighting style or choose 'Custom' to use your own prompt"
|
152 |
-
)
|
153 |
-
|
154 |
-
|
155 |
|
156 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
157 |
|
@@ -187,14 +213,14 @@ with gr.Blocks(css=css) as demo:
|
|
187 |
|
188 |
gr.Examples(
|
189 |
examples=[
|
190 |
-
["./assets/pexels-creationhill-1681010.jpg", "Add multiple colored light sources from lanterns. Create warm festival lighting. Set varied color temperatures. Add bokeh effects.", "colorful lantern light at festival", 0, True, 2.5],
|
191 |
-
["./assets/pexels-creationhill-1681010.jpg", "add futuristic RGB lighting with electric blues, hot pinks, and neon greens creating a high-tech atmosphere with dramatic color separation and glowing effects", "sci-fi RGB glowing, cyberpunk",0, True, 2.5],
|
192 |
-
["./assets/pexels-moose-photos-170195-1587009.jpg", "Set blue-green color temperature. Add volumetric lighting effects. Reduce red channel significantly. Create particle effects in light beams. Add caustic light patterns.", "underwater glow, deep sea",0, True, 2.5],
|
193 |
-
["./assets/pexels-moose-photos-170195-1587009.jpg", "Replace lighting with red sources. Add flashing strobing effects. Increase contrast. Create harsh shadows. Set monochromatic red color scheme.", "red glow, emergency lights", 0, True, 2.5],
|
194 |
-
["./assets/pexels-simon-robben-55958-614810.jpg", "Add directional sunlight from window source. Increase brightness on lit areas. Create hard shadows with sharp edges. Set warm white color temperature. Add visible light rays and dust particles in beams.", "sunshine from window",0, True, 2.5],
|
195 |
-
["./assets/pexels-simon-robben-55958-614810.jpg", "add vibrant neon lights in electric blues, magentas, and greens casting colorful reflections on surfaces, creating a cyberpunk urban atmosphere with dramatic color contrasts", "neon night, city", 0, True, 2.5]
|
196 |
],
|
197 |
-
inputs=[input_image, prompt, illumination_dropdown, seed, randomize_seed, guidance_scale],
|
198 |
outputs=[result, seed],
|
199 |
fn=infer,
|
200 |
cache_examples="lazy"
|
@@ -203,7 +229,7 @@ with gr.Blocks(css=css) as demo:
|
|
203 |
gr.on(
|
204 |
triggers=[run_button.click, prompt.submit],
|
205 |
fn = infer,
|
206 |
-
inputs = [input_image, prompt, illumination_dropdown, seed, randomize_seed, guidance_scale],
|
207 |
outputs = [result, seed]
|
208 |
)
|
209 |
|
|
|
21 |
ILLUMINATION_OPTIONS = {
|
22 |
"sunset over sea": "add warm sunset light reflecting off water, creating a peaceful atmosphere with soft, diffused lighting and gentle color gradients",
|
23 |
"sunshine from window": "Add directional sunlight from window source. Increase brightness on lit areas. Create hard shadows with sharp edges. Set warm white color temperature. Add visible light rays and dust particles in beams.",
|
|
|
24 |
"golden time": "Set golden color temperature. Increase contrast moderately. Add rim lighting on subjects. Enhance warm colors. Create soft directional shadows. Reduce blue tones.",
|
25 |
"sci-fi RGB glowing, cyberpunk": "add futuristic RGB lighting with electric blues, hot pinks, and neon greens creating a high-tech atmosphere with dramatic color separation and glowing effects",
|
26 |
"neon night, city":"add vibrant neon lights in electric blues, magentas, and greens casting colorful reflections on surfaces, creating a cyberpunk urban atmosphere with dramatic color contrasts",
|
|
|
77 |
"soft, diffused foggy glow": "Add volumetric fog throughout scene. Reduce contrast substantially. Create soft lighting with no harsh shadows. Set neutral color temperature.",
|
78 |
"underwater luminescence": "Set blue-green color temperature. Add bioluminescent glowing effects. Create caustic light patterns. Add particle effects in water.",
|
79 |
"rain-soaked reflections in city lights": "Add reflections on wet surfaces. Create light streaking effects. Set urban lighting with multiple colored sources. Add rain particle effects.",
|
|
|
80 |
"golden sunlight streaming through trees": "Add god rays effect. Set golden color temperature. Create dappled light patterns. Add atmospheric particles in light beams.",
|
81 |
"fireflies lighting up a summer night": "Add small glowing points of light. Set warm color temperature. Create subtle animated glow effects. Maintain dark ambient lighting.",
|
82 |
"glowing embers from a forge": "Add orange-red glowing particle effects. Set very warm color temperature. Create intense heat glow. Add sparking effects.",
|
|
|
88 |
"golden beams piercing through storm clouds": "Add dramatic god rays through clouds. Set golden color temperature. Create high contrast between light and shadow areas."
|
89 |
}
|
90 |
|
91 |
+
# Lighting direction options
|
92 |
+
DIRECTION_OPTIONS = {
|
93 |
+
"none": "",
|
94 |
+
"left side": "Position the light source from the left side of the frame, creating shadows falling to the right.",
|
95 |
+
"right side": "Position the light source from the right side of the frame, creating shadows falling to the left.",
|
96 |
+
"top": "Position the light source from directly above, creating downward shadows.",
|
97 |
+
"top left": "Position the light source from the top left corner, creating diagonal shadows falling down and to the right.",
|
98 |
+
"top right": "Position the light source from the top right corner, creating diagonal shadows falling down and to the left.",
|
99 |
+
"bottom": "Position the light source from below, creating upward shadows and dramatic under-lighting.",
|
100 |
+
"front": "Position the light source from the front, minimizing shadows and creating even illumination.",
|
101 |
+
"back": "Position the light source from behind the subject, creating silhouette effects and rim lighting."
|
102 |
+
}
|
103 |
+
|
104 |
@spaces.GPU
|
105 |
+
def infer(input_image, prompt, illumination_dropdown, direction_dropdown, seed=42, randomize_seed=False, guidance_scale=2.5, progress=gr.Progress(track_tqdm=True)):
|
106 |
|
107 |
if randomize_seed:
|
108 |
seed = random.randint(0, MAX_SEED)
|
109 |
|
110 |
input_image = input_image.convert("RGB")
|
111 |
|
112 |
+
# Combine illumination and direction if direction is not "Auto"
|
113 |
+
if direction_dropdown != "none":
|
114 |
+
prompt_prefix = f"with {illumination_dropdown} coming from the {direction_dropdown}"
|
115 |
+
else:
|
116 |
+
prompt_prefix = f"with {illumination_dropdown} coming from the {direction_dropdown}"
|
117 |
+
|
118 |
+
prompt_with_template = f"Relight the image, {prompt_prefix}. {prompt} Maintain the identity of the foreground subjects."
|
119 |
|
120 |
image = pipe(
|
121 |
image=input_image,
|
|
|
129 |
|
130 |
def update_prompt_from_dropdown(illumination_option):
|
131 |
"""Update the prompt textbox based on dropdown selection"""
|
132 |
+
if illumination_option == "custom":
|
133 |
return "" # Clear the prompt for custom input
|
134 |
else:
|
135 |
return ILLUMINATION_OPTIONS[illumination_option]
|
|
|
152 |
with gr.Row():
|
153 |
with gr.Column():
|
154 |
input_image = gr.Image(label="Upload the image for relighting", type="pil")
|
155 |
+
|
156 |
+
with gr.Row():
|
157 |
+
illumination_dropdown = gr.Dropdown(
|
158 |
+
choices=list(ILLUMINATION_OPTIONS.keys()) + ["custom"],
|
159 |
+
value="sunshine from window",
|
160 |
+
label="Choose Illumination Style",
|
161 |
+
info="Select a predefined lighting style or choose 'Custom' to use your own prompt",
|
162 |
+
scale=2
|
163 |
+
)
|
164 |
+
|
165 |
+
direction_dropdown = gr.Dropdown(
|
166 |
+
choices=list(DIRECTION_OPTIONS.keys()),
|
167 |
+
value="auto",
|
168 |
+
label="Light Direction",
|
169 |
+
info="Choose the direction of the light source",
|
170 |
+
scale=1
|
171 |
+
)
|
172 |
+
|
173 |
prompt = gr.Textbox(
|
174 |
+
label="Lighting Description",
|
175 |
show_label=True,
|
176 |
max_lines=3,
|
177 |
placeholder="Select an illumination style above or enter your custom description...",
|
178 |
+
value="Add directional sunlight from window source. Increase brightness on lit areas. Create hard shadows with sharp edges. Set warm white color temperature. Add visible light rays and dust particles in beams.",
|
179 |
container=True
|
180 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
183 |
|
|
|
213 |
|
214 |
gr.Examples(
|
215 |
examples=[
|
216 |
+
["./assets/pexels-creationhill-1681010.jpg", "Add multiple colored light sources from lanterns. Create warm festival lighting. Set varied color temperatures. Add bokeh effects.", "colorful lantern light at festival", "auto", 0, True, 2.5],
|
217 |
+
["./assets/pexels-creationhill-1681010.jpg", "add futuristic RGB lighting with electric blues, hot pinks, and neon greens creating a high-tech atmosphere with dramatic color separation and glowing effects", "sci-fi RGB glowing, cyberpunk", "left side", 0, True, 2.5],
|
218 |
+
["./assets/pexels-moose-photos-170195-1587009.jpg", "Set blue-green color temperature. Add volumetric lighting effects. Reduce red channel significantly. Create particle effects in light beams. Add caustic light patterns.", "underwater glow, deep sea", "top", 0, True, 2.5],
|
219 |
+
["./assets/pexels-moose-photos-170195-1587009.jpg", "Replace lighting with red sources. Add flashing strobing effects. Increase contrast. Create harsh shadows. Set monochromatic red color scheme.", "red glow, emergency lights", "right side", 0, True, 2.5],
|
220 |
+
["./assets/pexels-simon-robben-55958-614810.jpg", "Add directional sunlight from window source. Increase brightness on lit areas. Create hard shadows with sharp edges. Set warm white color temperature. Add visible light rays and dust particles in beams.", "sunshine from window", "top right", 0, True, 2.5],
|
221 |
+
["./assets/pexels-simon-robben-55958-614810.jpg", "add vibrant neon lights in electric blues, magentas, and greens casting colorful reflections on surfaces, creating a cyberpunk urban atmosphere with dramatic color contrasts", "neon night, city", "top left", 0, True, 2.5]
|
222 |
],
|
223 |
+
inputs=[input_image, prompt, illumination_dropdown, direction_dropdown, seed, randomize_seed, guidance_scale],
|
224 |
outputs=[result, seed],
|
225 |
fn=infer,
|
226 |
cache_examples="lazy"
|
|
|
229 |
gr.on(
|
230 |
triggers=[run_button.click, prompt.submit],
|
231 |
fn = infer,
|
232 |
+
inputs = [input_image, prompt, illumination_dropdown, direction_dropdown, seed, randomize_seed, guidance_scale],
|
233 |
outputs = [result, seed]
|
234 |
)
|
235 |
|