Anonymous commited on
Commit
610f540
1 Parent(s): 96b30d4

add example

Browse files
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
 
3
  import sys
 
4
  import pandas as pd
5
  import os
6
  import argparse
@@ -519,7 +520,14 @@ def demo_update_w(mode):
519
  return w_positions
520
 
521
  def plot_update(*positions):
522
- key_length = int(positions[-1])
 
 
 
 
 
 
 
523
  frame_indices = positions[:key_length]
524
  h_positions = positions[MAX_KEYS:MAX_KEYS+key_length]
525
  h_positions_re = []
@@ -565,127 +573,128 @@ with gr.Blocks(css=css) as demo:
565
  video_result = gr.Video(label="Video Output")
566
  video_result_bbox = gr.Video(label="Video Output with BBox")
567
 
568
- with gr.Row():
569
- prompt_in = gr.Textbox(label="Prompt", placeholder="A corgi running on the grassland on the grassland.", scale = 3)
570
- target_indices = gr.Textbox(label="Target Indices", placeholder="1,2", scale = 1)
571
-
572
- with gr.Row():
573
- radio_mode = gr.Radio(label='Trajectory Mode', choices = ['demo', 'diy', 'ori'], scale = 1)
574
- height_ratio = gr.Slider(label='Height Ratio of BBox',
575
- minimum=0.2,
576
- maximum=0.4,
577
- step=0.01,
578
- value=0.3,
579
- scale = 1)
580
- width_ratio = gr.Slider(label='Width Ratio of BBox',
581
- minimum=0.2,
582
- maximum=0.4,
583
- step=0.01,
584
- value=0.3,
585
- scale = 1)
586
-
587
- with gr.Row(visible=False) as row_demo:
588
- dropdown_demo = gr.Dropdown(
589
- label="Demo Trajectory",
590
- choices= ['topleft->bottomright', 'bottomleft->topright', 'topleft->bottomleft->bottomright', 'bottomright->topright->topleft', '"V"', '"^"', 'left->right->left->right', 'triangle']
591
- )
592
-
593
- with gr.Row(visible=False) as row_diy:
594
- dropdown_diy = gr.Dropdown(
595
- label="Number of keyframes",
596
- choices=range(2, MAX_KEYS+1),
597
- )
598
 
599
- for i in range(MAX_KEYS):
600
- with gr.Row(visible=False) as row:
601
- text = f"Keyframe #{i}"
602
- text = gr.HTML(text, visible=True)
603
- frame_ids = gr.Textbox(
604
- None,
605
- label=f"Frame Indices #{i}",
606
- visible=True,
607
- interactive=True,
608
- scale=1
609
  )
610
- h_position = gr.Slider(label='Position in Height',
611
- minimum=0.0,
612
- maximum=1.0,
613
- step=0.01,
614
- scale=1)
615
- w_position = gr.Slider(label='Position in Width',
616
- minimum=0.0,
617
- maximum=1.0,
618
- step=0.01,
619
- scale=1)
620
 
621
- frame_indices.append(frame_ids)
622
- h_positions.append(h_position)
623
- w_positions.append(w_position)
624
- keyframes.append(row)
625
-
626
-
627
- dropdown_demo.change(demo_update, dropdown_demo, dropdown_diy)
628
- dropdown_diy.change(keyframe_update, dropdown_diy, keyframes)
629
- dropdown_demo.change(demo_update_frame, dropdown_demo, frame_indices)
630
- dropdown_demo.change(demo_update_h, dropdown_demo, h_positions)
631
- dropdown_demo.change(demo_update_w, dropdown_demo, w_positions)
632
- radio_mode.change(mode_update, radio_mode, [row_demo, row_diy])
633
-
634
- traj_plot = gr.ScatterPlot(
635
- label="Trajectory",
636
- width=512,
637
- height=320,
638
- )
639
-
640
- h_positions[0].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
641
- h_positions[1].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
642
- h_positions[2].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
643
- h_positions[3].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
644
- h_positions[4].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
645
- w_positions[0].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
646
- w_positions[1].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
647
- w_positions[2].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
648
- w_positions[3].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
649
- w_positions[4].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
650
-
651
- with gr.Row():
652
- with gr.Accordion('Useful FreeTraj Parameters (feel free to adjust these parameters based on your prompt): ', open=True):
653
- with gr.Row():
654
- ddim_edit = gr.Slider(label='Editing Steps (larger for better control while losing some quality)',
655
- minimum=0,
656
- maximum=12,
657
- step=1,
658
- value=6)
659
- seed = gr.Slider(label='Random Seed',
660
- minimum=0,
661
- maximum=10000,
662
- step=1,
663
- value=123)
664
 
