sayakpaul HF Staff commited on
Commit
b0dfa4c
·
verified ·
1 Parent(s): 1a0cfc6

Upload example.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. example.py +38 -0
example.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Mimicked from https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py
3
+ """
4
+
5
+ from diffusers.modular_pipelines import ModularPipelineBlocks, WanModularPipeline
6
+ from diffusers.utils import load_image
7
+ from diffusers import UniPCMultistepScheduler
8
+ from modular_blocks import ChronoEditBlocks
9
+ import torch
10
+ from PIL import Image
11
+
12
+ repo_id = "nvidia/ChronoEdit-14B-Diffusers"
13
+ blocks = ChronoEditBlocks()
14
+ pipe = WanModularPipeline(blocks, repo_id)
15
+
16
+ pipe.load_components(
17
+ trust_remote_code=True,
18
+ device_map="cuda",
19
+ torch_dtype={"default": torch.bfloat16, "image_encoder": torch.float32},
20
+ )
21
+ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0)
22
+ pipe.load_lora_weights(repo_id, weight_name="lora/chronoedit_distill_lora.safetensors")
23
+ pipe.fuse_lora(lora_scale=1.0)
24
+
25
+ image = load_image("https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png")
26
+ prompt = "Transform the image so that inside the floral teacup of steaming tea, a small, cute mouse is sitting and taking a bath; the mouse should look relaxed and cheerful, with a tiny white bath towel draped over its head as if enjoying a spa moment, while the steam rises gently around it, blending seamlessly with the warm and cozy atmosphere."
27
+
28
+ # image is resized within the pipeline unlike https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py#L151
29
+ # refer to `ChronoEditImageInputStep`.
30
+ out = pipe(
31
+ image=image,
32
+ prompt=prompt, # todo: enhance prompt
33
+ num_inference_steps=8, # todo: implement temporal reasoning
34
+ num_frames=5, # https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py#L152
35
+ output_type="np",
36
+ )
37
+ frames = out.values["videos"][0]
38
+ Image.fromarray((frames[-1] * 255).clip(0, 255).astype("uint8")).save("demo.png")