multimodalart HF Staff commited on
Commit
60d901b
·
verified ·
1 Parent(s): 8970f27

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +18 -5
  2. app.py +161 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,13 +1,26 @@
1
  ---
2
- title: Krea2 Moody Golden Hour
3
- emoji: 📊
4
- colorFrom: pink
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.19.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 Moody Golden Hour Editorial
3
+ emoji: 🌅
4
+ colorFrom: red
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.19.0
 
8
  app_file: app.py
9
  pinned: false
10
+ hardware: zero-a10g
11
+ short_description: Krea-2 Turbo LoRA for moody golden-hour editorial images
12
+ python_version: "3.10"
13
+ models:
14
+ - krea/Krea-2-Turbo
15
+ - ilkerzgi/krea-2-moody-golden-hour-editorial-lora
16
  ---
17
 
18
+ # Krea 2 · Moody Golden Hour Editorial
19
+
20
+ A Gradio demo for the [**Moody Golden Hour Editorial**](https://huggingface.co/ilkerzgi/krea-2-moody-golden-hour-editorial-lora)
21
+ style LoRA, running on [**Krea-2-Turbo**](https://huggingface.co/krea/Krea-2-Turbo).
22
+
23
+ The trigger phrase *"moody golden hour editorial style"* is automatically appended to every
24
+ prompt. Just describe your scene and click Generate.
25
+
26
+ **Recipe:** 8 steps, guidance_scale = 0.0 (Turbo), LoRA scale 1.0 (adjustable up to 1.25).
app.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ import gradio as gr
4
+ import spaces
5
+ import torch
6
+ from diffusers import Krea2Pipeline
7
+
8
+ # ---------------------------------------------------------------------------
9
+ # Constants
10
+ # ---------------------------------------------------------------------------
11
+ BASE_MODEL = "krea/Krea-2-Turbo"
12
+ LORA_REPO = "ilkerzgi/krea-2-moody-golden-hour-editorial-lora"
13
+ LORA_WEIGHT_NAME = "moody-golden-hour-editorial.safetensors"
14
+ TRIGGER_WORD = "moody golden hour editorial style"
15
+ MAX_SEED = 2**31 - 1
16
+
17
+ # Resolution presets — all multiples of 16 (Krea 2 requirement).
18
+ RESOLUTIONS = {
19
+ "Square · 1024×1024": (1024, 1024),
20
+ "Portrait · 832×1216": (832, 1216),
21
+ "Landscape · 1216×832": (1216, 832),
22
+ "Tall · 1024×1280": (1024, 1280),
23
+ }
24
+
25
+ # Example prompts — drawn from the LoRA's own model-card example and
26
+ # extended with subjects that showcase the moody golden-hour editorial style.
27
+ EXAMPLES = [
28
+ "a lighthouse on a rocky cliff",
29
+ "a lone figure walking through a misty forest path",
30
+ "a vintage car parked on a desert highway at dusk",
31
+ "a fashion model leaning against a brick wall in soft warm light",
32
+ ]
33
+
34
+ # ---------------------------------------------------------------------------
35
+ # Model loading — at module scope, on CUDA (ZeroGPU CUDA emulation).
36
+ # Krea 2 LoRAs load via the transformer's adapter API, per the official cards.
37
+ # ---------------------------------------------------------------------------
38
+ pipe = Krea2Pipeline.from_pretrained(BASE_MODEL, torch_dtype=torch.bfloat16)
39
+ pipe.to("cuda")
40
+ pipe.transformer.load_lora_adapter(LORA_REPO, weight_name=LORA_WEIGHT_NAME)
41
+ pipe.transformer.set_adapters("default", weights=1.0)
42
+
43
+
44
+ def _build_prompt(user_prompt: str) -> str:
45
+ """Prepend the trigger phrase so the user doesn't have to."""
46
+ p = user_prompt.strip()
47
+ if not p:
48
+ return p
49
+ if TRIGGER_WORD.lower() in p.lower():
50
+ return p
51
+ return f"{p}. {TRIGGER_WORD}"
52
+
53
+
54
+ @spaces.GPU(duration=60)
55
+ def generate(
56
+ prompt,
57
+ resolution_label,
58
+ lora_scale,
59
+ seed,
60
+ randomize_seed,
61
+ progress=gr.Progress(track_tqdm=True),
62
+ ):
63
+ if not prompt or not prompt.strip():
64
+ raise gr.Error("Enter a prompt to generate an image.")
65
+
66
+ if randomize_seed:
67
+ seed = random.randint(0, MAX_SEED)
68
+ seed = int(seed)
69
+
70
+ width, height = RESOLUTIONS[resolution_label]
71
+
72
+ # Apply the LoRA scale dynamically.
73
+ pipe.transformer.set_adapters("default", weights=float(lora_scale))
74
+
75
+ full_prompt = _build_prompt(prompt)
76
+
77
+ generator = torch.Generator("cuda").manual_seed(seed)
78
+ image = pipe(
79
+ prompt=full_prompt,
80
+ num_inference_steps=8,
81
+ guidance_scale=0.0,
82
+ width=width,
83
+ height=height,
84
+ generator=generator,
85
+ ).images[0]
86
+
87
+ return image, seed
88
+
89
+
90
+ # ---------------------------------------------------------------------------
91
+ # UI
92
+ # ---------------------------------------------------------------------------
93
+ with gr.Blocks(title="Krea 2 · Moody Golden Hour Editorial") as demo:
94
+ gr.Markdown(
95
+ """
96
+ # Krea 2 · Moody Golden Hour Editorial
97
+
98
+ A style LoRA for [**Krea-2-Turbo**](https://huggingface.co/krea/Krea-2-Turbo) by
99
+ [**ilkerzgi**](https://huggingface.co/ilkerzgi). Generates moody, warm, golden-hour
100
+ editorial imagery. The trigger phrase *\"moody golden hour editorial style\"* is
101
+ auto-appended to your prompt.
102
+ """
103
+ )
104
+
105
+ with gr.Row(equal_height=True):
106
+ with gr.Column(scale=5):
107
+ prompt = gr.Textbox(
108
+ label="Prompt",
109
+ lines=3,
110
+ placeholder="Describe your scene… e.g. a lighthouse on a rocky cliff",
111
+ autofocus=True,
112
+ )
113
+ resolution = gr.Radio(
114
+ choices=list(RESOLUTIONS.keys()),
115
+ value="Square · 1024×1024",
116
+ label="Aspect ratio",
117
+ )
118
+ run_button = gr.Button("Generate", variant="primary", size="lg")
119
+
120
+ with gr.Accordion("Advanced", open=False):
121
+ lora_scale = gr.Slider(
122
+ label="LoRA scale (style strength)",
123
+ minimum=0.0,
124
+ maximum=1.5,
125
+ step=0.05,
126
+ value=1.0,
127
+ info="1.0 = default, up to 1.25 for a stronger look.",
128
+ )
129
+ with gr.Row():
130
+ seed = gr.Slider(
131
+ label="Seed",
132
+ minimum=0,
133
+ maximum=MAX_SEED,
134
+ step=1,
135
+ value=0,
136
+ )
137
+ randomize_seed = gr.Checkbox(
138
+ label="Randomize seed", value=True
139
+ )
140
+
141
+ with gr.Column(scale=5):
142
+ result = gr.Image(label="Result", format="png", show_label=False)
143
+
144
+ gr.Examples(
145
+ fn=generate,
146
+ examples=EXAMPLES,
147
+ inputs=[prompt],
148
+ outputs=[result, seed],
149
+ cache_examples=True,
150
+ cache_mode="lazy",
151
+ )
152
+
153
+ gr.on(
154
+ triggers=[run_button.click, prompt.submit],
155
+ fn=generate,
156
+ inputs=[prompt, resolution, lora_scale, seed, randomize_seed],
157
+ outputs=[result, seed],
158
+ )
159
+
160
+ if __name__ == "__main__":
161
+ demo.launch(show_error=True)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ git+https://github.com/huggingface/diffusers.git
2
+ transformers>=4.57.0
3
+ accelerate
4
+ sentencepiece
5
+ torchvision
6
+ safetensors
7
+ peft