goryhon commited on
Commit
f003ca6
·
verified ·
1 Parent(s): ec02c31

Update web-demos/hugging_face/app.py

Browse files
Files changed (1) hide show
  1. web-demos/hugging_face/app.py +24 -14
web-demos/hugging_face/app.py CHANGED
@@ -316,7 +316,7 @@ def inpaint_video(video_state, *_args):
316
  inpaint_masks[inpaint_masks == i] = 0
317
 
318
  chunk_size = 30
319
- save_size = 20
320
  step = save_size
321
  fixed_resize_ratio = 1.0
322
  fixed_dilate_radius = 8
@@ -326,20 +326,15 @@ def inpaint_video(video_state, *_args):
326
 
327
  total_len = len(frames)
328
  inpainted_all = []
329
- last_chunk_result = None
330
 
331
  for start in range(0, total_len, step):
332
  end = min(start + chunk_size, total_len)
333
  chunk_frames = frames[start:end]
334
  chunk_masks = inpaint_masks[start:end]
335
 
336
- if end - start < 2 and last_chunk_result is not None:
337
- print(f"Skipping tiny chunk {start}:{end}, copying from previous.")
338
- remaining = end - start
339
- inpainted_all.extend(last_chunk_result[-remaining:])
340
- continue
341
-
342
  print(f"Inpainting chunk {start}:{end}")
 
343
  chunk_result = model.baseinpainter.inpaint(
344
  chunk_frames,
345
  chunk_masks,
@@ -351,15 +346,29 @@ def inpaint_video(video_state, *_args):
351
  ref_stride=fixed_ref_stride
352
  )
353
 
 
 
 
354
  if start == 0:
355
- chunk_to_save = chunk_result[:save_size]
356
  elif end == total_len:
357
- chunk_to_save = chunk_result[(chunk_size - (end - start)):]
358
  else:
359
- chunk_to_save = chunk_result[:save_size]
360
-
361
- inpainted_all.extend(chunk_to_save)
362
- last_chunk_result = chunk_result
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  output_path = "./result/inpaint/{}".format(video_state["video_name"])
365
  video_output = generate_video_from_frames(
@@ -370,6 +379,7 @@ def inpaint_video(video_state, *_args):
370
 
371
  return video_output, operation_log, operation_log
372
 
 
373
  # generate video after vos inference
374
  def generate_video_from_frames(frames, output_path, fps=30, bitrate=None):
375
  """
 
316
  inpaint_masks[inpaint_masks == i] = 0
317
 
318
  chunk_size = 30
319
+ save_size = 22
320
  step = save_size
321
  fixed_resize_ratio = 1.0
322
  fixed_dilate_radius = 8
 
326
 
327
  total_len = len(frames)
328
  inpainted_all = []
329
+ saved_indices = set()
330
 
331
  for start in range(0, total_len, step):
332
  end = min(start + chunk_size, total_len)
333
  chunk_frames = frames[start:end]
334
  chunk_masks = inpaint_masks[start:end]
335
 
 
 
 
 
 
 
336
  print(f"Inpainting chunk {start}:{end}")
337
+
338
  chunk_result = model.baseinpainter.inpaint(
339
  chunk_frames,
340
  chunk_masks,
 
346
  ref_stride=fixed_ref_stride
347
  )
348
 
349
+ chunk_len = end - start
350
+
351
+ # Выбираем уникальные индексы для сохранения
352
  if start == 0:
353
+ to_save = list(range(min(save_size, chunk_len)))
354
  elif end == total_len:
355
+ to_save = list(range(chunk_len - (total_len - start), chunk_len))
356
  else:
357
+ to_save = list(range(min(save_size, chunk_len)))
358
+
359
+ for i in to_save:
360
+ absolute_index = start + i
361
+ if absolute_index not in saved_indices:
362
+ inpainted_all.append(chunk_result[i])
363
+ saved_indices.add(absolute_index)
364
+
365
+ # 🧠 Убедимся, что длина совпадает
366
+ if len(inpainted_all) < total_len:
367
+ last_frame = inpainted_all[-1]
368
+ for _ in range(total_len - len(inpainted_all)):
369
+ inpainted_all.append(last_frame)
370
+ elif len(inpainted_all) > total_len:
371
+ inpainted_all = inpainted_all[:total_len]
372
 
373
  output_path = "./result/inpaint/{}".format(video_state["video_name"])
374
  video_output = generate_video_from_frames(
 
379
 
380
  return video_output, operation_log, operation_log
381
 
382
+
383
  # generate video after vos inference
384
  def generate_video_from_frames(frames, output_path, fps=30, bitrate=None):
385
  """