11import os , argparse
22import sys
33import gradio as gr
4+ import random
45from scripts .gradio .i2v_test import Image2Video
56sys .path .insert (1 , os .path .join (sys .path [0 ], 'lvdm' ))
67
3132 ['prompts/256/guitar0.jpeg' , 'bear playing guitar happily, snowing' , 50 , 7.5 , 1.0 , 3 , 122 ]
3233]
3334
35+ max_seed = 2 ** 31
36+
3437
3538def dynamicrafter_demo (result_dir = './tmp/' , res = 1024 ):
3639 if res == 1024 :
3740 resolution = '576_1024'
38- css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}"""
41+ css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important} """
3942 elif res == 512 :
4043 resolution = '320_512'
41- css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}"""
44+ css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #random_button {max-width: 100px !important} """
4245 elif res == 256 :
4346 resolution = '256_256'
44- css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}"""
47+ css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px} #random_button {max-width: 100px !important} """
4548 else :
4649 raise NotImplementedError (f"Unsupported resolution: { res } " )
4750 image2video = Image2Video (result_dir , resolution = resolution )
@@ -70,12 +73,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024):
7073 with gr .Row ():
7174 i2v_input_text = gr .Text (label = 'Prompts' )
7275 with gr .Row ():
73- i2v_seed = gr .Slider (label = 'Random Seed' , minimum = 0 , maximum = 10000 , step = 1 , value = 123 )
7476 i2v_eta = gr .Slider (minimum = 0.0 , maximum = 1.0 , step = 0.1 , label = 'ETA' , value = 1.0 , elem_id = "i2v_eta" )
7577 i2v_cfg_scale = gr .Slider (minimum = 1.0 , maximum = 15.0 , step = 0.5 , label = 'CFG Scale' , value = 7.5 , elem_id = "i2v_cfg_scale" )
7678 with gr .Row ():
7779 i2v_steps = gr .Slider (minimum = 1 , maximum = 60 , step = 1 , elem_id = "i2v_steps" , label = "Sampling steps" , value = 50 )
7880 i2v_motion = gr .Slider (minimum = 5 , maximum = 20 , step = 1 , elem_id = "i2v_motion" , label = "FPS" , value = 10 )
81+ with gr .Row ():
82+ i2v_seed = gr .Slider (label = 'Random Seed' , minimum = 0 , maximum = max_seed , step = 1 , value = 123 )
83+ random_button = gr .Button ('\U0001f3b2 \ufe0f ' , elem_id = "random_button" )
84+ random_button .click (
85+ fn = lambda : random .randint (0 , max_seed ),
86+ outputs = i2v_seed ,
87+ queue = False
88+ )
7989 i2v_end_btn = gr .Button ("Generate" )
8090 # with gr.Tab(label='Result'):
8191 with gr .Row ():
@@ -101,12 +111,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024):
101111 with gr .Row ():
102112 i2v_input_text = gr .Text (label = 'Prompts' )
103113 with gr .Row ():
104- i2v_seed = gr .Slider (label = 'Random Seed' , minimum = 0 , maximum = 10000 , step = 1 , value = 123 )
105114 i2v_eta = gr .Slider (minimum = 0.0 , maximum = 1.0 , step = 0.1 , label = 'ETA' , value = 1.0 , elem_id = "i2v_eta" )
106115 i2v_cfg_scale = gr .Slider (minimum = 1.0 , maximum = 15.0 , step = 0.5 , label = 'CFG Scale' , value = 7.5 , elem_id = "i2v_cfg_scale" )
107116 with gr .Row ():
108117 i2v_steps = gr .Slider (minimum = 1 , maximum = 60 , step = 1 , elem_id = "i2v_steps" , label = "Sampling steps" , value = 50 )
109118 i2v_motion = gr .Slider (minimum = 15 , maximum = 30 , step = 1 , elem_id = "i2v_motion" , label = "FPS" , value = 24 )
119+ with gr .Row ():
120+ i2v_seed = gr .Slider (label = 'Random Seed' , minimum = 0 , maximum = max_seed , step = 1 , value = 123 )
121+ random_button = gr .Button ('\U0001f3b2 \ufe0f ' , elem_id = "random_button" )
122+ random_button .click (
123+ fn = lambda : random .randint (0 , max_seed ),
124+ outputs = i2v_seed ,
125+ queue = False
126+ )
110127 i2v_end_btn = gr .Button ("Generate" )
111128 # with gr.Tab(label='Result'):
112129 with gr .Row ():
@@ -132,12 +149,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024):
132149 with gr .Row ():
133150 i2v_input_text = gr .Text (label = 'Prompts' )
134151 with gr .Row ():
135- i2v_seed = gr .Slider (label = 'Random Seed' , minimum = 0 , maximum = 10000 , step = 1 , value = 123 )
136152 i2v_eta = gr .Slider (minimum = 0.0 , maximum = 1.0 , step = 0.1 , label = 'ETA' , value = 1.0 , elem_id = "i2v_eta" )
137153 i2v_cfg_scale = gr .Slider (minimum = 1.0 , maximum = 15.0 , step = 0.5 , label = 'CFG Scale' , value = 7.5 , elem_id = "i2v_cfg_scale" )
138154 with gr .Row ():
139155 i2v_steps = gr .Slider (minimum = 1 , maximum = 60 , step = 1 , elem_id = "i2v_steps" , label = "Sampling steps" , value = 50 )
140156 i2v_motion = gr .Slider (minimum = 1 , maximum = 4 , step = 1 , elem_id = "i2v_motion" , label = "Motion magnitude" , value = 3 )
157+ with gr .Row ():
158+ i2v_seed = gr .Slider (label = 'Random Seed' , minimum = 0 , maximum = max_seed , step = 1 , value = 123 )
159+ random_button = gr .Button ('\U0001f3b2 \ufe0f ' , elem_id = "random_button" )
160+ random_button .click (
161+ fn = lambda : random .randint (0 , max_seed ),
162+ outputs = i2v_seed ,
163+ queue = False
164+ )
141165 i2v_end_btn = gr .Button ("Generate" )
142166 # with gr.Tab(label='Result'):
143167 with gr .Row ():
0 commit comments