Update app.py
Browse files
app.py
CHANGED
|
@@ -295,6 +295,70 @@ def _apply_preset(name: str):
|
|
| 295 |
p = PRESETS.get(name, PRESETS["Default"])
|
| 296 |
return p["steps"], p["mu"], p["std"]
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
with gr.Blocks(title=APP_TITLE) as demo:
|
| 300 |
lora_note = (
|
|
|
|
| 295 |
p = PRESETS.get(name, PRESETS["Default"])
|
| 296 |
return p["steps"], p["mu"], p["std"]
|
| 297 |
|
| 298 |
+
DEFAULT_CAPTION = {
|
| 299 |
+
"high_level_description": "A clean poster announcing a small experimental image generation lab.",
|
| 300 |
+
"style_description": {
|
| 301 |
+
"aesthetics": "minimal, precise, modern graphic design, generous whitespace",
|
| 302 |
+
"lighting": "even soft studio lighting",
|
| 303 |
+
"medium": "graphic_design",
|
| 304 |
+
"art_style": "flat vector poster, crisp sans-serif typography",
|
| 305 |
+
"color_palette": ["#F9FAFB", "#111827", "#2563EB", "#F97316"],
|
| 306 |
+
},
|
| 307 |
+
"compositional_deconstruction": {
|
| 308 |
+
"background": "A warm off-white poster background with a subtle paper texture.",
|
| 309 |
+
"elements": [
|
| 310 |
+
{
|
| 311 |
+
"type": "text",
|
| 312 |
+
"bbox": [250, 130, 430, 870],
|
| 313 |
+
"text": "IDEOGRAM 4",
|
| 314 |
+
"desc": "Large bold black uppercase title text centered near the upper half.",
|
| 315 |
+
"color_palette": ["#111827"],
|
| 316 |
+
},
|
| 317 |
+
{
|
| 318 |
+
"type": "text",
|
| 319 |
+
"bbox": [470, 240, 580, 760],
|
| 320 |
+
"text": "JSON LAB",
|
| 321 |
+
"desc": "Medium blue uppercase subtitle text centered under the main title.",
|
| 322 |
+
"color_palette": ["#2563EB"],
|
| 323 |
+
},
|
| 324 |
+
{
|
| 325 |
+
"type": "obj",
|
| 326 |
+
"bbox": [660, 330, 760, 670],
|
| 327 |
+
"desc": "A thin orange rounded rectangle outline used as a design accent.",
|
| 328 |
+
"color_palette": ["#F97316"],
|
| 329 |
+
},
|
| 330 |
+
],
|
| 331 |
+
},
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
def dumps_caption(caption):
|
| 336 |
+
return json.dumps(caption, ensure_ascii=False, separators=(",", ":"), indent=2)
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def normalize_caption(raw_caption):
|
| 340 |
+
try:
|
| 341 |
+
caption = json.loads(raw_caption, strict=False)
|
| 342 |
+
except Exception as e:
|
| 343 |
+
raise gr.Error(f"JSON parse error: {e}") from e
|
| 344 |
+
|
| 345 |
+
if not isinstance(caption, dict):
|
| 346 |
+
raise gr.Error("Top-level JSON must be an object.")
|
| 347 |
+
|
| 348 |
+
if "compositional_deconstruction" not in caption:
|
| 349 |
+
gr.Warning("compositional_deconstruction is missing. The model accepts any string, but this is outside the usual Ideogram 4 caption format.")
|
| 350 |
+
|
| 351 |
+
return json.dumps(caption, ensure_ascii=False, separators=(",", ":")), caption
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def build_preset(mode, main_guidance=DEFAULT_MAIN_GUIDANCE, final_guidance=DEFAULT_FINAL_GUIDANCE):
|
| 355 |
+
preset = dict(MODES.get(mode, MODES["Default 路 20 steps"]))
|
| 356 |
+
steps = int(preset.pop("num_inference_steps"))
|
| 357 |
+
final_steps = min(int(preset.pop("final_guidance_steps")), steps)
|
| 358 |
+
main_steps = steps - final_steps
|
| 359 |
+
guidance_schedule = (float(main_guidance),) * main_steps + (float(final_guidance),) * final_steps
|
| 360 |
+
preset.update(num_inference_steps=steps, guidance_schedule=guidance_schedule)
|
| 361 |
+
return preset
|
| 362 |
|
| 363 |
with gr.Blocks(title=APP_TITLE) as demo:
|
| 364 |
lora_note = (
|