multimodalart's picture
multimodalart HF Staff
Link the usage gist in the demo description
fc52929 verified
|
Raw
History Blame Contribute Delete
2.37 kB
---
title: Krea 2 Image Reference
emoji: 🎨
colorFrom: indigo
colorTo: blue
sdk: gradio
sdk_version: 6.15.1
app_file: app.py
short_description: Training-free style transfer for Krea 2 (RoPE)
python_version: "3.12"
startup_duration_timeout: 1h
---
# Krea 2 Image Reference
Training-free **style transfer** for [Krea 2](https://huggingface.co/krea/Krea-2-Turbo),
porting [Untwisting RoPE: Frequency Control for Shared Attention in DiTs](https://arxiv.org/abs/2602.05013)
(originally a [ComfyUI node](https://github.com/BigStationW/ComfyUi-Untwisting-RoPE)) to 🧨 diffusers.
Give a **reference image** (the style) and a **prompt** (the content). At every
denoising step the transformer runs on a `[target, reference]` cross-batch;
inside each attention block, after rotary position embedding, the reference
image's keys are rescaled per frequency band (`high_scale` for fine structure,
`low_scale` for global style) and the target attends to those rescaled
reference keys/values. Optional AdaIN aligns color/contrast statistics.
No training, no LoRA. Runs eager (the attention-processor swap is incompatible
with AOTI-compiled blocks).
`krea2_untwist.py` is a standalone module — import `style_transfer` to use it
with any `Krea2Pipeline`.
## Use it in code
`krea2_untwist.py` works with plain diffusers. Full snippet + module in this
**[gist](https://gist.github.com/apolinario/9ecc9e0efffbbf133fe997b7181b6cfa)**
(the module is also here in the Space:
[raw](https://huggingface.co/spaces/multimodalart/Krea-2-Image-Reference/raw/main/krea2_untwist.py)).
```bash
pip install "transformers>=4.57.0" accelerate sentencepiece \
git+https://github.com/huggingface/diffusers.git
```
```python
import torch
from diffusers import Krea2Pipeline
from diffusers.utils import load_image
from krea2_untwist import style_transfer
pipe = Krea2Pipeline.from_pretrained("krea/Krea-2-Turbo", torch_dtype=torch.bfloat16).to("cuda")
image = style_transfer(
pipe,
prompt="a red fox sitting in a snowy forest, soft winter light",
reference_image=load_image("your_style_reference.png"),
num_inference_steps=8,
beta=2.25,
low_scale_start=1.0, low_scale_end=2.75, # style strength
high_scale_start=1.0, high_scale_end=0.0, # structure decays -> prompt keeps composition
adain_strength=0.75,
blocks=(7, 27),
)
image.save("out.png")
```