linoyts HF Staff commited on
Commit
33f10c8
·
verified ·
1 Parent(s): b15e441

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -49,9 +49,9 @@ MAX_FRAMES_MODEL = 81
49
 
50
  # Default prompts for different modes - Updated with new mode names
51
  MODE_PROMPTS = {
52
- "reference": "the playful penguin picks up the green cat eye sunglasses and puts them on",
53
- "first - last frame": "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective.",
54
- "random transitions": "Various different characters appear and disappear in a fast transition video showcasting their unique features and personalities. The video is about showcasing different dance styles, with each character performing a distinct dance move. The background is a vibrant, colorful stage with dynamic lighting that changes with each dance style. The camera captures close-ups of the dancers' expressions and movements. Highly dynamic, fast-paced music video, with quick cuts and transitions between characters, cinematic, vibrant colors"
55
  }
56
 
57
  default_negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards, watermark, text, signature"
@@ -335,7 +335,7 @@ def get_duration(gallery_images, mode, prompt, height, width,
335
  base_duration = 75
336
 
337
  # Add extra time for background removal processing
338
- if mode == "reference" and remove_bg: # Updated to use new mode name
339
  base_duration += 30
340
 
341
  return base_duration
@@ -351,7 +351,7 @@ def generate_video(gallery_images, mode, prompt, height, width,
351
 
352
  Args:
353
  gallery_images (list): List of PIL images from the gallery
354
- mode (str): Processing mode - "reference", "first - last frame", or "random transitions"
355
  prompt (str): Text prompt describing the desired animation
356
  height (int): Target height for the output video
357
  width (int): Target width for the output video
@@ -376,7 +376,7 @@ def generate_video(gallery_images, mode, prompt, height, width,
376
  image = img[0] # Extract PIL image from gallery format
377
 
378
  # Apply background removal only for reference mode if checkbox is checked
379
- if mode == "reference" and remove_bg: # Updated to use new mode name
380
  image = remove_background_from_image(image)
381
 
382
  # Always remove alpha channels to ensure RGB format
@@ -385,9 +385,9 @@ def generate_video(gallery_images, mode, prompt, height, width,
385
 
386
  gallery_images = processed_images
387
 
388
- if mode == "first - last frame" and len(gallery_images) >= 2: # Updated mode name
389
  gallery_images = gallery_images[:2]
390
- elif mode == "first - last frame" and len(gallery_images) < 2: # Updated mode name
391
  raise gr.Error("First - Last Frame mode requires at least 2 images, but only {} were supplied.".format(len(gallery_images)))
392
 
393
  target_h = max(MOD_VALUE, (int(height) // MOD_VALUE) * MOD_VALUE)
@@ -398,7 +398,7 @@ def generate_video(gallery_images, mode, prompt, height, width,
398
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
399
 
400
  # Process images based on the selected mode
401
- if mode == "first - last frame": # Updated mode name
402
  frames, mask = prepare_video_and_mask_FLF2V(
403
  first_img=gallery_images[0],
404
  last_img=gallery_images[1],
@@ -407,7 +407,7 @@ def generate_video(gallery_images, mode, prompt, height, width,
407
  num_frames=num_frames
408
  )
409
  reference_images = None
410
- elif mode == "reference": # Updated mode name
411
  frames, mask = prepare_video_and_mask_Ref2V(height=target_h, width=target_w, num_frames=num_frames)
412
  reference_images = gallery_images
413
  else: # mode == "random transitions" # Updated mode name
@@ -460,7 +460,7 @@ with gr.Blocks() as demo:
460
  with gr.Group():
461
  # Radio button for mode selection with updated names
462
  mode_radio = gr.Radio(
463
- choices=["Reference", "First - Last frame", "Random Transitions"],
464
  value="reference",
465
  label="Control Mode",
466
  #info="Reference: upload reference images to take elements from | First - Last Frame: upload 1st and last frames| Random Transitions: upload images to be used as frame anchors"
 
49
 
50
  # Default prompts for different modes - Updated with new mode names
51
  MODE_PROMPTS = {
52
+ "Reference": "the playful penguin picks up the green cat eye sunglasses and puts them on",
53
+ "First - Last Frame": "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective.",
54
+ "Random Transitions": "Various different characters appear and disappear in a fast transition video showcasting their unique features and personalities. The video is about showcasing different dance styles, with each character performing a distinct dance move. The background is a vibrant, colorful stage with dynamic lighting that changes with each dance style. The camera captures close-ups of the dancers' expressions and movements. Highly dynamic, fast-paced music video, with quick cuts and transitions between characters, cinematic, vibrant colors"
55
  }
56
 
57
  default_negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards, watermark, text, signature"
 
335
  base_duration = 75
336
 
337
  # Add extra time for background removal processing
338
+ if mode == "Reference" and remove_bg: # Updated to use new mode name
339
  base_duration += 30
340
 
341
  return base_duration
 
351
 
352
  Args:
353
  gallery_images (list): List of PIL images from the gallery
354
+ mode (str): Processing mode - "Reference", "first - last frame", or "random transitions"
355
  prompt (str): Text prompt describing the desired animation
356
  height (int): Target height for the output video
357
  width (int): Target width for the output video
 
376
  image = img[0] # Extract PIL image from gallery format
377
 
378
  # Apply background removal only for reference mode if checkbox is checked
379
+ if mode == "Reference" and remove_bg: # Updated to use new mode name
380
  image = remove_background_from_image(image)
381
 
382
  # Always remove alpha channels to ensure RGB format
 
385
 
386
  gallery_images = processed_images
387
 
388
+ if mode == "First - Last Frame" and len(gallery_images) >= 2: # Updated mode name
389
  gallery_images = gallery_images[:2]
390
+ elif mode == "First - Last Frame" and len(gallery_images) < 2: # Updated mode name
391
  raise gr.Error("First - Last Frame mode requires at least 2 images, but only {} were supplied.".format(len(gallery_images)))
392
 
393
  target_h = max(MOD_VALUE, (int(height) // MOD_VALUE) * MOD_VALUE)
 
398
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
399
 
400
  # Process images based on the selected mode
401
+ if mode == "First - Last Frame": # Updated mode name
402
  frames, mask = prepare_video_and_mask_FLF2V(
403
  first_img=gallery_images[0],
404
  last_img=gallery_images[1],
 
407
  num_frames=num_frames
408
  )
409
  reference_images = None
410
+ elif mode == "Reference": # Updated mode name
411
  frames, mask = prepare_video_and_mask_Ref2V(height=target_h, width=target_w, num_frames=num_frames)
412
  reference_images = gallery_images
413
  else: # mode == "random transitions" # Updated mode name
 
460
  with gr.Group():
461
  # Radio button for mode selection with updated names
462
  mode_radio = gr.Radio(
463
+ choices=["Reference", "First - Last Frame", "Random Transitions"],
464
  value="reference",
465
  label="Control Mode",
466
  #info="Reference: upload reference images to take elements from | First - Last Frame: upload 1st and last frames| Random Transitions: upload images to be used as frame anchors"