rahul7star commited on
Commit
0041f53
·
verified ·
1 Parent(s): 1039b7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -84,6 +84,17 @@ def _calculate_new_dimensions_wan(pil_image, mod_val, calculation_max_area,
84
  return new_h, new_w
85
 
86
  def handle_image_upload_for_dims_wan(uploaded_pil_image, current_h_val, current_w_val):
 
 
 
 
 
 
 
 
 
 
 
87
  if uploaded_pil_image is None:
88
  return gr.update(value=DEFAULT_H_SLIDER_VALUE), gr.update(value=DEFAULT_W_SLIDER_VALUE)
89
  try:
@@ -114,14 +125,7 @@ def get_duration(image,
114
  seed,
115
  progress):
116
  """Calculate dynamic GPU duration based on parameters."""
117
- if duration_seconds >= 3:
118
- return 220
119
- elif sampling_steps > 35 and duration_seconds >= 2:
120
- return 180
121
- elif sampling_steps < 35 or duration_seconds < 2:
122
- return 105
123
- else:
124
- return 90
125
 
126
  # --- 2. Gradio Inference Function ---
127
  @spaces.GPU(duration=get_duration)
@@ -137,7 +141,24 @@ def generate_video(
137
  seed=42,
138
  progress=gr.Progress(track_tqdm=True)
139
  ):
140
- """The main function to generate video, called by the Gradio interface."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  if seed == -1:
142
  seed = random.randint(0, sys.maxsize)
143
 
@@ -250,4 +271,4 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(), delete_cache=(60, 900)) as demo:
250
  )
251
 
252
  if __name__ == "__main__":
253
- demo.launch()
 
84
  return new_h, new_w
85
 
86
  def handle_image_upload_for_dims_wan(uploaded_pil_image, current_h_val, current_w_val):
87
+ """
88
+ Handle image upload and calculate appropriate dimensions for video generation.
89
+
90
+ Args:
91
+ uploaded_pil_image: The uploaded image (PIL Image or numpy array)
92
+ current_h_val: Current height slider value
93
+ current_w_val: Current width slider value
94
+
95
+ Returns:
96
+ Tuple of gr.update objects for height and width sliders
97
+ """
98
  if uploaded_pil_image is None:
99
  return gr.update(value=DEFAULT_H_SLIDER_VALUE), gr.update(value=DEFAULT_W_SLIDER_VALUE)
100
  try:
 
125
  seed,
126
  progress):
127
  """Calculate dynamic GPU duration based on parameters."""
128
+ return sampling_steps * 15
 
 
 
 
 
 
 
129
 
130
  # --- 2. Gradio Inference Function ---
131
  @spaces.GPU(duration=get_duration)
 
141
  seed=42,
142
  progress=gr.Progress(track_tqdm=True)
143
  ):
144
+ """
145
+ Generate a video from text prompt and optional image using the Wan 2.2 TI2V model.
146
+
147
+ Args:
148
+ image: Optional input image (numpy array) for image-to-video generation
149
+ prompt: Text prompt describing the desired video
150
+ height: Target video height in pixels
151
+ width: Target video width in pixels
152
+ duration_seconds: Desired video duration in seconds
153
+ sampling_steps: Number of denoising steps for video generation
154
+ guide_scale: Guidance scale for classifier-free guidance
155
+ shift: Sample shift parameter for the model
156
+ seed: Random seed for reproducibility (-1 for random)
157
+ progress: Gradio progress tracker
158
+
159
+ Returns:
160
+ Path to the generated video file
161
+ """
162
  if seed == -1:
163
  seed = random.randint(0, sys.maxsize)
164
 
 
271
  )
272
 
273
  if __name__ == "__main__":
274
+ demo.launch(mcp_server=True)