linoyts HF Staff commited on
Commit
64041b2
·
verified ·
1 Parent(s): e1d5bb5

Update app.py (#1)

Browse files

- Update app.py (b3547a510c7a30c0995836463308ff6a98d90a1e)
- Update app.py (f41263642fc83451fae2692116077eac7746722b)

Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -27,14 +27,17 @@ def round_to_nearest_resolution_acceptable_by_vae(height, width):
27
  @spaces.GPU
28
  def generate(prompt,
29
  negative_prompt,
30
- image,
 
31
  steps,
32
  num_frames,
33
  seed,
34
  randomize_seed,
35
  t2v, improve_texture=False, progress=gr.Progress(track_tqdm=True)):
36
 
37
-
 
 
38
  # Part 1. Generate video at smaller resolution
39
  # Text-only conditioning is also supported without the need to pass `conditions`
40
  expected_height, expected_width = 768, 1152
@@ -42,11 +45,15 @@ def generate(prompt,
42
  downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
43
  downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
44
 
45
- if randomize_seed:
46
- seed = random.randint(0, MAX_SEED)
 
 
 
 
47
 
48
- if image is not None or t2v:
49
- condition1 = LTXVideoCondition(video=image, frame_index=0)
50
  latents = pipe(
51
  conditions=condition1,
52
  prompt=prompt,
@@ -155,9 +162,15 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
155
  with gr.Row():
156
  with gr.Column():
157
  with gr.Group():
158
- image = gr.Image(label="")
 
 
 
 
 
 
 
159
  prompt = gr.Textbox(label="prompt")
160
- t2v = gr.Checkbox(label="run text-to-video", value=False)
161
  run_button = gr.Button()
162
  with gr.Column():
163
  output = gr.Video(interactive=False)
@@ -170,13 +183,15 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
170
  randomize_seed = gr.Checkbox(label="randomize seed")
171
  with gr.Row():
172
  steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)
173
- num_frames = gr.Slider(label="# frames", minimum=1, maximum=200, value=161, step=1)
 
174
 
175
 
176
  run_button.click(fn=generate,
177
  inputs=[prompt,
178
  negative_prompt,
179
- image,
 
180
  steps,
181
  num_frames,
182
  seed,
 
27
  @spaces.GPU
28
  def generate(prompt,
29
  negative_prompt,
30
+ image,
31
+ video,
32
  steps,
33
  num_frames,
34
  seed,
35
  randomize_seed,
36
  t2v, improve_texture=False, progress=gr.Progress(track_tqdm=True)):
37
 
38
+ if randomize_seed:
39
+ seed = random.randint(0, MAX_SEED)
40
+
41
  # Part 1. Generate video at smaller resolution
42
  # Text-only conditioning is also supported without the need to pass `conditions`
43
  expected_height, expected_width = 768, 1152
 
45
  downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
46
  downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
47
 
48
+ condition = image is not None or video is not None
49
+ if video:
50
+ frames_to_use = 21
51
+ video = load_video(video)[:frames_to_use]
52
+ else:
53
+ video = [image]
54
 
55
+ if condition and (not t2v):
56
+ condition1 = LTXVideoCondition(video=video, frame_index=0)
57
  latents = pipe(
58
  conditions=condition1,
59
  prompt=prompt,
 
162
  with gr.Row():
163
  with gr.Column():
164
  with gr.Group():
165
+ with gr.Tab("text-to-video"):
166
+ image = gr.Image(label="", visible=False)
167
+ #prompt = gr.Textbox(label="prompt")
168
+ with gr.Tab("image-to-video"):
169
+ image = gr.Image(label="")
170
+ #prompt = gr.Textbox(label="prompt")
171
+ with gr.Tab("video-to-video"):
172
+ video = gr.Video(label="")
173
  prompt = gr.Textbox(label="prompt")
 
174
  run_button = gr.Button()
175
  with gr.Column():
176
  output = gr.Video(interactive=False)
 
183
  randomize_seed = gr.Checkbox(label="randomize seed")
184
  with gr.Row():
185
  steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)
186
+ num_frames = gr.Slider(label="# frames", minimum=1, maximum=30, value=8, step=1)
187
+
188
 
189
 
190
  run_button.click(fn=generate,
191
  inputs=[prompt,
192
  negative_prompt,
193
+ image,
194
+ video,
195
  steps,
196
  num_frames,
197
  seed,