HolySmokes1234 commited on
Commit
4baa141
Β·
verified Β·
1 Parent(s): 5a2594c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -357,16 +357,14 @@ def run_canonizer(
357
  steps,
358
  progress=gr.Progress(track_tqdm=True),
359
  ):
360
- # Safety cleanup
361
  gc.collect()
362
  if torch.cuda.is_available():
363
  torch.cuda.empty_cache()
364
 
365
- # No images β†’ error
366
  if not images:
367
  raise gr.Error("⚠️ Please upload an image first.")
368
 
369
- # Load first image only
370
  first = images[0]
371
  try:
372
  path = first[0] if isinstance(first, (tuple, list)) else first
@@ -384,17 +382,16 @@ def run_canonizer(
384
  seed = random.randint(0, MAX_SEED)
385
  generator = torch.Generator(device=device).manual_seed(int(seed))
386
 
387
- # Resize to frame
388
- fw, fh = BASE_FRAMES[FRAME_LABELS.index(frame_label)].size
389
- base_img = base_img.resize((fw, fh), Image.LANCZOS)
390
 
391
  # Prompt
392
  prompt = generate_prompt(name, sin, personality, vibe, color, prop)
393
 
394
- # SD‑Turbo inference (super stable)
395
  try:
396
- result = pipe(
397
- image=base_img,
398
  prompt=prompt,
399
  negative_prompt=DEFAULT_NEGATIVE_PROMPT,
400
  num_inference_steps=int(steps),
@@ -404,13 +401,17 @@ def run_canonizer(
404
  ).images[0]
405
  except Exception as e:
406
  print("INFERENCE ERROR:", e)
407
- raise gr.Error("⚠️ The AI failed to generate the saint image. Try a smaller image or lower steps.")
 
 
 
 
408
 
409
- # Frame + ribbon
410
- framed = apply_frame(result, frame_label)
411
  final_img = draw_name_on_ribbon(framed, name or "Unnamed Saint")
412
 
413
- # Oracle
414
  saint_text = generate_local_oracle(name, sin, personality, vibe, color, prop)
415
  saint_html = saint_text.replace("\n", "<br>")
416
 
@@ -422,12 +423,13 @@ def run_canonizer(
422
  </div>
423
  """
424
 
425
- # Download
426
  download_path = build_download_image(final_img, saint_text, name or "saint")
427
 
428
  return final_img, oracle_html, seed, download_path
429
 
430
 
 
431
  # ═══════════════════════════════════════════════════════════════════════
432
  # CSS
433
  # ═══════════════════════════════════════════════════════════════════════
 
357
  steps,
358
  progress=gr.Progress(track_tqdm=True),
359
  ):
 
360
  gc.collect()
361
  if torch.cuda.is_available():
362
  torch.cuda.empty_cache()
363
 
 
364
  if not images:
365
  raise gr.Error("⚠️ Please upload an image first.")
366
 
367
+ # Load first image
368
  first = images[0]
369
  try:
370
  path = first[0] if isinstance(first, (tuple, list)) else first
 
382
  seed = random.randint(0, MAX_SEED)
383
  generator = torch.Generator(device=device).manual_seed(int(seed))
384
 
385
+ # STEP 1 β€” Downscale to 512px for SD‑Turbo
386
+ base_small = base_img.resize((512, 512), Image.LANCZOS)
 
387
 
388
  # Prompt
389
  prompt = generate_prompt(name, sin, personality, vibe, color, prop)
390
 
391
+ # STEP 2 β€” SD‑Turbo inference (super stable)
392
  try:
393
+ result_small = pipe(
394
+ image=base_small,
395
  prompt=prompt,
396
  negative_prompt=DEFAULT_NEGATIVE_PROMPT,
397
  num_inference_steps=int(steps),
 
401
  ).images[0]
402
  except Exception as e:
403
  print("INFERENCE ERROR:", e)
404
+ raise gr.Error("⚠️ The AI failed to generate the saint image. Try lower steps.")
405
+
406
+ # STEP 3 β€” Upscale back to frame size (800Γ—1920)
407
+ fw, fh = BASE_FRAMES[FRAME_LABELS.index(frame_label)].size
408
+ result_big = result_small.resize((fw, fh), Image.LANCZOS)
409
 
410
+ # STEP 4 β€” Frame + ribbon
411
+ framed = apply_frame(result_big, frame_label)
412
  final_img = draw_name_on_ribbon(framed, name or "Unnamed Saint")
413
 
414
+ # STEP 5 β€” Oracle
415
  saint_text = generate_local_oracle(name, sin, personality, vibe, color, prop)
416
  saint_html = saint_text.replace("\n", "<br>")
417
 
 
423
  </div>
424
  """
425
 
426
+ # STEP 6 β€” Download
427
  download_path = build_download_image(final_img, saint_text, name or "saint")
428
 
429
  return final_img, oracle_html, seed, download_path
430
 
431
 
432
+
433
  # ═══════════════════════════════════════════════════════════════════════
434
  # CSS
435
  # ═══════════════════════════════════════════════════════════════════════