svjack commited on
Commit
8d85f06
·
verified ·
1 Parent(s): cb8cd80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -64,7 +64,7 @@ def create_video_from_frames(frame_files, output_path, duration_seconds, width,
64
 
65
  video.release()
66
 
67
- def process_svg_to_video(input_svg_path, original_width, original_height, video_duration_seconds=10, chunk_size=None):
68
  """Process SVG file and create a video with specified duration using exact row slicing"""
69
  # Read SVG file as a table to maintain exact row slicing logic
70
  df = pd.read_table(input_svg_path, header=None)
@@ -75,10 +75,12 @@ def process_svg_to_video(input_svg_path, original_width, original_height, video_
75
  # Use the original image dimensions
76
  width, height = original_width, original_height
77
 
78
- # Calculate chunk size if not specified
79
  total_rows = len(df_middle)
80
- if chunk_size is None:
81
- chunk_size = max(1, total_rows // 30) # Default to ~30 steps
 
 
82
 
83
  # Create a temporary directory for images
84
  temp_dir = tempfile.mkdtemp()
@@ -113,6 +115,7 @@ def process_svg_to_video(input_svg_path, original_width, original_height, video_
113
  def convert_to_vector_and_video(
114
  image,
115
  video_duration=10,
 
116
  colormode="color",
117
  hierarchical="stacked",
118
  mode="spline",
@@ -158,7 +161,8 @@ def convert_to_vector_and_video(
158
  output_svg_path,
159
  original_width,
160
  original_height,
161
- video_duration_seconds=video_duration
 
162
  )
163
 
164
  # Read the SVG output
@@ -179,6 +183,7 @@ def clear_inputs():
179
  return (
180
  gr.Image(value=None),
181
  gr.Slider(value=10),
 
182
  gr.Radio(value="color"),
183
  gr.Radio(value="stacked"),
184
  gr.Radio(value="spline"),
@@ -243,6 +248,8 @@ with gr.Blocks(css=css) as app:
243
  with gr.Column():
244
  image_input = gr.Image(type="pil", label="Upload Image")
245
  video_duration = gr.Slider(1, 60, value=10, step=1, label="Video Duration (seconds)")
 
 
246
 
247
  with gr.Accordion("Advanced Settings", open=False):
248
  with gr.Accordion("Clustering", open=False):
@@ -300,6 +307,7 @@ with gr.Blocks(css=css) as app:
300
  outputs=[
301
  image_input,
302
  video_duration,
 
303
  colormode,
304
  hierarchical,
305
  mode,
@@ -319,6 +327,7 @@ with gr.Blocks(css=css) as app:
319
  inputs=[
320
  image_input,
321
  video_duration,
 
322
  colormode,
323
  hierarchical,
324
  mode,
 
64
 
65
  video.release()
66
 
67
+ def process_svg_to_video(input_svg_path, original_width, original_height, video_duration_seconds=10, chunk_size=30):
68
  """Process SVG file and create a video with specified duration using exact row slicing"""
69
  # Read SVG file as a table to maintain exact row slicing logic
70
  df = pd.read_table(input_svg_path, header=None)
 
75
  # Use the original image dimensions
76
  width, height = original_width, original_height
77
 
78
+ # If chunk_size is 0, use automatic calculation (total_rows // 30)
79
  total_rows = len(df_middle)
80
+ if chunk_size == 0:
81
+ chunk_size = max(1, total_rows // 30)
82
+ else:
83
+ chunk_size = max(1, min(chunk_size, total_rows)) # Ensure it's within valid range
84
 
85
  # Create a temporary directory for images
86
  temp_dir = tempfile.mkdtemp()
 
115
  def convert_to_vector_and_video(
116
  image,
117
  video_duration=10,
118
+ chunk_size=30,
119
  colormode="color",
120
  hierarchical="stacked",
121
  mode="spline",
 
161
  output_svg_path,
162
  original_width,
163
  original_height,
164
+ video_duration_seconds=video_duration,
165
+ chunk_size=chunk_size
166
  )
167
 
168
  # Read the SVG output
 
183
  return (
184
  gr.Image(value=None),
185
  gr.Slider(value=10),
186
+ gr.Slider(value=30),
187
  gr.Radio(value="color"),
188
  gr.Radio(value="stacked"),
189
  gr.Radio(value="spline"),
 
248
  with gr.Column():
249
  image_input = gr.Image(type="pil", label="Upload Image")
250
  video_duration = gr.Slider(1, 60, value=10, step=1, label="Video Duration (seconds)")
251
+ chunk_size = gr.Slider(0, 1000, value=30, step=1, label="Chunk Size (0=auto)",
252
+ info="Number of SVG path elements to add per frame (0 for automatic calculation)")
253
 
254
  with gr.Accordion("Advanced Settings", open=False):
255
  with gr.Accordion("Clustering", open=False):
 
307
  outputs=[
308
  image_input,
309
  video_duration,
310
+ chunk_size,
311
  colormode,
312
  hierarchical,
313
  mode,
 
327
  inputs=[
328
  image_input,
329
  video_duration,
330
+ chunk_size,
331
  colormode,
332
  hierarchical,
333
  mode,