prithivMLmods cbensimon HF Staff commited on
Commit
c1904ce
·
verified ·
1 Parent(s): c9802c1

Dynamic duration (#2)

Browse files

- Dynamic duration (8cc70eb7d42e43f5b4b56cc4e6e47647c8627cea)


Co-authored-by: Charles Bensimon <[email protected]>

Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -41,8 +41,26 @@ aspect_ratios = {
41
  "3:4": (1140, 1472)
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # Generation function for Qwen/Qwen-Image
45
- @spaces.GPU
46
  def generate_qwen(
47
  prompt: str,
48
  negative_prompt: str = "",
@@ -89,7 +107,7 @@ def generate_qwen(
89
  return image_paths, seed, f"{duration:.2f}", zip_path
90
 
91
  # Wrapper function to handle UI logic
92
- @spaces.GPU
93
  def generate(
94
  prompt: str,
95
  negative_prompt: str,
 
41
  "3:4": (1140, 1472)
42
  }
43
 
44
+ def get_duration(
45
+ prompt: str,
46
+ negative_prompt: str,
47
+ use_negative_prompt: bool,
48
+ seed: int,
49
+ width: int,
50
+ height: int,
51
+ guidance_scale: float,
52
+ randomize_seed: bool,
53
+ num_inference_steps: int,
54
+ num_images: int,
55
+ zip_images: bool,
56
+ progress=gr.Progress(track_tqdm=True),
57
+ ):
58
+ step_duration = 0.6
59
+ step_duration *= (width * height) / (1024 * 1024)
60
+ per_image_duration = 5 + num_inference_steps * step_duration
61
+ return 10 + num_images * per_image_duration
62
+
63
  # Generation function for Qwen/Qwen-Image
 
64
  def generate_qwen(
65
  prompt: str,
66
  negative_prompt: str = "",
 
107
  return image_paths, seed, f"{duration:.2f}", zip_path
108
 
109
  # Wrapper function to handle UI logic
110
+ @spaces.GPU(duration=get_duration)
111
  def generate(
112
  prompt: str,
113
  negative_prompt: str,