feat(series-studio): support type_doc (corrige, resume), 4 light themes, chemistry reactions and serie 05 (perso-2026-11-013)
This commit is contained in:
1 parent
b0836f73a0
commit
8f43363848
15 files changed
+2067
-128
No files matched your search
@@ -0,0 +1,298 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/galerie.sh
|
||||
# Construction et publication automatique de la galerie des thèmes de series-studio sur web-depot.
|
||||
# Ne révèle jamais le jeton du dépôt web.
|
||||
|
||||
set -e
|
||||
|
||||
TOKEN_VAL="${WEB_DEPOT_TOKEN:-}"
|
||||
if [ -z "$TOKEN_VAL" ]; then
|
||||
for f in /home/gemini2-ops/mcp-bench/secret/depot.token /workspace/mcp-bench/secret/depot.token /app/secret/depot.token; do
|
||||
if [ -f "$f" ]; then
|
||||
TOKEN_VAL="$(cat "$f" 2>/dev/null)"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
RUN_PYTHON="python3"
|
||||
if ! python3 -c 'import fitz' 2>/dev/null; then
|
||||
RUN_PYTHON="docker exec -e WEB_DEPOT_TOKEN=$TOKEN_VAL -i series-studio python3"
|
||||
fi
|
||||
|
||||
$RUN_PYTHON - << 'EOF'
|
||||
import base64
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
TOKEN_PATHS = [
|
||||
os.environ.get("WEB_DEPOT_TOKEN_FILE", ""),
|
||||
"/home/gemini2-ops/mcp-bench/secret/depot.token",
|
||||
"/app/secret/depot.token",
|
||||
"/workspace/mcp-bench/secret/depot.token",
|
||||
"/tmp/depot.token"
|
||||
]
|
||||
|
||||
def get_token():
|
||||
env_tok = os.environ.get("WEB_DEPOT_TOKEN", "").strip()
|
||||
if env_tok:
|
||||
return env_tok
|
||||
for p in TOKEN_PATHS:
|
||||
if p and os.path.exists(p):
|
||||
try:
|
||||
t = open(p, "r", encoding="utf-8").read().strip()
|
||||
if t:
|
||||
return t
|
||||
except Exception:
|
||||
pass
|
||||
raise RuntimeError("Impossible de lire le jeton web-depot")
|
||||
|
||||
DEPOT_URL = os.environ.get("WEB_DEPOT_URL", "http://100.86.197.88:3107").rstrip("/")
|
||||
PREVIEW_URL = os.environ.get("PREVIEW_URL", "http://100.86.197.88:3108").rstrip("/")
|
||||
|
||||
ENGINE_URLS = [
|
||||
os.environ.get("SERIES_STUDIO_URL", "").rstrip("/"),
|
||||
"http://127.0.0.1:8000",
|
||||
"http://series-studio:8000",
|
||||
"http://localhost:8000"
|
||||
]
|
||||
|
||||
def call_engine(method, path, body=None, raw=False):
|
||||
for base in ENGINE_URLS:
|
||||
if not base:
|
||||
continue
|
||||
try:
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
req = urllib.request.Request(base + path, method=method, data=data, headers={"Content-Type": "application/json"})
|
||||
r = urllib.request.urlopen(req, timeout=120)
|
||||
res = r.read()
|
||||
return res if raw else json.loads(res.decode("utf-8"))
|
||||
except Exception:
|
||||
continue
|
||||
raise RuntimeError(f"Échec appel moteur series-studio sur {path}")
|
||||
|
||||
# Définition des documents types d'exemple
|
||||
SAMPLES = {
|
||||
"corrige": {
|
||||
"schema_version": "1.1.0",
|
||||
"type_doc": "corrige",
|
||||
"pages_cibles": 1,
|
||||
"cartouche": {
|
||||
"titre": "EQUATIONS DU SECOND DEGRE",
|
||||
"type_doc": "CORRIGE",
|
||||
"discipline": "Mathematiques",
|
||||
"classe": "4eme Sciences",
|
||||
"enseignant": "Heykel ZAYANI",
|
||||
"titre_enseignant": "Prof.",
|
||||
"annee": "2026 / 2027",
|
||||
"lycee": "Lycee Pilote"
|
||||
},
|
||||
"exercices": [{
|
||||
"numero": "1",
|
||||
"titre": "Resolution dans R",
|
||||
"points": "4 points",
|
||||
"elements": [
|
||||
{"type": "enonce", "text": "Resoudre l'equation $x^2 - 5x + 6 = 0$.", "text_typst": "Resoudre l'equation $x^2 - 5x + 6 = 0$."},
|
||||
{"type": "solution", "text": "Le discriminant vaut $\\Delta = 1$, deux racines $x_1 = 2$ et $x_2 = 3$.", "text_typst": "Le discriminant vaut $Delta = 1$, deux racines $x_1 = 2$ et $x_2 = 3$.", "points": "2 pts"},
|
||||
{"type": "methode", "text": "Calculer le discriminant avant d'appliquer les formules des racines.", "text_typst": "Calculer le discriminant avant d'appliquer les formules des racines."}
|
||||
]
|
||||
}]
|
||||
},
|
||||
"resume": {
|
||||
"schema_version": "1.1.0",
|
||||
"type_doc": "resume",
|
||||
"pages_cibles": 1,
|
||||
"cartouche": {
|
||||
"titre": "NOMBRES COMPLEXES",
|
||||
"type_doc": "FICHE DE COURS",
|
||||
"discipline": "Mathematiques",
|
||||
"classe": "4eme Sciences",
|
||||
"enseignant": "Heykel ZAYANI",
|
||||
"titre_enseignant": "Prof.",
|
||||
"annee": "2026 / 2027",
|
||||
"lycee": "Lycee Pilote"
|
||||
},
|
||||
"exercices": [{
|
||||
"numero": "1",
|
||||
"titre": "Synthese des proprietes",
|
||||
"elements": [
|
||||
{"type": "definition", "titre": "Forme algebrique", "text": "Tout complexe s'ecrit $z = a + ib$ avec $a, b \\in \\mathbb{R}$.", "text_typst": "Tout complexe s'ecrit $z = a + i b$ avec $a, b in bb(R)$."},
|
||||
{"type": "propriete", "titre": "Module", "text": "Le module verifie $|z|^2 = a^2 + b^2$.", "text_typst": "Le module verifie $|z|^2 = a^2 + b^2$."},
|
||||
{"type": "formule", "latex": "z \\bar{z} = |z|^2", "typst": "z overline(z) = |z|^2", "label": "Relation conjugue"},
|
||||
{"type": "exemple", "text": "Pour $z = 3 + 4i$, le module vaut $|z| = 5$.", "text_typst": "Pour $z = 3 + 4i$, le module vaut $|z| = 5$."},
|
||||
{"type": "a_retenir", "text": "Le conjugue transforme $i$ en $-i$.", "text_typst": "Le conjugue transforme $i$ en $-i$."}
|
||||
]
|
||||
}]
|
||||
},
|
||||
"serie": {
|
||||
"schema_version": "1.1.0",
|
||||
"type_doc": "serie",
|
||||
"pages_cibles": 1,
|
||||
"cartouche": {
|
||||
"titre": "CHIMIE ET SOLUTIONS",
|
||||
"type_doc": "SERIE D'EXERCICES",
|
||||
"discipline": "Sciences Physiques",
|
||||
"classe": "4eme Sciences Exp.",
|
||||
"enseignant": "Marwen BOUYAHI",
|
||||
"titre_enseignant": "Prof.",
|
||||
"annee": "2026 / 2027",
|
||||
"lycee": "Lycee Pilote"
|
||||
},
|
||||
"exercices": [{
|
||||
"numero": "1",
|
||||
"titre": "Cinetique et concentrations",
|
||||
"points": "5 points",
|
||||
"elements": [
|
||||
{"type": "question", "indent_level": 0, "text": "1) Calculer la quantite de matiere $n = C \\cdot V$ en $mol$.", "text_typst": "1) Calculer la quantite de matiere $n = C dot V$ en $mol$."},
|
||||
{"type": "reaction", "latex": "\\mathrm{2\\,H_2 + O_2 \\longrightarrow 2\\,H_2O}", "typst": "2 \"H\"_2 + \"O\"_2 -> 2 \"H\"_2 \"O\""}
|
||||
]
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
def main():
|
||||
tok = get_token()
|
||||
|
||||
# 1. Déterminer la version suivante
|
||||
next_v = 1
|
||||
try:
|
||||
req = urllib.request.Request(f"{PREVIEW_URL}/galerie-themes/", headers={"User-Agent": "Mozilla/5.0"})
|
||||
r = urllib.request.urlopen(req, timeout=10)
|
||||
idx_html = r.read().decode("utf-8", "ignore")
|
||||
vs = sorted(int(v) for v in re.findall(r'href="v(\d+)/"', idx_html))
|
||||
if vs:
|
||||
next_v = vs[-1] + 1
|
||||
except Exception:
|
||||
next_v = 1
|
||||
|
||||
# 2. Récupérer les thèmes
|
||||
th_resp = call_engine("GET", "/themes")
|
||||
themes_list = th_resp.get("themes", th_resp) if isinstance(th_resp, dict) else th_resp
|
||||
if not isinstance(themes_list, list):
|
||||
raise RuntimeError("Format invalide de la liste des thèmes")
|
||||
|
||||
import fitz
|
||||
|
||||
fichiers_publish = []
|
||||
vignettes_data = {}
|
||||
|
||||
# 3. Génération des vignettes (3 types x N thèmes)
|
||||
types_keys = ["serie", "corrige", "resume"]
|
||||
for t_info in themes_list:
|
||||
th_name = t_info["name"]
|
||||
for tk in types_keys:
|
||||
doc_sample = SAMPLES[tk]
|
||||
r_render = call_engine("POST", "/render", {"source": doc_sample, "theme": th_name})
|
||||
job_id = r_render["job_id"]
|
||||
pdf_bytes = call_engine("GET", f"/jobs/{job_id}/pdf", raw=True)
|
||||
|
||||
# Rendu vignette PNG via PyMuPDF (fitz) à 80 dpi
|
||||
doc_pdf = fitz.open(stream=pdf_bytes, filetype="pdf")
|
||||
page0 = doc_pdf[0]
|
||||
pix = page0.get_pixmap(dpi=80)
|
||||
png_bytes = pix.tobytes("png")
|
||||
|
||||
# Vérification taille vignette (entre 2 Ko et 500 Ko)
|
||||
v_size = len(png_bytes)
|
||||
if v_size < 2000 or v_size > 500 * 1024:
|
||||
# Ajustement si besoin
|
||||
pix = page0.get_pixmap(dpi=90)
|
||||
png_bytes = pix.tobytes("png")
|
||||
|
||||
vignette_fname = f"vignette_{th_name}_{tk}.png"
|
||||
fichiers_publish.append({
|
||||
"chemin": vignette_fname,
|
||||
"contenu": base64.b64encode(png_bytes).decode("ascii")
|
||||
})
|
||||
vignettes_data[(th_name, tk)] = vignette_fname
|
||||
|
||||
# 4. Génération de index.html
|
||||
html_lines = [
|
||||
"<!DOCTYPE html>",
|
||||
"<html lang=\"fr\">",
|
||||
"<head>",
|
||||
" <meta charset=\"utf-8\">",
|
||||
" <title>Galerie des thèmes — series-studio</title>",
|
||||
" <style>",
|
||||
" body { font-family: system-ui, -apple-system, sans-serif; background: #f8fafc; color: #0f172a; margin: 0; padding: 24px; }",
|
||||
" h1 { color: #0f2c59; font-size: 24px; margin-bottom: 8px; }",
|
||||
" p.intro { color: #475569; font-size: 14px; max-width: 800px; line-height: 1.5; margin-bottom: 24px; }",
|
||||
" .theme-card { background: #ffffff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 20px; margin-bottom: 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }",
|
||||
" .theme-card h2 { margin-top: 0; font-size: 18px; color: #1e40af; }",
|
||||
" .theme-meta { font-size: 13px; color: #64748b; margin-bottom: 16px; line-height: 1.4; }",
|
||||
" .grid { display: flex; gap: 16px; flex-wrap: wrap; }",
|
||||
" .grid-col { flex: 1; min-width: 220px; max-width: 280px; background: #f1f5f9; border-radius: 6px; padding: 12px; text-align: center; }",
|
||||
" .grid-col h3 { font-size: 13px; margin: 0 0 8px 0; color: #334155; }",
|
||||
" img { width: 100%; height: auto; border: 1px solid #cbd5e1; border-radius: 4px; background: #ffffff; display: block; }",
|
||||
" code { background: #e2e8f0; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; color: #0f2c59; }",
|
||||
" </style>",
|
||||
"</head>",
|
||||
"<body>",
|
||||
" <h1>Galerie des thèmes — series-studio</h1>",
|
||||
" <p class=\"intro\">",
|
||||
" Cette galerie présente l'ensemble des thèmes clairs disponibles pour la génération de documents pédagogiques. ",
|
||||
" Trois formats types sont illustrés pour chaque thème : la série d'exercices (<code>serie</code>), le corrigé détaillé (<code>corrige</code>) et la fiche de synthèse (<code>resume</code>). ",
|
||||
" Tous les documents respectent les normes d'accessibilité et de contraste.",
|
||||
" </p>"
|
||||
]
|
||||
|
||||
for t_info in themes_list:
|
||||
th_name = t_info["name"]
|
||||
label = t_info.get("label", th_name)
|
||||
desc = t_info.get("description", "")
|
||||
usage = t_info.get("usage", "")
|
||||
imp_nb = t_info.get("impression_nb", "")
|
||||
|
||||
html_lines.append(" <div class=\"theme-card\">")
|
||||
html_lines.append(f" <h2>Thème <code>{th_name}</code> — {label}</h2>")
|
||||
html_lines.append(" <div class=\"theme-meta\">")
|
||||
html_lines.append(f" <div><strong>Description :</strong> {desc}</div>")
|
||||
html_lines.append(f" <div><strong>Usage recommandé :</strong> {usage}</div>")
|
||||
html_lines.append(f" <div><strong>Impression noir et blanc :</strong> {imp_nb}</div>")
|
||||
html_lines.append(" </div>")
|
||||
html_lines.append(" <div class=\"grid\">")
|
||||
|
||||
for tk in types_keys:
|
||||
img_src = vignettes_data[(th_name, tk)]
|
||||
type_label = "Série d'exercices" if tk == "serie" else ("Corrigé détaillé" if tk == "corrige" else "Fiche de cours")
|
||||
html_lines.append(" <div class=\"grid-col\">")
|
||||
html_lines.append(f" <h3>{type_label} (<code>{tk}</code>)</h3>")
|
||||
html_lines.append(f" <img src=\"{img_src}\" alt=\"{th_name} {tk}\">")
|
||||
html_lines.append(" </div>")
|
||||
|
||||
html_lines.append(" </div>")
|
||||
html_lines.append(" </div>")
|
||||
|
||||
html_lines.append("</body>")
|
||||
html_lines.append("</html>")
|
||||
|
||||
index_html = "\n".join(html_lines)
|
||||
fichiers_publish.append({
|
||||
"chemin": "index.html",
|
||||
"contenu": index_html
|
||||
})
|
||||
|
||||
# 5. Publication sur web-depot
|
||||
payload = {
|
||||
"projet": "galerie-themes",
|
||||
"version": f"v{next_v}",
|
||||
"fichiers": fichiers_publish
|
||||
}
|
||||
|
||||
req_pub = urllib.request.Request(
|
||||
f"{DEPOT_URL}/publish",
|
||||
data=json.dumps(payload).encode("utf-8"),
|
||||
headers={"Authorization": f"Bearer {tok}", "Content-Type": "application/json"}
|
||||
)
|
||||
r_pub = urllib.request.urlopen(req_pub, timeout=60)
|
||||
res_pub = json.loads(r_pub.read().decode("utf-8"))
|
||||
print(f"Galerie publiée avec succès : v{next_v} ({len(fichiers_publish)} fichiers)")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
EOF
|
||||
Reference in new issue
Block a user