Merge pull request 'fix: broken subprocess command and tuple unpacking in app.py' (#19) from fix/app-critical-bugs into main

Reviewed-on: #19
This commit was merged in pull request #19.
This commit is contained in:
2026-03-19 18:16:15 +00:00

37
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
@@ -33,10 +38,16 @@ 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]]:
cmd = [ cmd = [
"python prompt_to_card_pipeline.py ", sys.executable, "prompt_to_card_pipeline.py",
prompt_text, prompt_text,
"--text-cleaner-path text-cleaner/text_cleaning_pipeline.py --infer-script-path clean-text-to-keywords/infer_json_usage.py --checkpoint pokemon_card_lora --template clean-text-to-keywords/json_template_example.json --generator-module card_generator_adapter.py --device cuda --save-path generated_card.png --print-json" "--text-cleaner-path", "text-cleaner/text_cleaning_pipeline.py",
"--infer-script-path", "clean-text-to-keywords/infer_json_usage.py",
"--checkpoint", "pokemon_card_lora",
"--template", "clean-text-to-keywords/json_template_example.json",
"--generator-module", "card_generator_adapter.py",
"--device", "cuda",
"--save-path", "generated_card.png",
"--print-json",
] ]
result = subprocess.run( result = subprocess.run(
@@ -116,7 +127,7 @@ if generate:
st.warning("Veuillez entrer une description avant de générer.") st.warning("Veuillez entrer une description avant de générer.")
else: else:
with st.spinner("Génération de la carte Pokémon..."): with st.spinner("Génération de la carte Pokémon..."):
image, logs = run_prompt_pipeline(raw_text) image, logs, _cmd = run_prompt_pipeline(raw_text)
if image is not None: if image is not None:
st.image(image, caption="Carte Pokémon générée", width="stretch") st.image(image, caption="Carte Pokémon générée", width="stretch")