665
- with gr.Row():
666
- with gr.Accordion('Useless FreeTraj Parameters (mostly no need to adjust): ', open=False):
667
- with gr.Row():
668
- ddim_steps = gr.Slider(label='DDIM Steps',
669
- minimum=5,
670
- maximum=200,
671
- step=1,
672
- value=50)
673
- unconditional_guidance_scale = gr.Slider(label='Unconditional Guidance Scale',
674
- minimum=1.0,
675
- maximum=20.0,
676
- step=0.1,
677
- value=12.0)
678
- with gr.Row():
679
- video_fps = gr.Slider(label='Video FPS (larger for quicker motion)',
680
- minimum=8,
681
- maximum=36,
682
- step=4,
683
- value=16)
684
- save_fps = gr.Slider(label='Save FPS',
685
- minimum=1,
686
- maximum=30,
687
- step=1,
688
- value=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
689
 
690
  with gr.Row():
691
  submit_btn = gr.Button("Generate", variant='primary')
@@ -693,6 +702,12 @@ with gr.Blocks(css=css) as demo:
693
  with gr.Row():
694
  gr.Examples(label='Sample Prompts', examples=examples, inputs=[prompt_in, target_indices, ddim_edit, seed, ddim_steps, unconditional_guidance_scale, video_fps, save_fps, height_ratio, width_ratio, radio_mode, dropdown_diy, *frame_indices, *h_positions, *w_positions])
695
 
 
 
 
 
 
 
696
  with gr.Row():
697
  gr.Markdown(
698
  """
 
1
  import gradio as gr
2
 
3
  import sys
4
+ import random
5
  import pandas as pd
6
  import os
7
  import argparse
 
520
  return w_positions
521
 
522
  def plot_update(*positions):
523
+ if type(positions[-1]) != int:
524
+ traj_plot = gr.ScatterPlot(
525
+ label="Trajectory",
526
+ width=512,
527
+ height=320,
528
+ )
529
+ return traj_plot
530
+ key_length = positions[-1]
531
  frame_indices = positions[:key_length]
532
  h_positions = positions[MAX_KEYS:MAX_KEYS+key_length]
533
  h_positions_re = []
 
573
  video_result = gr.Video(label="Video Output")
574
  video_result_bbox = gr.Video(label="Video Output with BBox")
575
 
576
+ with gr.Group():
577
+ with gr.Row():
578
+ prompt_in = gr.Textbox(label="Prompt", placeholder="A corgi running on the grassland on the grassland.", scale = 3)
579
+ target_indices = gr.Textbox(label="Target Indices", placeholder="1,2", scale = 1)
580
+
581
+ with gr.Row():
582
+ radio_mode = gr.Radio(label='Trajectory Mode', choices = ['demo', 'diy', 'ori'], scale = 1)
583
+ height_ratio = gr.Slider(label='Height Ratio of BBox',
584
+ minimum=0.2,
585
+ maximum=0.4,
586
+ step=0.01,
587
+ value=0.3,
588
+ scale = 1)
589
+ width_ratio = gr.Slider(label='Width Ratio of BBox',
590
+ minimum=0.2,
591
+ maximum=0.4,
592
+ step=0.01,
593
+ value=0.3,
594
+ scale = 1)
 
 
 
 
 
 
 
 
 
 
 
595
 
596
+ with gr.Row(visible=False) as row_demo:
597
+ dropdown_demo = gr.Dropdown(
598
+ label="Demo Trajectory",
599
+ choices= ['topleft->bottomright', 'bottomleft->topright', 'topleft->bottomleft->bottomright', 'bottomright->topright->topleft', '"V"', '"^"', 'left->right->left->right', 'triangle']
 
 
 
 
 
 
600
  )
 
 
 
 
 
 
 
 
 
 
601
 
602
+ with gr.Row(visible=False) as row_diy:
603
+ dropdown_diy = gr.Dropdown(
604
+ label="Number of keyframes",
605
+ choices=range(2, MAX_KEYS+1),
606
+ )
607
+
608
+ for i in range(MAX_KEYS):
609
+ with gr.Row(visible=False) as row:
610
+ text = f"Keyframe #{i}"
611
+ text = gr.HTML(text, visible=True)
612
+ frame_ids = gr.Textbox(
613
+ None,
614
+ label=f"Frame Indices #{i}",
615
+ visible=True,
616
+ interactive=True,
617
+ scale=1
618
+ )
619
+ h_position = gr.Slider(label='Position in Height',
620
+ minimum=0.0,
621
+ maximum=1.0,
622
+ step=0.01,
623
+ scale=1)
624
+ w_position = gr.Slider(label='Position in Width',
625
+ minimum=0.0,
626
+ maximum=1.0,
627
+ step=0.01,
628
+ scale=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
 
630
+ frame_indices.append(frame_ids)
631
+ h_positions.append(h_position)
632
+ w_positions.append(w_position)
633
+ keyframes.append(row)
634
+
635
+
636
+ dropdown_demo.change(demo_update, dropdown_demo, dropdown_diy)
637
+ dropdown_diy.change(keyframe_update, dropdown_diy, keyframes)
638
+ dropdown_demo.change(demo_update_frame, dropdown_demo, frame_indices)
639
+ dropdown_demo.change(demo_update_h, dropdown_demo, h_positions)
640
+ dropdown_demo.change(demo_update_w, dropdown_demo, w_positions)
641
+ radio_mode.change(mode_update, radio_mode, [row_demo, row_diy])
642
+
643
+ traj_plot = gr.ScatterPlot(
644
+ label="Trajectory",
645
+ width=512,
646
+ height=320,
647
+ )
648
+
649
+ h_positions[0].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
650
+ h_positions[1].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
651
+ h_positions[2].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
652
+ h_positions[3].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
653
+ h_positions[4].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
654
+ w_positions[0].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
655
+ w_positions[1].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
656
+ w_positions[2].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
657
+ w_positions[3].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
658
+ w_positions[4].change(plot_update, frame_indices + h_positions + w_positions + [dropdown_diy], traj_plot)
659
+
660
+ with gr.Row():
661
+ with gr.Accordion('Useful FreeTraj Parameters (feel free to adjust these parameters based on your prompt): ', open=True):
662
+ with gr.Row():
663
+ ddim_edit = gr.Slider(label='Editing Steps (larger for better control while losing some quality)',
664
+ minimum=0,
665
+ maximum=12,
666
+ step=1,
667
+ value=6)
668
+ seed = gr.Slider(label='Random Seed',
669
+ minimum=0,
670
+ maximum=10000,
671
+ step=1,
672
+ value=123)
673
+
674
+ with gr.Row():
675
+ with gr.Accordion('Useless FreeTraj Parameters (mostly no need to adjust): ', open=False):
676
+ with gr.Row():
677
+ ddim_steps = gr.Slider(label='DDIM Steps',
678
+ minimum=5,
679
+ maximum=200,
680
+ step=1,
681
+ value=50)
682
+ unconditional_guidance_scale = gr.Slider(label='Unconditional Guidance Scale',
683
+ minimum=1.0,
684
+ maximum=20.0,
685
+ step=0.1,
686
+ value=12.0)
687
+ with gr.Row():
688
+ video_fps = gr.Slider(label='Video FPS (larger for quicker motion)',
689
+ minimum=8,
690
+ maximum=36,
691
+ step=4,
692
+ value=16)
693
+ save_fps = gr.Slider(label='Save FPS',
694
+ minimum=1,
695
+ maximum=30,
696
+ step=1,
697
+ value=10)
698
 
699
  with gr.Row():
700
  submit_btn = gr.Button("Generate", variant='primary')
 
702
  with gr.Row():
703
  gr.Examples(label='Sample Prompts', examples=examples, inputs=[prompt_in, target_indices, ddim_edit, seed, ddim_steps, unconditional_guidance_scale, video_fps, save_fps, height_ratio, width_ratio, radio_mode, dropdown_diy, *frame_indices, *h_positions, *w_positions])
704
 
705
+ demo_list = ['0026_0_0.4_0.4.gif', '0047_1_0.4_0.3.gif', '0051_1_0.4_0.4.gif']
706
+ demo_pick = random.randint(0, len(demo_list) - 1)
707
+ with gr.Row():
708
+ for i in range(len(demo_list)):
709
+ gr.Image(show_label = False, show_download_button = False, value='assets/' + demo_list[i])
710
+
711
  with gr.Row():
712
  gr.Markdown(
713
  """
assets/0026_0_0.4_0.4.gif ADDED
assets/0047_1_0.4_0.3.gif ADDED
assets/0051_1_0.4_0.4.gif ADDED