V4: LLM-generated SVG slides for high quality output
Browse files- interface/app_gradio.py +99 -111
interface/app_gradio.py
CHANGED
|
@@ -211,134 +211,117 @@ def generate_images(outline, project_path, image_mode, progress_callback=None):
|
|
| 211 |
pass
|
| 212 |
|
| 213 |
|
| 214 |
-
def generate_svgs(outline, project_path, style):
|
| 215 |
-
"""Generate SVG files for each slide."""
|
| 216 |
svg_dir = Path(project_path) / "svg_output"
|
| 217 |
svg_dir.mkdir(parents=True, exist_ok=True)
|
| 218 |
images_dir = Path(project_path) / "images"
|
| 219 |
|
| 220 |
-
FT = 'Georgia, Times New Roman, serif'
|
| 221 |
-
FB = 'Arial, Microsoft YaHei, sans-serif'
|
| 222 |
-
|
| 223 |
# Style color palettes
|
| 224 |
palettes = {
|
| 225 |
-
"Dark Fantasy":
|
| 226 |
-
"Corporate":
|
| 227 |
-
"Tech / Startup":
|
| 228 |
-
"Nature / Zen":
|
| 229 |
-
"Académique":
|
| 230 |
-
"Minimaliste":
|
| 231 |
}
|
| 232 |
-
|
|
|
|
|
|
|
| 233 |
|
| 234 |
for slide in outline.get("slides", []):
|
| 235 |
num = slide["number"]
|
| 236 |
-
title = slide["title"].replace('&', '&').replace('<', '<').replace('>', '>')
|
| 237 |
-
content = slide.get("content", [])
|
| 238 |
-
layout = slide.get("layout", "content")
|
| 239 |
name = f"slide_{num:02d}"
|
| 240 |
|
|
|
|
|
|
|
|
|
|
| 241 |
# Find image for this slide
|
| 242 |
-
|
| 243 |
for ext in ('.png', '.jpg', '.jpeg', '.webp'):
|
| 244 |
candidate = images_dir / f"{name}{ext}"
|
| 245 |
if candidate.exists():
|
| 246 |
-
|
| 247 |
break
|
| 248 |
|
| 249 |
-
|
| 250 |
-
svg_lines = [
|
| 251 |
-
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720" width="1280" height="720">',
|
| 252 |
-
f' <defs>',
|
| 253 |
-
f' <linearGradient id="bgG" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="{C["bg"]}"/><stop offset="100%" stop-color="{C["bg2"]}"/></linearGradient>',
|
| 254 |
-
f' </defs>',
|
| 255 |
-
f' <rect width="1280" height="720" fill="url(#bgG)"/>',
|
| 256 |
-
]
|
| 257 |
-
|
| 258 |
-
if img_file and layout == "cover":
|
| 259 |
-
svg_lines.append(f' <image href="{img_file}" x="0" y="0" width="1280" height="720" preserveAspectRatio="xMidYMid slice"/>')
|
| 260 |
-
svg_lines.append(f' <rect width="1280" height="720" fill="{C["bg"]}" fill-opacity="0.55"/>')
|
| 261 |
-
svg_lines.append(f' <g id="cover-title">')
|
| 262 |
-
svg_lines.append(f' <text x="80" y="320" font-family="{FT}" font-size="72" font-weight="bold" fill="{C["text"]}">{title}</text>')
|
| 263 |
-
svg_lines.append(f' <rect x="80" y="345" width="350" height="5" rx="2" fill="{C["primary"]}"/>')
|
| 264 |
-
if content:
|
| 265 |
-
svg_lines.append(f' <text x="80" y="400" font-family="{FB}" font-size="24" fill="{C["muted"]}">{content[0].replace("&","&").replace("<","<")[:100]}</text>')
|
| 266 |
-
svg_lines.append(f' </g>')
|
| 267 |
-
|
| 268 |
-
elif img_file and layout in ("content", "comparison", "quote"):
|
| 269 |
-
# Split layout: image right, text left
|
| 270 |
-
svg_lines.append(f' <image href="{img_file}" x="680" y="60" width="540" height="600" preserveAspectRatio="xMidYMid slice"/>')
|
| 271 |
-
svg_lines.append(f' <rect x="680" y="60" width="540" height="600" fill="{C["bg"]}" fill-opacity="0.2"/>')
|
| 272 |
-
svg_lines.append(f' <g id="text-content">')
|
| 273 |
-
svg_lines.append(f' <text x="60" y="100" font-family="{FT}" font-size="36" font-weight="bold" fill="{C["text"]}">{title}</text>')
|
| 274 |
-
svg_lines.append(f' <rect x="60" y="118" width="160" height="4" rx="2" fill="{C["primary"]}"/>')
|
| 275 |
-
for j, point in enumerate(content[:5]):
|
| 276 |
-
y = 175 + j * 95
|
| 277 |
-
point_esc = point.replace('&', '&').replace('<', '<').replace('>', '>')
|
| 278 |
-
# Truncate long lines
|
| 279 |
-
if len(point_esc) > 70:
|
| 280 |
-
line1 = point_esc[:70]
|
| 281 |
-
line2 = point_esc[70:140]
|
| 282 |
-
svg_lines.append(f' <circle cx="75" cy="{y-4}" r="5" fill="{C["primary"]}"/>')
|
| 283 |
-
svg_lines.append(f' <text x="92" y="{y}" font-family="{FB}" font-size="18" fill="{C["text"]}">{line1}</text>')
|
| 284 |
-
svg_lines.append(f' <text x="92" y="{y+26}" font-family="{FB}" font-size="18" fill="{C["muted"]}">{line2}</text>')
|
| 285 |
-
else:
|
| 286 |
-
svg_lines.append(f' <circle cx="75" cy="{y-4}" r="5" fill="{C["primary"]}"/>')
|
| 287 |
-
svg_lines.append(f' <text x="92" y="{y}" font-family="{FB}" font-size="18" fill="{C["text"]}">{point_esc}</text>')
|
| 288 |
-
svg_lines.append(f' </g>')
|
| 289 |
-
|
| 290 |
-
elif layout == "timeline":
|
| 291 |
-
svg_lines.append(f' <g id="title">')
|
| 292 |
-
svg_lines.append(f' <text x="640" y="80" text-anchor="middle" font-family="{FT}" font-size="36" font-weight="bold" fill="{C["text"]}">{title}</text>')
|
| 293 |
-
svg_lines.append(f' <rect x="530" y="96" width="220" height="4" rx="2" fill="{C["primary"]}"/>')
|
| 294 |
-
svg_lines.append(f' </g>')
|
| 295 |
-
svg_lines.append(f' <line x1="140" y1="360" x2="1140" y2="360" stroke="{C["border"]}" stroke-width="4" stroke-linecap="round"/>')
|
| 296 |
-
n_points = len(content[:5])
|
| 297 |
-
for j, point in enumerate(content[:5]):
|
| 298 |
-
x = 140 + j * (1000 // max(n_points - 1, 1)) if n_points > 1 else 640
|
| 299 |
-
point_esc = point.replace('&', '&').replace('<', '<').replace('>', '>')[:50]
|
| 300 |
-
svg_lines.append(f' <circle cx="{x}" cy="360" r="18" fill="{C["bg2"]}" stroke="{C["primary"]}" stroke-width="3"/>')
|
| 301 |
-
svg_lines.append(f' <text x="{x}" y="420" text-anchor="middle" font-family="{FB}" font-size="15" fill="{C["text"]}">{point_esc}</text>')
|
| 302 |
-
|
| 303 |
-
elif layout == "closing":
|
| 304 |
-
if img_file:
|
| 305 |
-
svg_lines.append(f' <image href="{img_file}" x="0" y="0" width="1280" height="720" preserveAspectRatio="xMidYMid slice"/>')
|
| 306 |
-
svg_lines.append(f' <rect width="1280" height="720" fill="{C["bg"]}" fill-opacity="0.6"/>')
|
| 307 |
-
svg_lines.append(f' <g id="closing">')
|
| 308 |
-
svg_lines.append(f' <text x="640" y="300" text-anchor="middle" font-family="{FT}" font-size="52" font-weight="bold" fill="{C["text"]}">{title}</text>')
|
| 309 |
-
svg_lines.append(f' <rect x="500" y="320" width="280" height="5" rx="2" fill="{C["primary"]}"/>')
|
| 310 |
-
if content:
|
| 311 |
-
svg_lines.append(f' <text x="640" y="400" text-anchor="middle" font-family="{FB}" font-size="22" fill="{C["muted"]}">{content[0].replace("&","&").replace("<","<")[:120]}</text>')
|
| 312 |
-
svg_lines.append(f' </g>')
|
| 313 |
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
|
| 333 |
-
|
| 334 |
-
svg_lines.append(f' <g id="footer">')
|
| 335 |
-
svg_lines.append(f' <rect x="56" y="672" width="1168" height="1" fill="{C["border"]}" fill-opacity="0.6"/>')
|
| 336 |
-
svg_lines.append(f' <text x="1224" y="700" text-anchor="end" font-family="{FB}" font-size="12" fill="{C["muted"]}">{num:02d}/{len(outline["slides"])}</text>')
|
| 337 |
-
svg_lines.append(f' </g>')
|
| 338 |
-
svg_lines.append(f'</svg>')
|
| 339 |
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
|
| 344 |
def generate_notes(outline, project_path):
|
|
@@ -429,10 +412,15 @@ def step2_generate_pptx(outline_json, style, image_mode, progress=gr.Progress())
|
|
| 429 |
generate_images(outline, project_path, image_mode, progress_callback=img_progress)
|
| 430 |
log_lines.append(f" ✅ Images terminées\n")
|
| 431 |
|
| 432 |
-
# Step B: Generate SVGs
|
| 433 |
-
progress(0.
|
| 434 |
-
log_lines.append("🎨
|
| 435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
log_lines.append(f" ✅ {num_slides} SVG générés\n")
|
| 437 |
|
| 438 |
# Step C: Generate notes
|
|
|
|
| 211 |
pass
|
| 212 |
|
| 213 |
|
| 214 |
+
def generate_svgs(outline, project_path, style, progress_callback=None):
|
| 215 |
+
"""Generate SVG files for each slide using the LLM for high-quality output."""
|
| 216 |
svg_dir = Path(project_path) / "svg_output"
|
| 217 |
svg_dir.mkdir(parents=True, exist_ok=True)
|
| 218 |
images_dir = Path(project_path) / "images"
|
| 219 |
|
|
|
|
|
|
|
|
|
|
| 220 |
# Style color palettes
|
| 221 |
palettes = {
|
| 222 |
+
"Dark Fantasy": "Dark background gradient (#0B0F17 to #111827), gold accent #C8A45D, red #8B1E2D, ice blue #6FA8B8, light text #E8E2D6, muted #AAB2C0",
|
| 223 |
+
"Corporate": "White background #FFFFFF, blue primary #1A56DB, red accent #E02424, dark text #1F2937, clean professional",
|
| 224 |
+
"Tech / Startup": "Dark navy background #0F172A to #1E293B, cyan #06B6D4, purple accent #8B5CF6, light text #F1F5F9",
|
| 225 |
+
"Nature / Zen": "Warm white #FEFDF8, green primary #2D5016, amber accent #B45309, dark text #1C1917, organic soft",
|
| 226 |
+
"Académique": "Cream background #FFFBF5, burgundy #7C2D12, blue accent #1E40AF, dark text, scholarly elegant",
|
| 227 |
+
"Minimaliste": "Pure white #FFFFFF, black primary #18181B, red accent #DC2626, maximum whitespace, ultra clean",
|
| 228 |
}
|
| 229 |
+
palette_desc = palettes.get(style, palettes["Dark Fantasy"])
|
| 230 |
+
|
| 231 |
+
num_slides = len(outline.get("slides", []))
|
| 232 |
|
| 233 |
for slide in outline.get("slides", []):
|
| 234 |
num = slide["number"]
|
|
|
|
|
|
|
|
|
|
| 235 |
name = f"slide_{num:02d}"
|
| 236 |
|
| 237 |
+
if progress_callback:
|
| 238 |
+
progress_callback(f"🎨 SVG {num}/{num_slides}: {slide['title'][:50]}...")
|
| 239 |
+
|
| 240 |
# Find image for this slide
|
| 241 |
+
img_ref = ""
|
| 242 |
for ext in ('.png', '.jpg', '.jpeg', '.webp'):
|
| 243 |
candidate = images_dir / f"{name}{ext}"
|
| 244 |
if candidate.exists():
|
| 245 |
+
img_ref = f'Include this image: <image href="../images/{name}{ext}" preserveAspectRatio="xMidYMid slice"/>'
|
| 246 |
break
|
| 247 |
|
| 248 |
+
content_text = "\n".join(f"- {p}" for p in slide.get("content", []))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
+
prompt = f"""Generate a beautiful SVG slide (viewBox="0 0 1280 720") for a presentation.
|
| 251 |
+
Slide {num}/{num_slides}. Layout: {slide.get('layout','content')}. Style: {style}.
|
| 252 |
+
|
| 253 |
+
Title: {slide['title']}
|
| 254 |
+
Content:
|
| 255 |
+
{content_text}
|
| 256 |
+
|
| 257 |
+
{img_ref}
|
| 258 |
+
|
| 259 |
+
Color palette: {palette_desc}
|
| 260 |
+
Fonts: Georgia, Times New Roman, serif for titles. Arial, sans-serif for body text.
|
| 261 |
+
|
| 262 |
+
Design rules:
|
| 263 |
+
- viewBox="0 0 1280 720", include width="1280" height="720"
|
| 264 |
+
- Include xmlns="http://www.w3.org/2000/svg"
|
| 265 |
+
- Use gradients, decorative shapes (circles, lines, rects with opacity)
|
| 266 |
+
- {f'Place the image prominently (half-slide or background)' if img_ref else 'No image available, use shapes and colors creatively'}
|
| 267 |
+
- Show ALL content points as text elements, nicely positioned
|
| 268 |
+
- Add a page number {num}/{num_slides} in bottom right
|
| 269 |
+
- NO <style>, NO class, NO foreignObject, NO animate, NO script, NO mask
|
| 270 |
+
- NO HTML entities, use raw Unicode characters
|
| 271 |
+
- All text in absolute positioned <text> elements
|
| 272 |
+
- Make it visually rich and professional
|
| 273 |
|
| 274 |
+
Reply with ONLY the SVG code. Start with <svg, end with </svg>."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
+
try:
|
| 277 |
+
svg_content = llm_chat(prompt, max_tokens=8000, temperature=0.3)
|
| 278 |
+
|
| 279 |
+
# Clean up: extract just the SVG
|
| 280 |
+
svg_start = svg_content.find('<svg')
|
| 281 |
+
svg_end = svg_content.rfind('</svg>')
|
| 282 |
+
if svg_start >= 0 and svg_end > svg_start:
|
| 283 |
+
svg_content = svg_content[svg_start:svg_end + 6]
|
| 284 |
+
elif svg_start >= 0:
|
| 285 |
+
svg_content = svg_content[svg_start:] + '</svg>'
|
| 286 |
+
|
| 287 |
+
# Basic validation
|
| 288 |
+
if '<svg' not in svg_content:
|
| 289 |
+
raise RuntimeError("No SVG in response")
|
| 290 |
+
|
| 291 |
+
(svg_dir / f"{name}.svg").write_text(svg_content, encoding="utf-8")
|
| 292 |
+
|
| 293 |
+
except Exception as e:
|
| 294 |
+
# Fallback: simple template SVG if LLM fails
|
| 295 |
+
if progress_callback:
|
| 296 |
+
progress_callback(f" ⚠️ LLM failed for slide {num}, using fallback: {str(e)[:60]}")
|
| 297 |
+
_fallback_svg(svg_dir, name, slide, style, img_ref, num, num_slides)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def _fallback_svg(svg_dir, name, slide, style, img_ref, num, total):
|
| 301 |
+
"""Simple fallback SVG when LLM generation fails."""
|
| 302 |
+
palettes = {
|
| 303 |
+
"Dark Fantasy": ('#0B0F17','#111827','#C8A45D','#E8E2D6','#AAB2C0','#344052'),
|
| 304 |
+
"Corporate": ('#FFFFFF','#F4F6F9','#1A56DB','#1F2937','#6B7280','#E5E7EB'),
|
| 305 |
+
"Tech / Startup": ('#0F172A','#1E293B','#06B6D4','#F1F5F9','#94A3B8','#334155'),
|
| 306 |
+
"Nature / Zen": ('#FEFDF8','#F0EDE4','#2D5016','#1C1917','#78716C','#D6D3D1'),
|
| 307 |
+
"Académique": ('#FFFBF5','#F5F0E8','#7C2D12','#1C1917','#57534E','#D6D3D1'),
|
| 308 |
+
"Minimaliste": ('#FFFFFF','#FAFAFA','#18181B','#18181B','#71717A','#E4E4E7'),
|
| 309 |
+
}
|
| 310 |
+
bg, bg2, primary, text, muted, border = palettes.get(style, palettes["Dark Fantasy"])
|
| 311 |
+
title = slide["title"].replace('&','&').replace('<','<').replace('>','>')
|
| 312 |
+
content = slide.get("content", [])
|
| 313 |
+
|
| 314 |
+
lines = [f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720" width="1280" height="720">',
|
| 315 |
+
f' <rect width="1280" height="720" fill="{bg}"/>',
|
| 316 |
+
f' <text x="60" y="90" font-family="Georgia, Times New Roman, serif" font-size="36" font-weight="bold" fill="{text}">{title}</text>',
|
| 317 |
+
f' <rect x="60" y="108" width="160" height="4" fill="{primary}"/>']
|
| 318 |
+
for j, p in enumerate(content[:6]):
|
| 319 |
+
y = 180 + j * 80
|
| 320 |
+
p_esc = p.replace('&','&').replace('<','<').replace('>','>')[:100]
|
| 321 |
+
lines.append(f' <text x="80" y="{y}" font-family="Arial, sans-serif" font-size="20" fill="{text}">{p_esc}</text>')
|
| 322 |
+
lines.append(f' <text x="1224" y="700" text-anchor="end" font-family="Arial, sans-serif" font-size="12" fill="{muted}">{num}/{total}</text>')
|
| 323 |
+
lines.append('</svg>')
|
| 324 |
+
(svg_dir / f"{name}.svg").write_text("\n".join(lines), encoding="utf-8")
|
| 325 |
|
| 326 |
|
| 327 |
def generate_notes(outline, project_path):
|
|
|
|
| 412 |
generate_images(outline, project_path, image_mode, progress_callback=img_progress)
|
| 413 |
log_lines.append(f" ✅ Images terminées\n")
|
| 414 |
|
| 415 |
+
# Step B: Generate SVGs via LLM (high quality)
|
| 416 |
+
progress(0.3, desc="Création des slides SVG via LLM (peut prendre plusieurs minutes)...")
|
| 417 |
+
log_lines.append("🎨 Génération SVG par le LLM (qualité haute)...")
|
| 418 |
+
log_lines.append(f" ⏱️ ~60-90s par slide, {num_slides} slides à générer...")
|
| 419 |
+
|
| 420 |
+
def svg_progress(msg):
|
| 421 |
+
log_lines.append(f" {msg}")
|
| 422 |
+
|
| 423 |
+
generate_svgs(outline, project_path, style, progress_callback=svg_progress)
|
| 424 |
log_lines.append(f" ✅ {num_slides} SVG générés\n")
|
| 425 |
|
| 426 |
# Step C: Generate notes
|