Spaces:
Runtime error
Runtime error
update app.py (#1)
Browse files- update app.py (6c3cf444d1d2ffe06f3dd1d8c90d4983b317df90)
app.py
CHANGED
|
@@ -73,6 +73,93 @@ DEFAULTS = {
|
|
| 73 |
"Turbo": {"steps": 8, "guidance": 0.0},
|
| 74 |
}
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
def _duration(prompt, negative_prompt, model, steps, guidance, width, height, seed, randomize, progress=None):
|
| 78 |
return int(steps) * 2 + 25
|
|
@@ -91,6 +178,8 @@ def generate(
|
|
| 91 |
randomize,
|
| 92 |
progress=gr.Progress(track_tqdm=True),
|
| 93 |
):
|
|
|
|
|
|
|
| 94 |
if randomize:
|
| 95 |
seed = random.randint(0, MAX_SEED)
|
| 96 |
seed = int(seed)
|
|
@@ -117,29 +206,171 @@ def on_model_change(model):
|
|
| 117 |
)
|
| 118 |
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 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|
|
|
|
| 141 |
inputs = [prompt, negative_prompt, model, steps, guidance, width, height, seed, randomize]
|
| 142 |
run.click(generate, inputs, [output, seed])
|
| 143 |
prompt.submit(generate, inputs, [output, seed])
|
| 144 |
|
| 145 |
-
demo.launch()
|
|
|
|
| 73 |
"Turbo": {"steps": 8, "guidance": 0.0},
|
| 74 |
}
|
| 75 |
|
| 76 |
+
# Resolution presets. The prompt guide notes Turbo renders up to 2K and every
|
| 77 |
+
# official sample is generated at 2K, so the presets default users toward it.
|
| 78 |
+
RESOLUTIONS = {
|
| 79 |
+
"Square 路 1024": (1024, 1024),
|
| 80 |
+
"Square 路 2K": (2048, 2048),
|
| 81 |
+
"Portrait 路 2K": (1536, 2048),
|
| 82 |
+
"Landscape 路 2K": (2048, 1536),
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
PROMPT_TIPS = """\
|
| 86 |
+
Krea 2 is tuned for natural language. Describe the image the way you would describe it to a person.
|
| 87 |
+
|
| 88 |
+
- Write in full sentences or rich phrases. Longer, more specific prompts give the best results, but short prompts work too.
|
| 89 |
+
- Name the things that matter: subject, setting, lighting, color, framing, medium, and mood.
|
| 90 |
+
- To render text in the image, wrap the words in quotes, for example: a storefront window with a neon sign that reads "open late".
|
| 91 |
+
- Turbo renders up to 2K. The example prompts below are all 2K.
|
| 92 |
+
|
| 93 |
+
Want help writing longer prompts? An `expansion.txt` system prompt is provided in the [model repo](https://huggingface.co/krea/Krea-2-Turbo) for use with any LLM.
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
# Drawn from the official Krea 2 prompt guide. These demonstrate the
|
| 97 |
+
# detailed, natural-language style the model rewards.
|
| 98 |
+
EXAMPLE_PROMPTS = [
|
| 99 |
+
["immense rocket launch exhaust as seen from extremely close up"],
|
| 100 |
+
[
|
| 101 |
+
"3D rendered matte black designer toy figure, stylized round anthropomorphic shape, "
|
| 102 |
+
"backward black baseball cap, oversized gold-rimmed aviator sunglasses, white traditional "
|
| 103 |
+
"line-art tattoos of tiger and bird on torso, black studded belt with gold buckle, smooth "
|
| 104 |
+
"vinyl texture, studio lighting, solid vibrant blue background, high contrast minimal composition"
|
| 105 |
+
],
|
| 106 |
+
[
|
| 107 |
+
"A tiny, russet-brown harvest mouse clings to a slender diagonal branch amid vibrant green "
|
| 108 |
+
"lobed leaves and small round buds. The mouse has soft textured fur, glossy black eyes, a pink "
|
| 109 |
+
"nose, fine whiskers, and delicate pink paws firmly gripping the wood. In this macro photograph, "
|
| 110 |
+
"an extremely shallow depth of field sharply focuses on the animal's face. The deep green "
|
| 111 |
+
"background dissolves into a smooth, creamy bokeh, illuminated by soft, diffused natural lighting "
|
| 112 |
+
"that highlights the intricate details of the fur and foliage."
|
| 113 |
+
],
|
| 114 |
+
[
|
| 115 |
+
"high-fashion editorial portrait of a young East Asian woman, short choppy platinum blonde bob "
|
| 116 |
+
"with heavy bangs, looking over her bare shoulder to the right, lips playfully pursed, wearing a "
|
| 117 |
+
"structured black top with an architectural protruding bust detail and thin straps, delicate gold "
|
| 118 |
+
"hoop earrings, arm bent with hand resting on hip, warm skin tones, solid striking crimson red "
|
| 119 |
+
"background, soft directional studio lighting, cinematic color palette, medium close-up shot"
|
| 120 |
+
],
|
| 121 |
+
[
|
| 122 |
+
"A minimalist flat-color illustration of a person wading through expansive shallow ocean waves "
|
| 123 |
+
"beneath a pale peach sky. The dark-skinned figure, wearing an orange swim cap, light blue top, and "
|
| 124 |
+
"bright green shorts, steps carefully through knee-deep water. The ocean is rendered in muted mint "
|
| 125 |
+
"green with delicate, thin black linework detailing the continuous ripples and gentle whitecaps. "
|
| 126 |
+
"Soft pinkish-peach reflections echo the sky on the water's surface. The high-angle wide perspective "
|
| 127 |
+
"emphasizes the vast negative space of the water, utilizing a clean ligne claire drawing aesthetic "
|
| 128 |
+
"with a subtle paper texture."
|
| 129 |
+
],
|
| 130 |
+
[
|
| 131 |
+
"A surreal retro-futuristic space scene features liquid chrome forming an abstract face merging "
|
| 132 |
+
"with a glowing planetary horizon. The foreground is dominated by swirling, highly reflective "
|
| 133 |
+
"metallic fluid that distorts into a stylized, melting facial profile with deep shadows and bright "
|
| 134 |
+
"silver highlights. This undulating chrome form rests against the curved, atmospheric edge of a "
|
| 135 |
+
"massive planet bathed in a soft electric blue and purple glow. Set against a deep black starfield, "
|
| 136 |
+
"the artwork employs a vintage 1980s airbrush aesthetic with smooth gradients, ethereal lighting, "
|
| 137 |
+
"and high-contrast metallic rendering."
|
| 138 |
+
],
|
| 139 |
+
[
|
| 140 |
+
"Stylized digital painting of a menacing jester figure rendered with bold, expressive brushstrokes "
|
| 141 |
+
"and a vibrant, almost psychedelic color palette against a pitch-black background. Dynamic low-angle "
|
| 142 |
+
"perspective forces a dramatic, imposing composition as the character leans forward, one leg raised "
|
| 143 |
+
"high. The jester wears a classic multi-pointed hat with bells, a ruffled collar, and striped tights "
|
| 144 |
+
"in alternating shades of purple, blue, and chartreuse. The figure's face is a smooth, faceless, pale "
|
| 145 |
+
"mauve mask with a single glowing white point of light at the center, and it grips a massive ornate "
|
| 146 |
+
"sword with a glowing ethereal white blade. Theatrical lighting, dark fantasy concept-art aesthetic."
|
| 147 |
+
],
|
| 148 |
+
[
|
| 149 |
+
"A close-up portrait of a young East Asian woman with straight black hair, loose strands sweeping "
|
| 150 |
+
"across her fair skin, and an intense gaze. She wears a light grey collared shirt with a black tie. "
|
| 151 |
+
"A vibrant bouquet of pink and orange lilies with lush green leaves sits in the blurred right "
|
| 152 |
+
"foreground. The background is a solid, striking crimson red. Soft, directional studio lighting "
|
| 153 |
+
"highlights her facial features, creating a high-contrast composition with a shallow depth of field."
|
| 154 |
+
],
|
| 155 |
+
]
|
| 156 |
+
|
| 157 |
+
PLACEHOLDER = (
|
| 158 |
+
"Describe your image in natural language. e.g. a russet harvest mouse clinging to a "
|
| 159 |
+
'branch, macro photograph, shallow depth of field, creamy green bokeh, soft natural light. '
|
| 160 |
+
'Wrap words in "quotes" to render them as text.'
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
|
| 164 |
def _duration(prompt, negative_prompt, model, steps, guidance, width, height, seed, randomize, progress=None):
|
| 165 |
return int(steps) * 2 + 25
|
|
|
|
| 178 |
randomize,
|
| 179 |
progress=gr.Progress(track_tqdm=True),
|
| 180 |
):
|
| 181 |
+
if not prompt or not prompt.strip():
|
| 182 |
+
raise gr.Error("Enter a prompt to generate an image.")
|
| 183 |
if randomize:
|
| 184 |
seed = random.randint(0, MAX_SEED)
|
| 185 |
seed = int(seed)
|
|
|
|
| 206 |
)
|
| 207 |
|
| 208 |
|
| 209 |
+
def on_resolution_change(label):
|
| 210 |
+
w, h = RESOLUTIONS[label]
|
| 211 |
+
return gr.update(value=w), gr.update(value=h)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
# Krea brand identity: neutral grayscale foundation with a single blue action
|
| 215 |
+
# accent (krea.ai/press). Dark surfaces, mono utility type, accent reserved for
|
| 216 |
+
# the primary action and focus states.
|
| 217 |
+
KREA_ACCENT = "#2b5cff"
|
| 218 |
+
|
| 219 |
+
theme = gr.themes.Base(
|
| 220 |
+
primary_hue=gr.themes.colors.blue,
|
| 221 |
+
neutral_hue=gr.themes.colors.neutral,
|
| 222 |
+
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
|
| 223 |
+
font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"],
|
| 224 |
+
).set(
|
| 225 |
+
body_background_fill="#000000",
|
| 226 |
+
body_background_fill_dark="#000000",
|
| 227 |
+
body_text_color="#f5f5f5",
|
| 228 |
+
background_fill_primary="#0d0d0d",
|
| 229 |
+
background_fill_secondary="#0d0d0d",
|
| 230 |
+
block_background_fill="#0d0d0d",
|
| 231 |
+
block_border_color="#262626",
|
| 232 |
+
block_border_width="1px",
|
| 233 |
+
block_label_background_fill="#0d0d0d",
|
| 234 |
+
block_label_text_color="#737373",
|
| 235 |
+
block_title_text_color="#d4d4d5",
|
| 236 |
+
border_color_primary="#262626",
|
| 237 |
+
input_background_fill="#000000",
|
| 238 |
+
input_border_color="#262626",
|
| 239 |
+
input_border_color_focus=KREA_ACCENT,
|
| 240 |
+
button_primary_background_fill=KREA_ACCENT,
|
| 241 |
+
button_primary_background_fill_hover="#1f4fff",
|
| 242 |
+
button_primary_text_color="#ffffff",
|
| 243 |
+
button_primary_border_color=KREA_ACCENT,
|
| 244 |
+
button_secondary_background_fill="#171717",
|
| 245 |
+
button_secondary_background_fill_hover="#262626",
|
| 246 |
+
button_secondary_text_color="#f5f5f5",
|
| 247 |
+
button_secondary_border_color="#262626",
|
| 248 |
+
slider_color=KREA_ACCENT,
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
CSS = """
|
| 252 |
+
.gradio-container { background: #000 !important; }
|
| 253 |
+
#page { max-width: 1120px; margin: 0 auto; padding: 4px 8px 32px; }
|
| 254 |
+
|
| 255 |
+
#krea-header {
|
| 256 |
+
padding: 32px 6px 22px;
|
| 257 |
+
border-bottom: 1px solid #1a1a1a;
|
| 258 |
+
margin-bottom: 22px;
|
| 259 |
+
}
|
| 260 |
+
#krea-header .eyebrow {
|
| 261 |
+
font-family: 'JetBrains Mono', ui-monospace, monospace;
|
| 262 |
+
font-size: 11px;
|
| 263 |
+
letter-spacing: 0.24em;
|
| 264 |
+
text-transform: uppercase;
|
| 265 |
+
color: #737373;
|
| 266 |
+
}
|
| 267 |
+
#krea-header h1 {
|
| 268 |
+
font-size: 42px;
|
| 269 |
+
font-weight: 600;
|
| 270 |
+
letter-spacing: -0.025em;
|
| 271 |
+
line-height: 1.05;
|
| 272 |
+
margin: 10px 0 6px;
|
| 273 |
+
color: #fff;
|
| 274 |
+
}
|
| 275 |
+
#krea-header .subtitle {
|
| 276 |
+
font-size: 15px;
|
| 277 |
+
line-height: 1.5;
|
| 278 |
+
color: #a3a3a3;
|
| 279 |
+
margin: 0;
|
| 280 |
+
max-width: 60ch;
|
| 281 |
+
}
|
| 282 |
+
#krea-header .badges { margin-top: 14px; display: flex; gap: 8px; }
|
| 283 |
+
#krea-header .badge {
|
| 284 |
+
font-family: 'JetBrains Mono', ui-monospace, monospace;
|
| 285 |
+
font-size: 10px;
|
| 286 |
+
letter-spacing: 0.12em;
|
| 287 |
+
text-transform: uppercase;
|
| 288 |
+
color: #d4d4d5;
|
| 289 |
+
border: 1px solid #262626;
|
| 290 |
+
border-radius: 999px;
|
| 291 |
+
padding: 4px 10px;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/* Mono utility type for control labels keeps the technical, tool-like register. */
|
| 295 |
+
.panel .block .gr-form label span,
|
| 296 |
+
.panel span[data-testid="block-info"] { letter-spacing: 0.01em; }
|
| 297 |
+
|
| 298 |
+
#generate-btn { font-weight: 600; letter-spacing: 0.01em; }
|
| 299 |
+
|
| 300 |
+
#result-image { min-height: 420px; border-radius: 10px; overflow: hidden; }
|
| 301 |
+
|
| 302 |
+
footer { display: none !important; }
|
| 303 |
+
.gradio-container .prose a { color: """ + KREA_ACCENT + """; }
|
| 304 |
+
"""
|
| 305 |
+
|
| 306 |
+
with gr.Blocks(theme=theme, css=CSS, title="Krea 2", fill_height=True) as demo:
|
| 307 |
+
with gr.Column(elem_id="page"):
|
| 308 |
+
gr.HTML(
|
| 309 |
+
"""
|
| 310 |
+
<header id="krea-header">
|
| 311 |
+
<div class="eyebrow">KREA 路 TEXT-TO-IMAGE</div>
|
| 312 |
+
<h1>Krea 2</h1>
|
| 313 |
+
<p class="subtitle">Generate images from natural language. Pick Raw for CFG-guided control or Turbo for fast, few-step results up to 2K.</p>
|
| 314 |
+
<div class="badges">
|
| 315 |
+
<span class="badge">Raw 路 CFG</span>
|
| 316 |
+
<span class="badge">Turbo 路 few-step</span>
|
| 317 |
+
</div>
|
| 318 |
+
</header>
|
| 319 |
+
"""
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
with gr.Row(equal_height=False):
|
| 323 |
+
with gr.Column(scale=5, elem_classes="panel"):
|
| 324 |
+
prompt = gr.Textbox(
|
| 325 |
+
label="Prompt",
|
| 326 |
+
lines=4,
|
| 327 |
+
placeholder=PLACEHOLDER,
|
| 328 |
+
show_label=True,
|
| 329 |
+
autofocus=True,
|
| 330 |
+
)
|
| 331 |
+
model = gr.Radio(["Turbo", "Raw"], value="Turbo", label="Model")
|
| 332 |
+
run = gr.Button("Generate", variant="primary", elem_id="generate-btn")
|
| 333 |
+
|
| 334 |
+
with gr.Accordion("Prompting tips", open=False):
|
| 335 |
+
gr.Markdown(PROMPT_TIPS)
|
| 336 |
+
|
| 337 |
+
resolution = gr.Radio(
|
| 338 |
+
list(RESOLUTIONS.keys()),
|
| 339 |
+
value="Square 路 2K",
|
| 340 |
+
label="Resolution",
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
with gr.Accordion("Advanced", open=False):
|
| 344 |
+
negative_prompt = gr.Textbox(
|
| 345 |
+
label="Negative prompt",
|
| 346 |
+
lines=1,
|
| 347 |
+
interactive=False,
|
| 348 |
+
info="Available with Raw, where guidance is above 0.",
|
| 349 |
+
)
|
| 350 |
+
steps = gr.Slider(1, 50, value=8, step=1, label="Steps")
|
| 351 |
+
guidance = gr.Slider(0.0, 10.0, value=0.0, step=0.1, label="Guidance scale")
|
| 352 |
+
with gr.Row():
|
| 353 |
+
width = gr.Slider(512, 2048, value=2048, step=16, label="Width")
|
| 354 |
+
height = gr.Slider(512, 2048, value=2048, step=16, label="Height")
|
| 355 |
+
with gr.Row():
|
| 356 |
+
seed = gr.Slider(0, MAX_SEED, value=0, step=1, label="Seed")
|
| 357 |
+
randomize = gr.Checkbox(value=True, label="Randomize seed")
|
| 358 |
+
|
| 359 |
+
with gr.Column(scale=6, elem_classes="panel"):
|
| 360 |
+
output = gr.Image(label="Result", format="png", elem_id="result-image")
|
| 361 |
+
|
| 362 |
+
gr.Examples(
|
| 363 |
+
examples=EXAMPLE_PROMPTS,
|
| 364 |
+
inputs=[prompt],
|
| 365 |
+
label="Example prompts",
|
| 366 |
+
examples_per_page=4,
|
| 367 |
+
)
|
| 368 |
|
| 369 |
model.change(on_model_change, model, [steps, guidance, negative_prompt])
|
| 370 |
+
resolution.change(on_resolution_change, resolution, [width, height])
|
| 371 |
+
|
| 372 |
inputs = [prompt, negative_prompt, model, steps, guidance, width, height, seed, randomize]
|
| 373 |
run.click(generate, inputs, [output, seed])
|
| 374 |
prompt.submit(generate, inputs, [output, seed])
|
| 375 |
|
| 376 |
+
demo.launch()
|