Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,6 @@ from diffusers.utils import load_image
|
|
12 |
from diffusers.utils import export_to_video
|
13 |
import random
|
14 |
from transformers import pipeline
|
15 |
-
|
16 |
# Translation model load
|
17 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
18 |
|
@@ -156,120 +155,206 @@ examples = [
|
|
156 |
["여자", "아기", "노인", 2.5]
|
157 |
]
|
158 |
|
|
|
|
|
159 |
css = """
|
160 |
footer {
|
161 |
visibility: hidden;
|
162 |
}
|
163 |
-
"""
|
164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
167 |
x_concept_1 = gr.State("")
|
168 |
x_concept_2 = gr.State("")
|
169 |
total_images = gr.Gallery(visible=False)
|
170 |
-
|
171 |
avg_diff_x = gr.State()
|
172 |
recalc_directions = gr.State(False)
|
173 |
-
|
174 |
-
with gr.Row():
|
175 |
-
|
176 |
-
with gr.Group():
|
177 |
-
prompt = gr.Textbox(label=english_labels["Prompt"],
|
178 |
-
info="Enter the description",
|
179 |
-
placeholder="A dog in the park")
|
180 |
-
with gr.Row():
|
181 |
-
concept_1 = gr.Textbox(label=english_labels["1st direction to steer"],
|
182 |
-
info="Initial state",
|
183 |
-
placeholder="winter")
|
184 |
-
concept_2 = gr.Textbox(label=english_labels["2nd direction to steer"],
|
185 |
-
info="Final state",
|
186 |
-
placeholder="summer")
|
187 |
-
x = gr.Slider(minimum=0,
|
188 |
-
value=1.75,
|
189 |
-
step=0.1,
|
190 |
-
maximum=4.0,
|
191 |
-
label=english_labels["Strength"],
|
192 |
-
info="Maximum strength for each direction (above 2.5 may be unstable)")
|
193 |
-
submit = gr.Button(english_labels["Generate directions"])
|
194 |
-
with gr.Column():
|
195 |
-
with gr.Group(elem_id="group"):
|
196 |
-
post_generation_image = gr.Image(label=english_labels["Generated Images"],
|
197 |
-
type="filepath",
|
198 |
-
elem_id="interactive")
|
199 |
-
post_generation_slider = gr.Slider(minimum=-10,
|
200 |
-
maximum=10,
|
201 |
-
value=0,
|
202 |
-
step=1,
|
203 |
-
label=english_labels["From 1st to 2nd direction"])
|
204 |
-
with gr.Row():
|
205 |
with gr.Column(scale=4):
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
examples=examples,
|
250 |
inputs=[prompt, concept_1, concept_2, x],
|
251 |
fn=generate,
|
252 |
-
outputs=[x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images,
|
253 |
post_generation_image, post_generation_slider, seed],
|
254 |
cache_examples="lazy"
|
255 |
)
|
256 |
|
|
|
257 |
submit.click(
|
258 |
fn=generate,
|
259 |
-
inputs=[prompt, concept_1, concept_2, x, randomize_seed, seed, recalc_directions,
|
260 |
-
iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2,
|
261 |
avg_diff_x, total_images],
|
262 |
-
outputs=[x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images,
|
263 |
post_generation_image, post_generation_slider, seed]
|
264 |
)
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
)
|
269 |
-
seed.change(
|
270 |
-
fn=reset_recalc_directions,
|
271 |
-
outputs=[recalc_directions]
|
272 |
-
)
|
273 |
post_generation_slider.change(
|
274 |
fn=update_pre_generated_images,
|
275 |
inputs=[post_generation_slider, total_images],
|
@@ -278,6 +363,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
278 |
show_progress="hidden",
|
279 |
concurrency_limit=None
|
280 |
)
|
281 |
-
|
282 |
if __name__ == "__main__":
|
283 |
demo.launch()
|
|
|
12 |
from diffusers.utils import export_to_video
|
13 |
import random
|
14 |
from transformers import pipeline
|
|
|
15 |
# Translation model load
|
16 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
17 |
|
|
|
155 |
["여자", "아기", "노인", 2.5]
|
156 |
]
|
157 |
|
158 |
+
|
159 |
+
|
160 |
css = """
|
161 |
footer {
|
162 |
visibility: hidden;
|
163 |
}
|
|
|
164 |
|
165 |
+
.container {
|
166 |
+
max-width: 1200px;
|
167 |
+
margin: auto;
|
168 |
+
}
|
169 |
+
|
170 |
+
.main-panel {
|
171 |
+
background-color: rgba(255, 255, 255, 0.05);
|
172 |
+
border-radius: 12px;
|
173 |
+
padding: 20px;
|
174 |
+
margin-bottom: 20px;
|
175 |
+
}
|
176 |
+
|
177 |
+
.controls-panel {
|
178 |
+
background-color: rgba(255, 255, 255, 0.02);
|
179 |
+
border-radius: 8px;
|
180 |
+
padding: 16px;
|
181 |
+
}
|
182 |
+
|
183 |
+
.image-display {
|
184 |
+
min-height: 400px;
|
185 |
+
display: flex;
|
186 |
+
flex-direction: column;
|
187 |
+
justify-content: center;
|
188 |
+
}
|
189 |
+
|
190 |
+
.slider-container {
|
191 |
+
padding: 10px 0;
|
192 |
+
}
|
193 |
+
|
194 |
+
.advanced-panel {
|
195 |
+
margin-top: 20px;
|
196 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
197 |
+
padding-top: 20px;
|
198 |
+
}
|
199 |
+
"""
|
200 |
|
201 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
202 |
x_concept_1 = gr.State("")
|
203 |
x_concept_2 = gr.State("")
|
204 |
total_images = gr.Gallery(visible=False)
|
|
|
205 |
avg_diff_x = gr.State()
|
206 |
recalc_directions = gr.State(False)
|
207 |
+
|
208 |
+
with gr.Row(elem_classes="container"):
|
209 |
+
# Left Column - Controls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
with gr.Column(scale=4):
|
211 |
+
with gr.Group(elem_classes="main-panel"):
|
212 |
+
gr.Markdown("### Image Generation Controls")
|
213 |
+
with gr.Group(elem_classes="controls-panel"):
|
214 |
+
prompt = gr.Textbox(
|
215 |
+
label=english_labels["Prompt"],
|
216 |
+
info="Enter the description",
|
217 |
+
placeholder="A dog in the park",
|
218 |
+
lines=2
|
219 |
+
)
|
220 |
+
with gr.Row():
|
221 |
+
with gr.Column(scale=1):
|
222 |
+
concept_1 = gr.Textbox(
|
223 |
+
label=english_labels["1st direction to steer"],
|
224 |
+
info="Initial state",
|
225 |
+
placeholder="winter"
|
226 |
+
)
|
227 |
+
with gr.Column(scale=1):
|
228 |
+
concept_2 = gr.Textbox(
|
229 |
+
label=english_labels["2nd direction to steer"],
|
230 |
+
info="Final state",
|
231 |
+
placeholder="summer"
|
232 |
+
)
|
233 |
+
|
234 |
+
with gr.Row(elem_classes="slider-container"):
|
235 |
+
x = gr.Slider(
|
236 |
+
minimum=0,
|
237 |
+
value=1.75,
|
238 |
+
step=0.1,
|
239 |
+
maximum=4.0,
|
240 |
+
label=english_labels["Strength"],
|
241 |
+
info="Maximum strength for each direction (above 2.5 may be unstable)"
|
242 |
+
)
|
243 |
+
|
244 |
+
submit = gr.Button(english_labels["Generate directions"], size="lg", variant="primary")
|
245 |
+
|
246 |
+
# Advanced Options Panel
|
247 |
+
with gr.Accordion(label=english_labels["Advanced options"], open=False, elem_classes="advanced-panel"):
|
248 |
+
with gr.Row():
|
249 |
+
with gr.Column(scale=1):
|
250 |
+
interm_steps = gr.Slider(
|
251 |
+
label=english_labels["Num of intermediate images"],
|
252 |
+
minimum=3,
|
253 |
+
value=7,
|
254 |
+
maximum=65,
|
255 |
+
step=2
|
256 |
+
)
|
257 |
+
with gr.Column(scale=1):
|
258 |
+
guidance_scale = gr.Slider(
|
259 |
+
label=english_labels["Guidance scale"],
|
260 |
+
minimum=0.1,
|
261 |
+
maximum=10.0,
|
262 |
+
step=0.1,
|
263 |
+
value=3.5
|
264 |
+
)
|
265 |
+
|
266 |
+
with gr.Row():
|
267 |
+
with gr.Column(scale=1):
|
268 |
+
iterations = gr.Slider(
|
269 |
+
label=english_labels["Num iterations for clip directions"],
|
270 |
+
minimum=0,
|
271 |
+
value=200,
|
272 |
+
maximum=400,
|
273 |
+
step=1
|
274 |
+
)
|
275 |
+
with gr.Column(scale=1):
|
276 |
+
steps = gr.Slider(
|
277 |
+
label=english_labels["Num inference steps"],
|
278 |
+
minimum=1,
|
279 |
+
value=3,
|
280 |
+
maximum=4,
|
281 |
+
step=1
|
282 |
+
)
|
283 |
+
|
284 |
+
with gr.Row():
|
285 |
+
with gr.Column(scale=1):
|
286 |
+
randomize_seed = gr.Checkbox(
|
287 |
+
True,
|
288 |
+
label=english_labels["Randomize seed"]
|
289 |
+
)
|
290 |
+
with gr.Column(scale=1):
|
291 |
+
seed = gr.Slider(
|
292 |
+
minimum=0,
|
293 |
+
maximum=MAX_SEED,
|
294 |
+
step=1,
|
295 |
+
label=english_labels["Seed"],
|
296 |
+
interactive=True,
|
297 |
+
randomize=True
|
298 |
+
)
|
299 |
+
|
300 |
+
# Right Column - Output
|
301 |
+
with gr.Column(scale=6):
|
302 |
+
with gr.Group(elem_classes="main-panel"):
|
303 |
+
gr.Markdown("### Generated Results")
|
304 |
+
with gr.Row():
|
305 |
+
with gr.Column():
|
306 |
+
post_generation_image = gr.Image(
|
307 |
+
label=english_labels["Generated Images"],
|
308 |
+
type="filepath",
|
309 |
+
elem_id="interactive",
|
310 |
+
elem_classes="image-display"
|
311 |
+
)
|
312 |
+
post_generation_slider = gr.Slider(
|
313 |
+
minimum=-10,
|
314 |
+
maximum=10,
|
315 |
+
value=0,
|
316 |
+
step=1,
|
317 |
+
label=english_labels["From 1st to 2nd direction"]
|
318 |
+
)
|
319 |
+
|
320 |
+
with gr.Row():
|
321 |
+
with gr.Column(scale=3):
|
322 |
+
image_seq = gr.Image(
|
323 |
+
label=english_labels["Strip"],
|
324 |
+
elem_id="strip",
|
325 |
+
height=100
|
326 |
+
)
|
327 |
+
with gr.Column(scale=2):
|
328 |
+
output_image = gr.Video(
|
329 |
+
label=english_labels["Looping video"],
|
330 |
+
elem_id="video",
|
331 |
+
loop=True,
|
332 |
+
autoplay=True,
|
333 |
+
height=100
|
334 |
+
)
|
335 |
+
|
336 |
+
# Examples Section
|
337 |
+
gr.Examples(
|
338 |
examples=examples,
|
339 |
inputs=[prompt, concept_1, concept_2, x],
|
340 |
fn=generate,
|
341 |
+
outputs=[x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images,
|
342 |
post_generation_image, post_generation_slider, seed],
|
343 |
cache_examples="lazy"
|
344 |
)
|
345 |
|
346 |
+
# Event Handlers
|
347 |
submit.click(
|
348 |
fn=generate,
|
349 |
+
inputs=[prompt, concept_1, concept_2, x, randomize_seed, seed, recalc_directions,
|
350 |
+
iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2,
|
351 |
avg_diff_x, total_images],
|
352 |
+
outputs=[x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images,
|
353 |
post_generation_image, post_generation_slider, seed]
|
354 |
)
|
355 |
+
|
356 |
+
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
357 |
+
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
|
|
|
|
|
|
|
|
|
|
358 |
post_generation_slider.change(
|
359 |
fn=update_pre_generated_images,
|
360 |
inputs=[post_generation_slider, total_images],
|
|
|
363 |
show_progress="hidden",
|
364 |
concurrency_limit=None
|
365 |
)
|
366 |
+
|
367 |
if __name__ == "__main__":
|
368 |
demo.launch()
|