Make Enhance Prompt an option

#3
by multimodalart HF Staff - opened
Files changed (4) hide show
  1. .gitattributes +0 -2
  2. app.py +38 -29
  3. examples/neon.mp4 +0 -3
  4. examples/painter.mp4 +0 -3
.gitattributes CHANGED
@@ -36,5 +36,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
36
  examples/man_walking.mp4 filter=lfs diff=lfs merge=lfs -text
37
  examples/leopard.mp4 filter=lfs diff=lfs merge=lfs -text
38
  examples/woman.mp4 filter=lfs diff=lfs merge=lfs -text
39
- examples/neon.mp4 filter=lfs diff=lfs merge=lfs -text
40
- examples/painter.mp4 filter=lfs diff=lfs merge=lfs -text
 
36
  examples/man_walking.mp4 filter=lfs diff=lfs merge=lfs -text
37
  examples/leopard.mp4 filter=lfs diff=lfs merge=lfs -text
38
  examples/woman.mp4 filter=lfs diff=lfs merge=lfs -text
 
 
app.py CHANGED
@@ -18,20 +18,20 @@ def calculate_resolution(input_width, input_height, min_dimension=480, max_dimen
18
  # Ensure dimensions are multiples of the compatible rounding
19
  def round_to(x, compatible_round):
20
  return max(min_dimension, min(max_dimension, int(round(x / compatible_round) * compatible_round)))
21
-
22
  # Get aspect ratio
23
  aspect_ratio = input_width / input_height
24
-
25
  # Square videos (aspect ratio close to 1:1)
26
  if 0.98 <= aspect_ratio <= 1.02:
27
  return 640, 640
28
-
29
  # Landscape videos (width > height)
30
  elif aspect_ratio > 1:
31
  # Try to use max width
32
  new_width = max_dimension
33
  new_height = new_width / aspect_ratio
34
-
35
  # If height would be too small, use min height
36
  if new_height < min_dimension:
37
  new_height = min_dimension
@@ -39,15 +39,15 @@ def calculate_resolution(input_width, input_height, min_dimension=480, max_dimen
39
  # If width exceeds max, clamp it
40
  if new_width > max_dimension:
41
  new_width = max_dimension
42
-
43
  return round_to(new_width, compatible_round), round_to(new_height, compatible_round)
44
-
45
  # Portrait videos (height > width)
46
  else:
47
  # Try to use max height
48
  new_height = max_dimension
49
  new_width = new_height * aspect_ratio
50
-
51
  # If width would be too small, use min width
52
  if new_width < min_dimension:
53
  new_width = min_dimension
@@ -55,7 +55,7 @@ def calculate_resolution(input_width, input_height, min_dimension=480, max_dimen
55
  # If height exceeds max, clamp it
56
  if new_height > max_dimension:
57
  new_height = max_dimension
58
-
59
  return round_to(new_width, compatible_round), round_to(new_height, compatible_round)
60
 
61
 
@@ -64,6 +64,7 @@ def process_video(
64
  video_path,
65
  prompt,
66
  negative_prompt="",
 
67
  num_frames=81,
68
  auto_resize=True,
69
  manual_height=480,
@@ -74,12 +75,16 @@ def process_video(
74
  # Load and preprocess video
75
  progress(0.2, desc="Loading video...")
76
 
 
 
 
 
77
  # Get video dimensions
78
  temp_video = load_video(video_path)
79
  print(len(temp_video))
80
  if temp_video and len(temp_video) > 0:
81
  original_width, original_height = temp_video[0].size
82
-
83
  # Calculate dimensions
84
  if auto_resize:
85
  width, height = calculate_resolution(original_width, original_height)
@@ -87,7 +92,7 @@ def process_video(
87
  width, height = manual_width, manual_height
88
  else:
89
  raise gr.Error("Could not load video or video is empty")
90
-
91
  # Convert video function
92
  def convert_video(video: List[Image.Image]) -> List[Image.Image]:
93
  # Ensure we don't exceed the video length
@@ -96,14 +101,14 @@ def process_video(
96
  # Resize frames
97
  video_frames = [frame.resize((width, height)) for frame in video_frames]
98
  return video_frames
99
-
100
  # Load video from file path
101
  video = load_video(video_path, convert_method=convert_video)
102
-
103
  # Ensure we have the right number of frames
104
  if len(video) < num_frames:
105
  num_frames = len(video)
106
-
107
  # Generate edited video
108
  progress(0.5, desc="Generating edited video...")
109
  output = pipe(
@@ -115,14 +120,14 @@ def process_video(
115
  num_frames=num_frames,
116
  guidance_scale=guidance_scale,
117
  ).frames[0]
118
-
119
  # Export to temporary file
120
  progress(0.9, desc="Exporting video...")
121
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
122
  output_path = tmp_file.name
123
-
124
  export_to_video(output, output_path, fps=24)
125
-
126
  progress(1.0, desc="Complete!")
127
  return output_path
128
 
@@ -141,19 +146,21 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
141
  &nbsp;|&nbsp; 📑 <a href="#">arXiv (Coming soon)</a>
142
  &nbsp;|&nbsp; 💬 <a href="https://discord.gg/decart">Discord</a>
143
  </p>""")
144
-
145
  with gr.Row():
146
  with gr.Column(scale=1):
147
  # Input controls
148
  video_input = gr.Video(label="Input Video")
149
-
150
  prompt = gr.Textbox(
151
  label="Edit Prompt",
152
  placeholder="Describe what you want to change in the video...",
153
  lines=3
154
  )
155
-
156
  with gr.Accordion("Advanced Settings", open=False):
 
 
157
  negative_prompt = gr.Textbox(
158
  label="Negative Prompt (optional)",
159
  placeholder="Describe what you DON'T want in the video...",
@@ -164,7 +171,7 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
164
  value=True,
165
  info="Automatically calculate dimensions based on input video"
166
  )
167
-
168
  num_frames = gr.Slider(
169
  label="Number of Frames",
170
  minimum=1,
@@ -173,7 +180,7 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
173
  step=1,
174
  info="More frames = longer processing time"
175
  )
176
-
177
  with gr.Row():
178
  manual_height = gr.Slider(
179
  label="Height (when auto-resize is off)",
@@ -189,7 +196,7 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
189
  value=832,
190
  step=32
191
  )
192
-
193
  guidance_scale = gr.Slider(
194
  label="Guidance Scale",
195
  minimum=1.0,
@@ -198,23 +205,24 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
198
  step=0.5,
199
  info="Higher values follow the prompt more strictly"
200
  )
201
-
202
  generate_btn = gr.Button("Edit Video", variant="primary")
203
-
204
  with gr.Column(scale=1):
205
- video_output = gr.Video(label="Edited Video", autoplay=True)
206
 
207
  gr.Examples(
208
  examples=[
209
- ["examples/neon.mp4", "Add a colorful scarlet macaw parrot perched on the man's left shoulder, bright red and blue wing feathers with yellow accents, curved black beak, intelligent dark eyes, talons gripping fabric naturally, long tail feathers extending downward, glossy plumage catching light, slight wing adjustment for balance, natural weight distribution, soft shadow beneath bird."],
210
- ["examples/painter.mp4", "Change the hair color to platinum blonde with natural highlights, subtle root shadowing, silky texture, gentle waves, soft shine, dimensional tones, strand definition, natural movement, professional color treatment, salon-quality finish, light-catching shimmer, varied blonde shades from honey to ash, realistic color gradation, healthy glossy appearance, volumetric lighting interaction."],
 
211
  ],
212
  inputs=[video_input, prompt],
213
  outputs=video_output,
214
  fn=process_video,
215
  cache_examples="lazy",
216
  )
217
-
218
  # Event handlers
219
  generate_btn.click(
220
  fn=process_video,
@@ -222,6 +230,7 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
222
  video_input,
223
  prompt,
224
  negative_prompt,
 
225
  num_frames,
226
  auto_resize,
227
  manual_height,
@@ -232,4 +241,4 @@ with gr.Blocks(title="Lucy Edit - Video Editing with Text", css=css) as demo:
232
  )
233
 
234
  if __name__ == "__main__":
235
- demo.launch(share=True)
 
18
  # Ensure dimensions are multiples of the compatible rounding
19
  def round_to(x, compatible_round):
20
  return max(min_dimension, min(max_dimension, int(round(x / compatible_round) * compatible_round)))
21
+
22
  # Get aspect ratio
23
  aspect_ratio = input_width / input_height
24
+
25
  # Square videos (aspect ratio close to 1:1)
26
  if 0.98 <= aspect_ratio <= 1.02:
27
  return 640, 640
28
+
29
  # Landscape videos (width > height)
30
  elif aspect_ratio > 1:
31
  # Try to use max width
32
  new_width = max_dimension
33
  new_height = new_width / aspect_ratio
34
+
35
  # If height would be too small, use min height
36
  if new_height < min_dimension:
37
  new_height = min_dimension
 
39
  # If width exceeds max, clamp it
40
  if new_width > max_dimension:
41
  new_width = max_dimension
42
+
43
  return round_to(new_width, compatible_round), round_to(new_height, compatible_round)
44
+
45
  # Portrait videos (height > width)
46
  else:
47
  # Try to use max height
48
  new_height = max_dimension
49
  new_width = new_height * aspect_ratio
50
+
51
  # If width would be too small, use min width
52
  if new_width < min_dimension:
53
  new_width = min_dimension
 
55
  # If height exceeds max, clamp it
56
  if new_height > max_dimension:
57
  new_height = max_dimension
58
+
59
  return round_to(new_width, compatible_round), round_to(new_height, compatible_round)
60
 
61
 
 
64
  video_path,
65
  prompt,
66
  negative_prompt="",
67
+ enhance_prompt=True,
68
  num_frames=81,
69
  auto_resize=True,
70
  manual_height=480,
 
75
  # Load and preprocess video
76
  progress(0.2, desc="Loading video...")
77
 
78
+ if(enhance_prompt):
79
+ #add here the prompt enhancement API call
80
+ pass
81
+
82
  # Get video dimensions
83
  temp_video = load_video(video_path)
84
  print(len(temp_video))
85
  if temp_video and len(temp_video) > 0:
86
  original_width, original_height = temp_video[0].size
87
+
88
  # Calculate dimensions
89
  if auto_resize:
90
  width, height = calculate_resolution(original_width, original_height)
 
92
  width, height = manual_width, manual_height
93
  else:
94
  raise gr.Error("Could not load video or video is empty")
95
+
96
  # Convert video function
97
  def convert_video(video: List[Image.Image]) -> List[Image.Image]:
98
  # Ensure we don't exceed the video length
 
101
  # Resize frames
102
  video_frames = [frame.resize((width, height)) for frame in video_frames]
103
  return video_frames
104
+
105
  # Load video from file path
106
  video = load_video(video_path, convert_method=convert_video)
107
+
108
  # Ensure we have the right number of frames
109
  if len(video) < num_frames:
110
  num_frames = len(video)
111
+
112
  # Generate edited video
113
  progress(0.5, desc="Generating edited video...")
114
  output = pipe(
 
120
  num_frames=num_frames,
121
  guidance_scale=guidance_scale,
122
  ).frames[0]
123
+
124
  # Export to temporary file
125
  progress(0.9, desc="Exporting video...")
126
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
127
  output_path = tmp_file.name
128
+
129
  export_to_video(output, output_path, fps=24)
130
+
131
  progress(1.0, desc="Complete!")
132
  return output_path
133
 
 
146
  &nbsp;|&nbsp; 📑 <a href="#">arXiv (Coming soon)</a>
147
  &nbsp;|&nbsp; 💬 <a href="https://discord.gg/decart">Discord</a>
148
  </p>""")
149
+
150
  with gr.Row():
151
  with gr.Column(scale=1):
152
  # Input controls
153
  video_input = gr.Video(label="Input Video")
154
+
155
  prompt = gr.Textbox(
156
  label="Edit Prompt",
157
  placeholder="Describe what you want to change in the video...",
158
  lines=3
159
  )
160
+
161
  with gr.Accordion("Advanced Settings", open=False):
162
+ enhance_prompt = gr.Checkbox(label="Enhance Prompt", value=True)
163
+
164
  negative_prompt = gr.Textbox(
165
  label="Negative Prompt (optional)",
166
  placeholder="Describe what you DON'T want in the video...",
 
171
  value=True,
172
  info="Automatically calculate dimensions based on input video"
173
  )
174
+
175
  num_frames = gr.Slider(
176
  label="Number of Frames",
177
  minimum=1,
 
180
  step=1,
181
  info="More frames = longer processing time"
182
  )
183
+
184
  with gr.Row():
185
  manual_height = gr.Slider(
186
  label="Height (when auto-resize is off)",
 
196
  value=832,
197
  step=32
198
  )
199
+
200
  guidance_scale = gr.Slider(
201
  label="Guidance Scale",
202
  minimum=1.0,
 
205
  step=0.5,
206
  info="Higher values follow the prompt more strictly"
207
  )
208
+
209
  generate_btn = gr.Button("Edit Video", variant="primary")
210
+
211
  with gr.Column(scale=1):
212
+ video_output = gr.Video(label="Edited Video")
213
 
214
  gr.Examples(
215
  examples=[
216
+ ["examples/man_walking.mp4", "make the man into an alien"],
217
+ ["examples/leopard.mp4", "make the leopard into a lion"],
218
+ ["examples/woman.mp4", "make the woman's coat blue"],
219
  ],
220
  inputs=[video_input, prompt],
221
  outputs=video_output,
222
  fn=process_video,
223
  cache_examples="lazy",
224
  )
225
+
226
  # Event handlers
227
  generate_btn.click(
228
  fn=process_video,
 
230
  video_input,
231
  prompt,
232
  negative_prompt,
233
+ enhance_prompt,
234
  num_frames,
235
  auto_resize,
236
  manual_height,
 
241
  )
242
 
243
  if __name__ == "__main__":
244
+ demo.launch(share=True)
examples/neon.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:e62dc89173956d4d22defac1d24f0835c8d8d0490f7969dd13b38429d69165ca
3
- size 3182890
 
 
 
 
examples/painter.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:37b385068db4c25d8f29104580b3267a4fafc2afbd4235f57a206a587a16e56f
3
- size 2941421