V8 Exceptional Tool: web research, editable plan JSON, ultra quality multi-agent pipeline
Browse files- interface/app_gradio.py +82 -8
interface/app_gradio.py
CHANGED
|
@@ -13,6 +13,8 @@ import glob
|
|
| 13 |
import shutil
|
| 14 |
import subprocess
|
| 15 |
import re
|
|
|
|
|
|
|
| 16 |
from pathlib import Path
|
| 17 |
from datetime import datetime
|
| 18 |
|
|
@@ -67,13 +69,67 @@ MODEL_CRITIC = "tencent/hy3-preview:free" # Good visual/design criti
|
|
| 67 |
MODEL_FALLBACK_EXECUTOR = "tencent/hy3-preview:free" # Fallback if GPT-OSS is rate-limited
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# ============================================================
|
| 71 |
# STEP 1: STRATEGIST — Generate design_spec + spec_lock + outline
|
| 72 |
# ============================================================
|
| 73 |
|
| 74 |
-
def strategist_phase(subject, num_slides, style, language, audience):
|
| 75 |
"""The Strategist generates the full design specification."""
|
| 76 |
|
|
|
|
|
|
|
| 77 |
prompt = f"""You are the Strategist for PPT Master. Generate a complete design specification for a presentation.
|
| 78 |
|
| 79 |
Subject: {subject}
|
|
@@ -83,6 +139,8 @@ Language: {language}
|
|
| 83 |
Target audience: {audience}
|
| 84 |
Canvas: PPT 16:9 (1280x720, viewBox="0 0 1280 720")
|
| 85 |
|
|
|
|
|
|
|
| 86 |
Produce a JSON response with this EXACT structure:
|
| 87 |
{{
|
| 88 |
"title": "Presentation title",
|
|
@@ -600,14 +658,14 @@ def postprocess_and_export(project_path):
|
|
| 600 |
# GRADIO HANDLERS
|
| 601 |
# ============================================================
|
| 602 |
|
| 603 |
-
def step1_handler(subject, num_slides, style, language, audience, image_mode):
|
| 604 |
"""Strategist phase."""
|
| 605 |
if not subject.strip():
|
| 606 |
return "❌ Entre un sujet !", "", "{}"
|
| 607 |
try:
|
| 608 |
-
data = strategist_phase(subject, int(num_slides), style, language, audience)
|
| 609 |
preview = format_strategist_preview(data)
|
| 610 |
-
return f"✅ Design spec généré — {len(data.get('slides',[]))} slides", preview, json.dumps(data, ensure_ascii=False)
|
| 611 |
except Exception as e:
|
| 612 |
return f"❌ Erreur Strategist: {str(e)[:300]}", "", "{}"
|
| 613 |
|
|
@@ -676,6 +734,16 @@ def step2_handler(data_json, style, image_mode, progress=gr.Progress()):
|
|
| 676 |
return "❌ Export échoué", None, "\n".join(log)
|
| 677 |
|
| 678 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 679 |
# ============================================================
|
| 680 |
# GRADIO UI
|
| 681 |
# ============================================================
|
|
@@ -703,15 +771,20 @@ with gr.Blocks(title="PPT Master — Générateur IA") as app:
|
|
| 703 |
style = gr.Dropdown(STYLES, value="Dark Fantasy", label="🎨 Style")
|
| 704 |
audience = gr.Textbox(label="👥 Public", value="Grand public", placeholder="Ex: professionnels, étudiants...")
|
| 705 |
image_mode = gr.Dropdown(IMAGE_MODES, value="ComfyUI (local GPU)", label="🖼️ Images")
|
|
|
|
| 706 |
|
| 707 |
btn_plan = gr.Button("🧠 Générer le design spec (Strategist)", variant="primary", size="lg")
|
| 708 |
status1 = gr.Textbox(label="Statut", interactive=False)
|
| 709 |
gr.Markdown("### 📋 Design Spec & Plan")
|
| 710 |
preview = gr.Markdown(value="*Le design spec apparaîtra ici...*")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
|
| 712 |
with gr.Tab("2️⃣ Générer le PPTX"):
|
| 713 |
gr.Markdown("### 🚀 Pipeline complet: Images + SVG (LLM) + Export")
|
| 714 |
-
gr.Markdown("⏱️ **Temps estimé**: ~2 min (images) + ~5-
|
| 715 |
btn_gen = gr.Button("⚡ Lancer la génération complète", variant="primary", size="lg")
|
| 716 |
status2 = gr.Textbox(label="Statut", interactive=False)
|
| 717 |
with gr.Row():
|
|
@@ -734,9 +807,10 @@ Le spec_lock garantit la cohérence couleurs/fonts sur l'ensemble du deck.
|
|
| 734 |
**Stack**: OpenRouter (2 modèles gratuits) + ComfyUI local (RTX 5070 Ti)
|
| 735 |
""")
|
| 736 |
|
| 737 |
-
btn_plan.click(fn=step1_handler, inputs=[subject, num_slides, style, language, audience, image_mode],
|
| 738 |
-
outputs=[status1, preview,
|
| 739 |
-
|
|
|
|
| 740 |
outputs=[status2, pptx_out, log_box])
|
| 741 |
|
| 742 |
|
|
|
|
| 13 |
import shutil
|
| 14 |
import subprocess
|
| 15 |
import re
|
| 16 |
+
import urllib.parse
|
| 17 |
+
import urllib.request
|
| 18 |
from pathlib import Path
|
| 19 |
from datetime import datetime
|
| 20 |
|
|
|
|
| 69 |
MODEL_FALLBACK_EXECUTOR = "tencent/hy3-preview:free" # Fallback if GPT-OSS is rate-limited
|
| 70 |
|
| 71 |
|
| 72 |
+
|
| 73 |
+
# ============================================================
|
| 74 |
+
# WEB RESEARCH (optional, no API key)
|
| 75 |
+
# ============================================================
|
| 76 |
+
|
| 77 |
+
def web_research(subject, max_results=6):
|
| 78 |
+
"""Fetch lightweight recent/contextual info from the web using no-key sources.
|
| 79 |
+
Uses DuckDuckGo HTML snippets + Wikipedia summaries as fallback/context.
|
| 80 |
+
"""
|
| 81 |
+
snippets = []
|
| 82 |
+
q = subject.strip()
|
| 83 |
+
if not q:
|
| 84 |
+
return ""
|
| 85 |
+
|
| 86 |
+
# DuckDuckGo HTML snippets
|
| 87 |
+
try:
|
| 88 |
+
url = "https://duckduckgo.com/html/?" + urllib.parse.urlencode({"q": q})
|
| 89 |
+
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
| 90 |
+
html = urllib.request.urlopen(req, timeout=12).read().decode("utf-8", errors="ignore")
|
| 91 |
+
# Extract result title/snippet pairs (rough but dependency-free)
|
| 92 |
+
blocks = re.findall(r'<a rel="nofollow" class="result__a"[^>]*>(.*?)</a>.*?<a class="result__snippet"[^>]*>(.*?)</a>', html, flags=re.S)
|
| 93 |
+
for title, snip in blocks[:max_results]:
|
| 94 |
+
clean_title = re.sub('<.*?>', '', title).strip()
|
| 95 |
+
clean_snip = re.sub('<.*?>', '', snip).strip()
|
| 96 |
+
clean_snip = clean_snip.replace('"', '"').replace('&', '&').replace(''', "'")
|
| 97 |
+
if clean_title or clean_snip:
|
| 98 |
+
snippets.append(f"- {clean_title}: {clean_snip}")
|
| 99 |
+
except Exception:
|
| 100 |
+
pass
|
| 101 |
+
|
| 102 |
+
# Wikipedia summary fallback / enrichment
|
| 103 |
+
try:
|
| 104 |
+
search_url = "https://en.wikipedia.org/w/api.php?" + urllib.parse.urlencode({
|
| 105 |
+
"action": "opensearch", "search": q, "limit": 3, "namespace": 0, "format": "json"
|
| 106 |
+
})
|
| 107 |
+
req = urllib.request.Request(search_url, headers={"User-Agent": "Mozilla/5.0"})
|
| 108 |
+
data = json.loads(urllib.request.urlopen(req, timeout=10).read().decode("utf-8"))
|
| 109 |
+
titles = data[1] if len(data) > 1 else []
|
| 110 |
+
for title in titles[:3]:
|
| 111 |
+
summary_url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + urllib.parse.quote(title)
|
| 112 |
+
req2 = urllib.request.Request(summary_url, headers={"User-Agent": "Mozilla/5.0"})
|
| 113 |
+
summary = json.loads(urllib.request.urlopen(req2, timeout=10).read().decode("utf-8"))
|
| 114 |
+
extract = summary.get("extract")
|
| 115 |
+
if extract:
|
| 116 |
+
snippets.append(f"- Wikipedia — {title}: {extract[:600]}")
|
| 117 |
+
except Exception:
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
if not snippets:
|
| 121 |
+
return ""
|
| 122 |
+
return "WEB RESEARCH CONTEXT (use for factual accuracy and recent/contextual details):\n" + "\n".join(snippets[:max_results+3])
|
| 123 |
+
|
| 124 |
# ============================================================
|
| 125 |
# STEP 1: STRATEGIST — Generate design_spec + spec_lock + outline
|
| 126 |
# ============================================================
|
| 127 |
|
| 128 |
+
def strategist_phase(subject, num_slides, style, language, audience, use_web=False):
|
| 129 |
"""The Strategist generates the full design specification."""
|
| 130 |
|
| 131 |
+
research_context = web_research(subject) if use_web else ""
|
| 132 |
+
|
| 133 |
prompt = f"""You are the Strategist for PPT Master. Generate a complete design specification for a presentation.
|
| 134 |
|
| 135 |
Subject: {subject}
|
|
|
|
| 139 |
Target audience: {audience}
|
| 140 |
Canvas: PPT 16:9 (1280x720, viewBox="0 0 1280 720")
|
| 141 |
|
| 142 |
+
{research_context}
|
| 143 |
+
|
| 144 |
Produce a JSON response with this EXACT structure:
|
| 145 |
{{
|
| 146 |
"title": "Presentation title",
|
|
|
|
| 658 |
# GRADIO HANDLERS
|
| 659 |
# ============================================================
|
| 660 |
|
| 661 |
+
def step1_handler(subject, num_slides, style, language, audience, image_mode, use_web):
|
| 662 |
"""Strategist phase."""
|
| 663 |
if not subject.strip():
|
| 664 |
return "❌ Entre un sujet !", "", "{}"
|
| 665 |
try:
|
| 666 |
+
data = strategist_phase(subject, int(num_slides), style, language, audience, use_web=use_web)
|
| 667 |
preview = format_strategist_preview(data)
|
| 668 |
+
return f"✅ Design spec généré — {len(data.get('slides',[]))} slides", preview, json.dumps(data, ensure_ascii=False, indent=2)
|
| 669 |
except Exception as e:
|
| 670 |
return f"❌ Erreur Strategist: {str(e)[:300]}", "", "{}"
|
| 671 |
|
|
|
|
| 734 |
return "❌ Export échoué", None, "\n".join(log)
|
| 735 |
|
| 736 |
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
def refresh_preview_from_json(data_json):
|
| 740 |
+
"""Refresh markdown preview from edited JSON."""
|
| 741 |
+
try:
|
| 742 |
+
data = json.loads(data_json)
|
| 743 |
+
return "✅ Aperçu mis à jour", format_strategist_preview(data), json.dumps(data, ensure_ascii=False, indent=2)
|
| 744 |
+
except Exception as e:
|
| 745 |
+
return f"❌ JSON invalide: {str(e)[:200]}", "", data_json
|
| 746 |
+
|
| 747 |
# ============================================================
|
| 748 |
# GRADIO UI
|
| 749 |
# ============================================================
|
|
|
|
| 771 |
style = gr.Dropdown(STYLES, value="Dark Fantasy", label="🎨 Style")
|
| 772 |
audience = gr.Textbox(label="👥 Public", value="Grand public", placeholder="Ex: professionnels, étudiants...")
|
| 773 |
image_mode = gr.Dropdown(IMAGE_MODES, value="ComfyUI (local GPU)", label="🖼️ Images")
|
| 774 |
+
use_web = gr.Checkbox(label="🌐 Recherche web pour données récentes", value=True)
|
| 775 |
|
| 776 |
btn_plan = gr.Button("🧠 Générer le design spec (Strategist)", variant="primary", size="lg")
|
| 777 |
status1 = gr.Textbox(label="Statut", interactive=False)
|
| 778 |
gr.Markdown("### 📋 Design Spec & Plan")
|
| 779 |
preview = gr.Markdown(value="*Le design spec apparaîtra ici...*")
|
| 780 |
+
gr.Markdown("### ✏️ Modifier la trame avant génération")
|
| 781 |
+
gr.Markdown("Tu peux modifier le JSON ci-dessous : titres, contenu, prompts images, layout, notes, couleurs, etc. Puis clique sur **Mettre à jour l’aperçu** avant génération.")
|
| 782 |
+
outline_editor = gr.Textbox(label="JSON éditable du plan/spec", lines=18, interactive=True)
|
| 783 |
+
btn_refresh = gr.Button("🔄 Mettre à jour l’aperçu depuis mes modifications", variant="secondary")
|
| 784 |
|
| 785 |
with gr.Tab("2️⃣ Générer le PPTX"):
|
| 786 |
gr.Markdown("### 🚀 Pipeline complet: Images + SVG (LLM) + Export")
|
| 787 |
+
gr.Markdown("⏱️ **Temps estimé Ultra**: ~2 min (images) + ~5-8 min (SVG GPT-OSS) + ~8-12 min (Art Director HY3) + export. Qualité maximale.")
|
| 788 |
btn_gen = gr.Button("⚡ Lancer la génération complète", variant="primary", size="lg")
|
| 789 |
status2 = gr.Textbox(label="Statut", interactive=False)
|
| 790 |
with gr.Row():
|
|
|
|
| 807 |
**Stack**: OpenRouter (2 modèles gratuits) + ComfyUI local (RTX 5070 Ti)
|
| 808 |
""")
|
| 809 |
|
| 810 |
+
btn_plan.click(fn=step1_handler, inputs=[subject, num_slides, style, language, audience, image_mode, use_web],
|
| 811 |
+
outputs=[status1, preview, outline_editor])
|
| 812 |
+
btn_refresh.click(fn=refresh_preview_from_json, inputs=[outline_editor], outputs=[status1, preview, outline_editor])
|
| 813 |
+
btn_gen.click(fn=step2_handler, inputs=[outline_editor, style, image_mode],
|
| 814 |
outputs=[status2, pptx_out, log_box])
|
| 815 |
|
| 816 |
|