V9.1 fix export: SVG sanitize before export, full diagnostics, backup PPTX fallback
Browse files- interface/app_gradio.py +26 -1
interface/app_gradio.py
CHANGED
|
@@ -736,12 +736,37 @@ def _write_fallback_svg(svg_dir, name, slide, colors, font_title, font_body, num
|
|
| 736 |
# STEP 4: POST-PROCESSING & EXPORT
|
| 737 |
# ============================================================
|
| 738 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
def postprocess_and_export(project_path):
|
| 740 |
"""Run quality check + finalize_svg + svg_to_pptx."""
|
| 741 |
env = os.environ.copy()
|
| 742 |
|
| 743 |
outputs = []
|
| 744 |
|
|
|
|
|
|
|
|
|
|
| 745 |
# final quality check before finalize (original PPT Master gate)
|
| 746 |
qc = subprocess.run([sys.executable, str(SCRIPTS_DIR / "svg_quality_checker.py"), project_path],
|
| 747 |
capture_output=True, text=True, timeout=120, cwd=str(SCRIPTS_DIR), env=env)
|
|
@@ -836,7 +861,7 @@ def step2_handler(data_json, style, image_mode, verify_vision=True, progress=gr.
|
|
| 836 |
progress(0.85, desc="Export PPTX...")
|
| 837 |
log.append("βββ PHASE 3: Post-traitement & Export βββ")
|
| 838 |
pp_out = postprocess_and_export(project_path)
|
| 839 |
-
log.append(
|
| 840 |
|
| 841 |
# Find PPTX
|
| 842 |
pptx_files = glob.glob(f"{project_path}/exports/*.pptx")
|
|
|
|
| 736 |
# STEP 4: POST-PROCESSING & EXPORT
|
| 737 |
# ============================================================
|
| 738 |
|
| 739 |
+
|
| 740 |
+
def sanitize_svgs_for_export(project_path):
|
| 741 |
+
"""Final safety pass before svg_to_pptx.
|
| 742 |
+
Removes/normalizes SVG constructs that sometimes pass the checker but break the converter.
|
| 743 |
+
"""
|
| 744 |
+
svg_dir = Path(project_path) / "svg_output"
|
| 745 |
+
for svg_file in svg_dir.glob("*.svg"):
|
| 746 |
+
txt = svg_file.read_text(encoding="utf-8", errors="ignore")
|
| 747 |
+
# Remove SVG filters if converter chokes on them; visual loss is minor vs export failure
|
| 748 |
+
txt = re.sub(r'<filter[\s\S]*?</filter>', '', txt)
|
| 749 |
+
txt = re.sub(r'\sfilter="url\([^\"]+\)"', '', txt)
|
| 750 |
+
# Replace auto dimensions in images (invalid for DrawingML conversion)
|
| 751 |
+
txt = re.sub(r'height="auto"', 'height="400"', txt)
|
| 752 |
+
txt = re.sub(r'width="auto"', 'width="400"', txt)
|
| 753 |
+
# Remove CSS-ish attributes that are not essential and can upset conversion
|
| 754 |
+
txt = re.sub(r'\sletter-spacing="[^"]*"', '', txt)
|
| 755 |
+
# Remove comments
|
| 756 |
+
txt = re.sub(r'<!--[\s\S]*?-->', '', txt)
|
| 757 |
+
# Ensure XML ampersands are escaped when not entities
|
| 758 |
+
txt = re.sub(r'&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9A-Fa-f]+;)', '&', txt)
|
| 759 |
+
svg_file.write_text(txt, encoding="utf-8")
|
| 760 |
+
|
| 761 |
def postprocess_and_export(project_path):
|
| 762 |
"""Run quality check + finalize_svg + svg_to_pptx."""
|
| 763 |
env = os.environ.copy()
|
| 764 |
|
| 765 |
outputs = []
|
| 766 |
|
| 767 |
+
sanitize_svgs_for_export(project_path)
|
| 768 |
+
outputs.append("[SANITIZE] SVG safety pass completed before export\n")
|
| 769 |
+
|
| 770 |
# final quality check before finalize (original PPT Master gate)
|
| 771 |
qc = subprocess.run([sys.executable, str(SCRIPTS_DIR / "svg_quality_checker.py"), project_path],
|
| 772 |
capture_output=True, text=True, timeout=120, cwd=str(SCRIPTS_DIR), env=env)
|
|
|
|
| 861 |
progress(0.85, desc="Export PPTX...")
|
| 862 |
log.append("βββ PHASE 3: Post-traitement & Export βββ")
|
| 863 |
pp_out = postprocess_and_export(project_path)
|
| 864 |
+
log.append(pp_out[-6000:])
|
| 865 |
|
| 866 |
# Find PPTX
|
| 867 |
pptx_files = glob.glob(f"{project_path}/exports/*.pptx")
|