Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import (
|
| 3 |
+
DDIMScheduler,
|
| 4 |
+
MotionAdapter,
|
| 5 |
+
PIAPipeline,
|
| 6 |
+
)
|
| 7 |
+
from diffusers.utils import export_to_gif, load_image
|
| 8 |
+
|
| 9 |
+
adapter = MotionAdapter.from_pretrained("openmmlab/PIA-condition-adapter")
|
| 10 |
+
pipe = PIAPipeline.from_pretrained("SG161222/Realistic_Vision_V6.0_B1_noVAE", motion_adapter=adapter)
|
| 11 |
+
|
| 12 |
+
# enable FreeInit
|
| 13 |
+
# Refer to the enable_free_init documentation for a full list of configurable parameters
|
| 14 |
+
pipe.enable_free_init(method="butterworth", use_fast_sampling=True)
|
| 15 |
+
|
| 16 |
+
# Memory saving options
|
| 17 |
+
pipe.enable_model_cpu_offload()
|
| 18 |
+
pipe.enable_vae_slicing()
|
| 19 |
+
|
| 20 |
+
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 21 |
+
image = load_image(
|
| 22 |
+
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/cat_6.png?download=true"
|
| 23 |
+
)
|
| 24 |
+
image = image.resize((512, 512))
|
| 25 |
+
prompt = "cat in a field"
|
| 26 |
+
negative_prompt = "wrong white balance, dark, sketches,worst quality,low quality"
|
| 27 |
+
|
| 28 |
+
generator = torch.Generator("cpu").manual_seed(0)
|
| 29 |
+
|
| 30 |
+
output = pipe(image=image, prompt=prompt, generator=generator)
|
| 31 |
+
frames = output.frames[0]
|
| 32 |
+
export_to_gif(frames, "pia-freeinit-animation.gif")
|