fix: extract image path from prefixed stdout line

_extract_image_from_stdout() failed to find the generated image because
the pipeline prints "Card generated and saved to: generated_card.png"
but the function only tried the full line as a path. Now also tries the
part after the last colon.
This commit is contained in:
2026-03-19 19:12:29 +01:00
parent 94b927c06b
commit 577308af17

23
app.py
View File

@@ -16,16 +16,21 @@ IMAGE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".webp", ".bmp")
def _extract_image_from_stdout(stdout: str) -> Path | None: def _extract_image_from_stdout(stdout: str) -> Path | None:
for line in reversed(stdout.splitlines()): for line in reversed(stdout.splitlines()):
text = line.strip().strip("\"'") # Try the whole line, then the part after the last colon
if not text: # (handles "Card generated and saved to: generated_card.png")
continue raw = line.strip().strip("\"'")
candidates = [raw]
if ":" in raw:
candidates.append(raw.rsplit(":", 1)[1].strip().strip("\"'"))
candidate = Path(text) for text in candidates:
if not candidate.is_absolute(): if not text:
candidate = APP_DIR / candidate continue
candidate = Path(text)
if candidate.suffix.lower() in IMAGE_EXTENSIONS and candidate.exists(): if not candidate.is_absolute():
return candidate candidate = APP_DIR / candidate
if candidate.suffix.lower() in IMAGE_EXTENSIONS and candidate.exists():
return candidate
return None return None