multimodalart HF Staff commited on
Commit
cc014f6
·
verified ·
1 Parent(s): cc8fb53

Timing logs; drop reference example

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -8,6 +8,7 @@ import spaces # must be imported before torch / CUDA-touching libs
8
  import random
9
  import re
10
  import tempfile
 
11
  from types import SimpleNamespace
12
 
13
  import einops
@@ -269,6 +270,7 @@ def edit_image(
269
  Returns:
270
  The edited image and the seed that was used.
271
  """
 
272
  if source_image is None:
273
  raise gr.Error("Please upload an image to edit.")
274
  if not instruction or not instruction.strip():
@@ -305,8 +307,10 @@ def edit_image(
305
  )
306
  if task == "ti_i2i":
307
  kwargs["reference_image"] = reference_image.convert("RGB")
 
308
  with torch.no_grad():
309
  out = pipe(**kwargs)
 
310
  return to_pil_first_frame(out.videos), seed
311
 
312
 
@@ -341,6 +345,7 @@ def edit_video(
341
  """
342
  from decord import VideoReader
343
 
 
344
  if not source_video:
345
  raise gr.Error("Please upload a video to edit.")
346
  if not instruction or not instruction.strip():
@@ -392,8 +397,10 @@ def edit_video(
392
  ref_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
393
  reference_image.convert("RGB").save(ref_path)
394
  kwargs["reference_image"] = ref_path
 
395
  with torch.no_grad():
396
  out = pipe(**kwargs)
 
397
 
398
  video = out.videos
399
  if video.ndim == 5:
@@ -466,15 +473,6 @@ with gr.Blocks() as demo:
466
  cache_mode="lazy",
467
  label="Image examples",
468
  )
469
- gr.Examples(
470
- examples=[["examples/dog.jpg", "change the dog to a [V*]", "examples/red_fox.jpg"]],
471
- inputs=[img_src, img_prompt, img_ref],
472
- outputs=[img_out, img_seed],
473
- fn=edit_image,
474
- cache_examples=True,
475
- cache_mode="lazy",
476
- label="Reference-guided example",
477
- )
478
 
479
  # ---------------- Video editing ----------------
480
  with gr.Tab("Video editing"):
 
8
  import random
9
  import re
10
  import tempfile
11
+ import time
12
  from types import SimpleNamespace
13
 
14
  import einops
 
270
  Returns:
271
  The edited image and the seed that was used.
272
  """
273
+ t0 = time.time()
274
  if source_image is None:
275
  raise gr.Error("Please upload an image to edit.")
276
  if not instruction or not instruction.strip():
 
307
  )
308
  if task == "ti_i2i":
309
  kwargs["reference_image"] = reference_image.convert("RGB")
310
+ t1 = time.time()
311
  with torch.no_grad():
312
  out = pipe(**kwargs)
313
+ print(f"[timing] edit_image: prep {t1 - t0:.1f}s, pipe {time.time() - t1:.1f}s")
314
  return to_pil_first_frame(out.videos), seed
315
 
316
 
 
345
  """
346
  from decord import VideoReader
347
 
348
+ t0 = time.time()
349
  if not source_video:
350
  raise gr.Error("Please upload a video to edit.")
351
  if not instruction or not instruction.strip():
 
397
  ref_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
398
  reference_image.convert("RGB").save(ref_path)
399
  kwargs["reference_image"] = ref_path
400
+ t1 = time.time()
401
  with torch.no_grad():
402
  out = pipe(**kwargs)
403
+ print(f"[timing] edit_video: prep {t1 - t0:.1f}s, pipe {time.time() - t1:.1f}s ({num_frames} frames)")
404
 
405
  video = out.videos
406
  if video.ndim == 5:
 
473
  cache_mode="lazy",
474
  label="Image examples",
475
  )
 
 
 
 
 
 
 
 
 
476
 
477
  # ---------------- Video editing ----------------
478
  with gr.Tab("Video editing"):