mcp-improve

#22
by victor HF Staff - opened
Files changed (1) hide show
  1. app.py +40 -5
app.py CHANGED
@@ -141,12 +141,47 @@ def get_duration(prompt, negative_prompt, input_image_filepath, input_video_file
141
  return 60
142
 
143
  @spaces.GPU(duration=get_duration)
144
- def generate(prompt, negative_prompt, input_image_filepath, input_video_filepath,
145
- height_ui, width_ui, mode,
146
- duration_ui,
147
- ui_frames_to_use,
148
- seed_ui, randomize_seed, ui_guidance_scale, improve_texture_flag,
149
  progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  if randomize_seed:
152
  seed_ui = random.randint(0, 2**32 - 1)
 
141
  return 60
142
 
143
  @spaces.GPU(duration=get_duration)
144
+ def generate(prompt, negative_prompt, input_image_filepath=None, input_video_filepath=None,
145
+ height_ui=512, width_ui=704, mode="text-to-video",
146
+ duration_ui=2.0,
147
+ ui_frames_to_use=9,
148
+ seed_ui=42, randomize_seed=True, ui_guidance_scale=3.0, improve_texture_flag=True,
149
  progress=gr.Progress(track_tqdm=True)):
150
+ """
151
+ Generate high-quality videos using LTX Video model with support for text-to-video, image-to-video, and video-to-video modes.
152
+
153
+ Args:
154
+ prompt (str): Text description of the desired video content. Required for all modes.
155
+ negative_prompt (str): Text describing what to avoid in the generated video. Optional, can be empty string.
156
+ input_image_filepath (str or None): Path to input image file. Required for image-to-video mode, None for other modes.
157
+ input_video_filepath (str or None): Path to input video file. Required for video-to-video mode, None for other modes.
158
+ height_ui (int): Height of the output video in pixels, must be divisible by 32. Default: 512.
159
+ width_ui (int): Width of the output video in pixels, must be divisible by 32. Default: 704.
160
+ mode (str): Generation mode. Required. One of "text-to-video", "image-to-video", or "video-to-video". Default: "text-to-video".
161
+ duration_ui (float): Duration of the output video in seconds. Range: 0.3 to 8.5. Default: 2.0.
162
+ ui_frames_to_use (int): Number of frames to use from input video. Only used in video-to-video mode. Must be N*8+1. Default: 9.
163
+ seed_ui (int): Random seed for reproducible generation. Range: 0 to 2^32-1. Default: 42.
164
+ randomize_seed (bool): Whether to use a random seed instead of seed_ui. Default: True.
165
+ ui_guidance_scale (float): CFG scale controlling prompt influence. Range: 1.0 to 10.0. Higher values = stronger prompt influence. Default: 3.0.
166
+ improve_texture_flag (bool): Whether to use multi-scale generation for better texture quality. Slower but higher quality. Default: True.
167
+ progress (gr.Progress): Progress tracker for the generation process. Optional, used for UI updates.
168
+
169
+ Returns:
170
+ tuple: A tuple containing (output_video_path, used_seed) where output_video_path is the path to the generated video file and used_seed is the actual seed used for generation.
171
+ """
172
+
173
+ # Validate mode-specific required parameters
174
+ if mode == "image-to-video":
175
+ if not input_image_filepath:
176
+ raise gr.Error("input_image_filepath is required for image-to-video mode")
177
+ elif mode == "video-to-video":
178
+ if not input_video_filepath:
179
+ raise gr.Error("input_video_filepath is required for video-to-video mode")
180
+ elif mode == "text-to-video":
181
+ # No additional file inputs required for text-to-video
182
+ pass
183
+ else:
184
+ raise gr.Error(f"Invalid mode: {mode}. Must be one of: text-to-video, image-to-video, video-to-video")
185
 
186
  if randomize_seed:
187
  seed_ui = random.randint(0, 2**32 - 1)