Fix image detection after print-to-logging migration

app.py relied on parsing stdout for the save path printed by the
pipeline. After PR #21 replaced that print with logger.info(), the
stdout parsing returned None, causing "Aucune image générée détectée".

Now check the known save path directly (APP_DIR / save_path) and
only fall back to stdout parsing if the file isn't found.
This commit is contained in:
2026-03-19 20:14:17 +01:00
parent 984bbbec18
commit e03daea1f3

7
app.py
View File

@@ -37,6 +37,7 @@ def _extract_image_from_stdout(stdout: str) -> Path | None:
def run_prompt_pipeline(prompt_text: str) -> tuple[Path | None, str, list[str]]: def run_prompt_pipeline(prompt_text: str) -> tuple[Path | None, str, list[str]]:
save_path = "generated_card.png"
cmd = [ cmd = [
sys.executable, "prompt_to_card_pipeline.py", sys.executable, "prompt_to_card_pipeline.py",
prompt_text, prompt_text,
@@ -46,7 +47,7 @@ def run_prompt_pipeline(prompt_text: str) -> tuple[Path | None, str, list[str]]:
"--template", "clean-text-to-keywords/json_template_example.json", "--template", "clean-text-to-keywords/json_template_example.json",
"--generator-module", "card_generator_adapter.py", "--generator-module", "card_generator_adapter.py",
"--device", "cuda", "--device", "cuda",
"--save-path", "generated_card.png", "--save-path", save_path,
"--print-json", "--print-json",
] ]
@@ -63,7 +64,9 @@ def run_prompt_pipeline(prompt_text: str) -> tuple[Path | None, str, list[str]]:
if result.returncode != 0: if result.returncode != 0:
return None, full_output.strip() or "Erreur inconnue pendant le pipeline.", cmd return None, full_output.strip() or "Erreur inconnue pendant le pipeline.", cmd
image_path = _extract_image_from_stdout(result.stdout or "") image_path = APP_DIR / save_path
if not image_path.exists():
image_path = _extract_image_from_stdout(result.stdout or "")
return image_path, full_output.strip(), cmd return image_path, full_output.strip(), cmd
# ------------------------------------------------------------------ # # ------------------------------------------------------------------ #