Spaces:
Paused
Paused
Update app_gradio.py
Browse files- app_gradio.py +72 -169
app_gradio.py
CHANGED
@@ -200,9 +200,7 @@ def generate_output(image, prompt: str, num_seeds: int = 3, lambda_value: float
|
|
200 |
|
201 |
return filtered_gifs
|
202 |
|
203 |
-
|
204 |
-
def create_gradio_interface():
|
205 |
-
with gr.Blocks(css="""
|
206 |
.container {
|
207 |
max-width: 1200px;
|
208 |
margin: 0 auto;
|
@@ -260,8 +258,12 @@ def create_gradio_interface():
|
|
260 |
opacity: 0.7;
|
261 |
cursor: not-allowed;
|
262 |
}
|
263 |
-
"""
|
264 |
-
|
|
|
|
|
|
|
|
|
265 |
"""
|
266 |
|
267 |
<div align="center" id = "user-content-toc">
|
@@ -272,75 +274,69 @@ def create_gradio_interface():
|
|
272 |
</div>
|
273 |
|
274 |
"""
|
275 |
-
|
276 |
|
277 |
-
with gr.
|
278 |
-
|
279 |
-
|
280 |
-
gr.
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
)
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
label="Prompt",
|
315 |
-
placeholder="Describe the motion...",
|
316 |
-
lines=3
|
317 |
-
)
|
318 |
-
with gr.Row():
|
319 |
-
example_num_seeds = gr.Slider(
|
320 |
-
minimum=1,
|
321 |
-
maximum=10,
|
322 |
-
value=5,
|
323 |
-
step=1,
|
324 |
-
label="Seeds"
|
325 |
-
)
|
326 |
-
example_lambda = gr.Slider(
|
327 |
-
minimum=0,
|
328 |
-
maximum=1,
|
329 |
-
value=0.5,
|
330 |
-
step=0.1,
|
331 |
-
label="Motion Strength"
|
332 |
-
)
|
333 |
-
example_generate_btn = gr.Button(
|
334 |
-
"Generate Animation",
|
335 |
-
variant="primary",
|
336 |
-
elem_classes="generate-btn",
|
337 |
-
interactive=True,
|
338 |
-
)
|
339 |
|
340 |
-
|
341 |
|
342 |
-
gr.
|
343 |
-
example_gallery = gr.Gallery(
|
344 |
label="Results",
|
345 |
elem_classes="output-gallery",
|
346 |
columns=3,
|
@@ -352,111 +348,18 @@ def create_gradio_interface():
|
|
352 |
preview=False
|
353 |
)
|
354 |
|
355 |
-
|
356 |
-
with gr.Tab("Upload Your Sketch"):
|
357 |
-
with gr.Group(elem_classes="selected-example"):
|
358 |
-
with gr.Row():
|
359 |
-
upload_image = gr.Image(
|
360 |
-
type="pil",
|
361 |
-
label="Upload Your Sketch",
|
362 |
-
scale=1,
|
363 |
-
height=300, # Fixed height for consistency
|
364 |
-
show_download_button=False,
|
365 |
-
sources=["upload"],
|
366 |
-
)
|
367 |
-
with gr.Column(scale=2):
|
368 |
-
upload_prompt = gr.Textbox(
|
369 |
-
label="Prompt",
|
370 |
-
placeholder="Describe what you want to generate...",
|
371 |
-
lines=3
|
372 |
-
)
|
373 |
-
with gr.Row():
|
374 |
-
upload_num_seeds = gr.Slider(
|
375 |
-
minimum=1,
|
376 |
-
maximum=10,
|
377 |
-
value=5,
|
378 |
-
step=1,
|
379 |
-
label="Number of Variations"
|
380 |
-
)
|
381 |
-
upload_lambda = gr.Slider(
|
382 |
-
minimum=0,
|
383 |
-
maximum=1,
|
384 |
-
value=0.5,
|
385 |
-
step=0.1,
|
386 |
-
label="Motion Strength"
|
387 |
-
)
|
388 |
-
upload_generate_btn = gr.Button(
|
389 |
-
"Generate Animation",
|
390 |
-
variant="primary",
|
391 |
-
elem_classes="generate-btn",
|
392 |
-
size="lg",
|
393 |
-
interactive=True,
|
394 |
-
)
|
395 |
-
|
396 |
-
gr.Markdown("## Result 👉 Generated Animations ❤️")
|
397 |
-
upload_gallery = gr.Gallery(
|
398 |
-
label="Results",
|
399 |
-
elem_classes="output-gallery",
|
400 |
-
columns=3,
|
401 |
-
rows=2,
|
402 |
-
height="auto",
|
403 |
-
allow_preview=False, # Disable preview expansion
|
404 |
-
show_share_button=False,
|
405 |
-
object_fit="cover",
|
406 |
-
preview=False
|
407 |
-
)
|
408 |
|
409 |
# Event handlers
|
410 |
-
def select_example(evt: gr.SelectData):
|
411 |
-
prompts = {'sketch1.png': 'The camel walks slowly',
|
412 |
-
'sketch2.png': 'The wine in the wine glass sways from side to side',
|
413 |
-
'sketch3.png': 'The squirrel is eating a nut',
|
414 |
-
'sketch4.png': 'The surfer surfs on the waves',
|
415 |
-
'sketch5.png': 'A galloping horse',
|
416 |
-
'sketch6.png': 'The cat walks forward',
|
417 |
-
'sketch7.png': 'The eagle flies in the sky',
|
418 |
-
'sketch8.png': 'The flower is blooming slowly',
|
419 |
-
'sketch9.png': 'The reindeer looks around',
|
420 |
-
'sketch10.png': 'The cloud floats in the sky',
|
421 |
-
'sketch11.png': 'The jazz saxophonist performs on stage with a rhythmic sway, his upper body sways subtly to the rhythm of the music.',
|
422 |
-
'sketch12.png': 'The biker rides on the road',}
|
423 |
-
if evt.index < len(example_images):
|
424 |
-
example_img = example_images[evt.index]
|
425 |
-
prompt_text = prompts.get(os.path.basename(example_img.filename), "")
|
426 |
-
|
427 |
-
|
428 |
-
return [
|
429 |
-
example_img,
|
430 |
-
prompt_text
|
431 |
-
]
|
432 |
-
return [None, ""]
|
433 |
-
|
434 |
-
example_selection.select(
|
435 |
-
select_example,
|
436 |
-
None,
|
437 |
-
[selected_example, example_prompt]
|
438 |
-
)
|
439 |
-
|
440 |
example_generate_btn.click(
|
441 |
fn=generate_output,
|
442 |
inputs=[
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
],
|
448 |
-
outputs=example_gallery
|
449 |
-
)
|
450 |
-
|
451 |
-
upload_generate_btn.click(
|
452 |
-
fn=generate_output,
|
453 |
-
inputs=[
|
454 |
-
upload_image,
|
455 |
-
upload_prompt,
|
456 |
-
upload_num_seeds,
|
457 |
-
upload_lambda
|
458 |
],
|
459 |
-
outputs=
|
460 |
)
|
461 |
|
462 |
return demo
|
|
|
200 |
|
201 |
return filtered_gifs
|
202 |
|
203 |
+
css="""
|
|
|
|
|
204 |
.container {
|
205 |
max-width: 1200px;
|
206 |
margin: 0 auto;
|
|
|
258 |
opacity: 0.7;
|
259 |
cursor: not-allowed;
|
260 |
}
|
261 |
+
"""
|
262 |
+
|
263 |
+
def create_gradio_interface():
|
264 |
+
with gr.Blocks(css=css) as demo:
|
265 |
+
with gr.Column():
|
266 |
+
gr.Markdown(
|
267 |
"""
|
268 |
|
269 |
<div align="center" id = "user-content-toc">
|
|
|
274 |
</div>
|
275 |
|
276 |
"""
|
277 |
+
)
|
278 |
|
279 |
+
with gr.Row():
|
280 |
+
with gr.Column():
|
281 |
+
|
282 |
+
input_sketch = gr.Image(
|
283 |
+
type="pil",
|
284 |
+
label="Selected Sketch",
|
285 |
+
scale=1,
|
286 |
+
interactive=True,
|
287 |
+
height=300 # Fixed height for consistency
|
288 |
+
)
|
289 |
+
|
290 |
+
motion_prompt = gr.Textbox(
|
291 |
+
label="Prompt",
|
292 |
+
placeholder="Describe the motion...",
|
293 |
+
lines=3
|
294 |
+
)
|
295 |
+
|
296 |
+
gr.Examples(
|
297 |
+
examples=[
|
298 |
+
['./static/examples/sketch1.png', 'The camel walks slowly'],
|
299 |
+
['./static/examples/sketch2.png', 'The wine in the wine glass sways from side to side'],
|
300 |
+
['./static/examples/sketch3.png', 'The squirrel is eating a nut'],
|
301 |
+
['./static/examples/sketch4.png', 'The surfer surfs on the waves'],
|
302 |
+
['./static/examples/sketch5.png', 'A galloping horse'],
|
303 |
+
['./static/examples/sketch6.png', 'The cat walks forward'],
|
304 |
+
['./static/examples/sketch7.png', 'The eagle flies in the sky'],
|
305 |
+
['./static/examples/sketch8.png', 'The flower is blooming slowly'],
|
306 |
+
['./static/examples/sketch9.png', 'The reindeer looks around'],
|
307 |
+
['./static/examples/sketch10.png', 'The cloud floats in the sky'],
|
308 |
+
['./static/examples/sketch11.png', 'The jazz saxophonist performs on stage with a rhythmic sway, his upper body sways subtly to the rhythm of the music.'],
|
309 |
+
['./static/examples/sketch12.png', 'The biker rides on the road']
|
310 |
+
],
|
311 |
+
inputs=[input_sketche, motion_prompt],
|
312 |
+
examples_per_page=1
|
313 |
+
)
|
314 |
+
|
315 |
+
with gr.Row():
|
316 |
+
num_seeds = gr.Slider(
|
317 |
+
minimum=1,
|
318 |
+
maximum=10,
|
319 |
+
value=5,
|
320 |
+
step=1,
|
321 |
+
label="Seeds"
|
322 |
)
|
323 |
+
lambda_ = gr.Slider(
|
324 |
+
minimum=0,
|
325 |
+
maximum=1,
|
326 |
+
value=0.5,
|
327 |
+
step=0.1,
|
328 |
+
label="Motion Strength"
|
329 |
+
)
|
330 |
+
generate_btn = gr.Button(
|
331 |
+
"Generate Animation",
|
332 |
+
variant="primary",
|
333 |
+
elem_classes="generate-btn",
|
334 |
+
interactive=True,
|
335 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
|
337 |
+
with gr.Column():
|
338 |
|
339 |
+
output_gallery = gr.Gallery(
|
|
|
340 |
label="Results",
|
341 |
elem_classes="output-gallery",
|
342 |
columns=3,
|
|
|
348 |
preview=False
|
349 |
)
|
350 |
|
351 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
example_generate_btn.click(
|
355 |
fn=generate_output,
|
356 |
inputs=[
|
357 |
+
input_sketch,
|
358 |
+
motion_prompt,
|
359 |
+
num_seeds,
|
360 |
+
lambda_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
],
|
362 |
+
outputs=output_gallery
|
363 |
)
|
364 |
|
365 |
return demo
|