multimodalart HF Staff commited on
Commit
26b5a39
·
verified ·
1 Parent(s): 3d77057

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/style_ref_01.png filter=lfs diff=lfs merge=lfs -text
37
+ examples/style_ref_yeti.png filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,40 @@
1
  ---
2
- title: Krea2 Style Reference
3
- emoji: 🐢
4
- colorFrom: blue
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 6.20.0
8
- python_version: '3.12'
9
  app_file: app.py
10
  pinned: false
 
 
 
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Krea 2 Style Reference
3
+ emoji: 🎨
4
+ colorFrom: indigo
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.20.0
 
8
  app_file: app.py
9
  pinned: false
10
+ hardware: zero-a10g
11
+ short_description: Style-guided image generation with Krea 2 Turbo
12
+ python_version: "3.10"
13
+ startup_duration_timeout: 600
14
+ models:
15
+ - krea/Krea-2-Turbo
16
+ - ostris/krea2_turbo_style_reference
17
  ---
18
 
19
+ # Krea 2 Style Reference
20
+
21
+ Generate an image from a text prompt, guided by a **style reference image**. This Space uses:
22
+
23
+ - **Base model:** [krea/Krea-2-Turbo](https://huggingface.co/krea/Krea-2-Turbo) (8-step distilled Krea 2)
24
+ - **LoRA:** [ostris/krea2_turbo_style_reference](https://huggingface.co/ostris/krea2_turbo_style_reference) (style reference conditioning)
25
+ - **Pipeline:** [ostris/Krea2OstrisEdit](https://huggingface.co/ostris/Krea2OstrisEdit) (custom community pipeline for reference-image conditioning)
26
+
27
+ ## How it works
28
+
29
+ Upload a style reference image and type a prompt describing what you want to generate. The LoRA conditions the Krea 2 Turbo model on both:
30
+ 1. **Text encoder** — the reference image is embedded into the prompt via Qwen3-VL vision placeholders
31
+ 2. **Latent space** — clean VAE latents of the reference are appended to the transformer sequence at flow time t=0
32
+
33
+ This produces an image that follows your prompt while adopting the visual style of the reference image.
34
+
35
+ ## Inference recipe
36
+
37
+ - **Steps:** 8 (Turbo distilled)
38
+ - **Guidance:** 0.0 (disabled, per Krea 2 Turbo convention)
39
+ - **LoRA scale:** 1.0 (adjustable)
40
+ - **Resolution:** 1024×1024 (adjustable, must be multiples of 16)
app.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import torch
3
+ import gradio as gr
4
+ from diffusers import DiffusionPipeline
5
+
6
+ BASE_MODEL = "krea/Krea-2-Turbo"
7
+ LORA_REPO = "ostris/krea2_turbo_style_reference"
8
+ LORA_WEIGHT = "krea2_style_reference.safetensors"
9
+ CUSTOM_PIPELINE = "ostris/Krea2OstrisEdit"
10
+
11
+ DTYPE = torch.bfloat16
12
+ MAX_SEED = 2**31 - 1
13
+
14
+ pipe = DiffusionPipeline.from_pretrained(
15
+ BASE_MODEL,
16
+ custom_pipeline=CUSTOM_PIPELINE,
17
+ torch_dtype=DTYPE,
18
+ )
19
+ pipe.to("cuda")
20
+ pipe.load_lora_weights(LORA_REPO, weight_name=LORA_WEIGHT)
21
+
22
+
23
+ @spaces.GPU(duration=90, size="large")
24
+ def generate(
25
+ prompt,
26
+ style_ref_image,
27
+ lora_scale,
28
+ steps,
29
+ guidance,
30
+ width,
31
+ height,
32
+ seed,
33
+ randomize_seed,
34
+ progress=gr.Progress(track_tqdm=True),
35
+ ):
36
+ if not prompt or not prompt.strip():
37
+ raise gr.Error("Please enter a prompt.")
38
+ if style_ref_image is None:
39
+ raise gr.Error("Please upload a style reference image.")
40
+
41
+ if randomize_seed:
42
+ seed = torch.randint(0, MAX_SEED, (1,)).item()
43
+ seed = int(seed)
44
+
45
+ # Snap dimensions to multiples of 16 (vae_scale_factor * patch_size = 16)
46
+ multiple = 16
47
+ width = ((width + multiple - 1) // multiple) * multiple
48
+ height = ((height + multiple - 1) // multiple) * multiple
49
+
50
+ generator = torch.Generator("cuda").manual_seed(seed)
51
+
52
+ image = pipe(
53
+ prompt=prompt,
54
+ image=style_ref_image,
55
+ num_inference_steps=int(steps),
56
+ guidance_scale=float(guidance),
57
+ width=width,
58
+ height=height,
59
+ generator=generator,
60
+ attention_kwargs={"scale": float(lora_scale)},
61
+ ).images[0]
62
+
63
+ return image, seed
64
+
65
+
66
+ CSS = """
67
+ #page { max-width: 1100px; margin: 0 auto; padding: 4px 8px 32px; }
68
+ #header { padding: 24px 4px 18px; border-bottom: 1px solid #e5e5e5; margin-bottom: 20px; }
69
+ #header h1 { font-size: 32px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.02em; }
70
+ #header .subtitle { font-size: 15px; color: #666; margin: 0; max-width: 70ch; line-height: 1.5; }
71
+ #header .links { margin-top: 12px; display: flex; gap: 16px; }
72
+ #header .links a {
73
+ font-size: 13px; color: #888; text-decoration: none;
74
+ border: 1px solid #ddd; border-radius: 6px; padding: 4px 10px;
75
+ }
76
+ #header .links a:hover { color: #333; border-color: #aaa; }
77
+ footer { display: none !important; }
78
+ """
79
+
80
+ HEADER = """
81
+ <div id="header">
82
+ <h1>Krea 2 Style Reference</h1>
83
+ <p class="subtitle">
84
+ Generate an image from a text prompt, guided by a style reference image.
85
+ Powered by Krea&nbsp;2&nbsp;Turbo with the
86
+ <a href="https://huggingface.co/ostris/krea2_turbo_style_reference" target="_blank">Krea2 Style Reference LoRA</a>
87
+ and the
88
+ <a href="https://huggingface.co/ostris/Krea2OstrisEdit" target="_blank">Krea2OstrisEdit community pipeline</a>.
89
+ </p>
90
+ <div class="links">
91
+ <a href="https://huggingface.co/krea/Krea-2-Turbo" target="_blank">Base model ↗</a>
92
+ <a href="https://huggingface.co/ostris/krea2_turbo_style_reference" target="_blank">LoRA ↗</a>
93
+ <a href="https://github.com/ostris/ComfyUI-Krea2-Ostris-Edit" target="_blank">ComfyUI nodes ↗</a>
94
+ </div>
95
+ </div>
96
+ """
97
+
98
+ with gr.Blocks(title="Krea 2 Style Reference") as demo:
99
+ with gr.Column(elem_id="page"):
100
+ gr.HTML(HEADER)
101
+ with gr.Row(equal_height=False):
102
+ with gr.Column(scale=1):
103
+ prompt = gr.Textbox(
104
+ label="Prompt",
105
+ lines=3,
106
+ placeholder="Describe what you want to generate, e.g. 'a white yeti with horns reading a book'",
107
+ )
108
+ style_ref = gr.Image(
109
+ label="Style Reference Image",
110
+ type="pil",
111
+ height=300,
112
+ )
113
+ generate_btn = gr.Button("Generate", variant="primary", size="lg")
114
+ with gr.Accordion("Advanced", open=False):
115
+ lora_scale = gr.Slider(
116
+ 0.0, 2.0, value=1.0, step=0.01,
117
+ label="LoRA scale",
118
+ info="Strength of the style reference influence",
119
+ )
120
+ steps = gr.Slider(1, 30, value=8, step=1, label="Steps")
121
+ guidance = gr.Slider(
122
+ 0.0, 10.0, value=0.0, step=0.1,
123
+ label="Guidance scale",
124
+ info="Krea 2 Turbo uses 0.0 (guidance disabled)",
125
+ )
126
+ with gr.Row():
127
+ width = gr.Slider(512, 1536, value=1024, step=16, label="Width")
128
+ height = gr.Slider(512, 1536, value=1024, step=16, label="Height")
129
+ with gr.Row():
130
+ seed = gr.Slider(0, MAX_SEED, value=0, step=1, label="Seed")
131
+ randomize_seed = gr.Checkbox(value=True, label="Randomize seed")
132
+ with gr.Column(scale=1):
133
+ result = gr.Image(label="Result", format="png", height=420)
134
+ used_seed = gr.Number(label="Seed used", visible=True, interactive=False)
135
+
136
+ gr.Examples(
137
+ examples=[
138
+ {
139
+ "prompt": "a white yeti with horns reading a book",
140
+ "style_ref_image": "examples/style_ref_yeti.png",
141
+ },
142
+ {
143
+ "prompt": "a futuristic city skyline at sunset, cyberpunk aesthetic",
144
+ "style_ref_image": "examples/style_ref_01.png",
145
+ },
146
+ ],
147
+ inputs=[prompt, style_ref],
148
+ outputs=[result, used_seed],
149
+ fn=generate,
150
+ cache_examples=True,
151
+ cache_mode="lazy",
152
+ )
153
+
154
+ inputs = [
155
+ prompt, style_ref, lora_scale, steps, guidance,
156
+ width, height, seed, randomize_seed,
157
+ ]
158
+ outputs = [result, used_seed]
159
+ gr.on([generate_btn.click, prompt.submit], generate, inputs, outputs)
160
+
161
+ if __name__ == "__main__":
162
+ demo.launch(theme=gr.themes.Citrus(), css=CSS)
examples/style_ref_01.png ADDED

Git LFS Details

  • SHA256: 282c186296e9b598cf4643f59a898f0901cf92f253544a18eb6f2f6f82e7ed03
  • Pointer size: 132 Bytes
  • Size of remote file: 2.19 MB
examples/style_ref_yeti.png ADDED

Git LFS Details

  • SHA256: dd36b3495e36eb94460f9d6d403ea6b9926244ab3f940074a9a214f92e68fc69
  • Pointer size: 132 Bytes
  • Size of remote file: 2.09 MB
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ diffusers
2
+ transformers
3
+ accelerate
4
+ peft
5
+ safetensors
6
+ torchvision
7
+ sentencepiece