Spaces:
Paused
Paused
Update web-demos/hugging_face/app.py
Browse files- web-demos/hugging_face/app.py +13 -22
web-demos/hugging_face/app.py
CHANGED
@@ -326,15 +326,20 @@ def inpaint_video(video_state, *_args):
|
|
326 |
|
327 |
total_len = len(frames)
|
328 |
inpainted_all = []
|
329 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
337 |
|
|
|
338 |
chunk_result = model.baseinpainter.inpaint(
|
339 |
chunk_frames,
|
340 |
chunk_masks,
|
@@ -346,29 +351,15 @@ def inpaint_video(video_state, *_args):
|
|
346 |
ref_stride=fixed_ref_stride
|
347 |
)
|
348 |
|
349 |
-
chunk_len = end - start
|
350 |
-
|
351 |
-
# Выбираем уникальные индексы для сохранения
|
352 |
if start == 0:
|
353 |
-
|
354 |
elif end == total_len:
|
355 |
-
|
356 |
else:
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
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(
|
|
|
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 |
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(
|