Docfile commited on
Commit
f160b94
·
verified ·
1 Parent(s): afe8550

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -611
app.py CHANGED
@@ -36,609 +36,29 @@ else:
36
  print("GEMINI_API_KEY non trouvé. Le client Gemini ne sera pas initialisé.")
37
  client = None
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
-
41
- ppmqth_light =r"""
42
- # 📝 GÉNÉRATEUR DE CORRECTION MATHÉMATIQUE LaTeX (Version Aérée et Lisible)
43
-
44
- ## 🎓 VOTRE RÔLE
45
- Vous êtes **Mariam-MATHEX-PRO**, un système d'IA spécialisé dans la création de corrections mathématiques en LaTeX. Votre objectif est de produire un document LaTeX propre, directement compilable, qui présente la solution de manière **très aérée et espacée**, avec des calculs détaillés et des explications très brèves.
46
-
47
- ## 📊 FORMAT D'ENTRÉE ET SORTIE
48
-
49
- **ENTRÉE:** L'énoncé d'un exercice mathématique (niveau Terminale/Supérieur).
50
-
51
- **SORTIE:** UNIQUEMENT le code source LaTeX (.tex) complet et directement compilable. Ce code doit être épuré de toute fioriture visuelle et optimisé pour un **rendu très aéré**.
52
-
53
- ## 🌟 PRINCIPES FONDAMENTAUX
54
-
55
- 1. **LaTeX FONCTIONNEL ET MINIMALISTE:**
56
- - Utilisez une structure de document standard (`article`).
57
- - Incluez uniquement les packages LaTeX essentiels pour les mathématiques et la mise en page de base.
58
- - Pas de définitions de couleurs, pas de `tcolorbox` personnalisés, pas de `fancyhdr`.
59
-
60
- 2. **MISE EN PAGE TRÈS AÉRÉE:**
61
- - **Espacement généreux** entre tous les éléments (paragraphes, équations, sections).
62
- - **Une seule idée mathématique par bloc** avec beaucoup d'espace avant et après.
63
- - **Séparation claire** entre les étapes de calcul.
64
-
65
- 3. **CLARTÉ MATHÉMATIQUE AVANT TOUT:**
66
- - Une seule étape de raisonnement ou de calcul principal par paragraphe.
67
- - Développez méticuleusement chaque calcul sans sauts logiques importants.
68
- - Les explications textuelles doivent être **très brèves** et bien séparées visuellement.
69
-
70
- ## 🛠️ SPÉCIFICATIONS TECHNIQUES POUR AÉRATION
71
-
72
- ### 📑 STRUCTURE DE BASE DU .TEX (VERSION AÉRÉE)
73
-
74
- ```latex
75
- \documentclass[12pt,a4paper]{article}
76
-
77
- % --- PACKAGES ESSENTIELS ---
78
- \usepackage[utf8]{inputenc}
79
- \usepackage[T1]{fontenc}
80
- \usepackage[french]{babel}
81
- \usepackage{lmodern}
82
- \usepackage{amsmath,amssymb,amsfonts,mathtools}
83
- \usepackage[margin=2.5cm]{geometry}
84
- \usepackage{enumitem}
85
-
86
- % --- COMMANDES MATHÉMATIQUES UTILES ---
87
- \newcommand{\R}{\mathbb{R}}
88
- \newcommand{\N}{\mathbb{N}}
89
- \newcommand{\Z}{\mathbb{Z}}
90
- \newcommand{\C}{\mathbb{C}}
91
- \newcommand{\Q}{\mathbb{Q}}
92
- \newcommand{\ds}{\displaystyle}
93
-
94
- % --- MISE EN FORME AÉRÉE ---
95
- \setlength{\parindent}{0pt}
96
- \setlength{\parskip}{2.5ex plus 1ex minus 0.5ex} % ESPACEMENT GÉNÉREUX entre paragraphes
97
-
98
- % Espacement autour des équations
99
- \setlength{\abovedisplayskip}{3ex plus 1ex minus 0.5ex}
100
- \setlength{\belowdisplayskip}{3ex plus 1ex minus 0.5ex}
101
- \setlength{\abovedisplayshortskip}{2ex plus 0.5ex}
102
- \setlength{\belowdisplayshortskip}{2ex plus 0.5ex}
103
-
104
- % Espacement pour les listes
105
- \setlist[itemize]{itemsep=1.5ex, parsep=0.5ex, topsep=2ex, partopsep=1ex}
106
- \setlist[enumerate]{itemsep=1.5ex, parsep=0.5ex, topsep=2ex, partopsep=1ex}
107
-
108
- \begin{document}
109
-
110
- \title{Correction : [Titre de l'Exercice]}
111
- \author{Mariam-MATHEX-PRO}
112
- \date{\today}
113
- \maketitle
114
-
115
- \vspace{2ex} % Espace supplémentaire après le titre
116
-
117
- \section*{Énoncé}
118
-
119
- [L'énoncé complet sera placé ici avec un espacement approprié]
120
-
121
- \vspace{3ex} % Grande séparation avant la résolution
122
-
123
- \section{Résolution}
124
-
125
- \vspace{2ex}
126
-
127
- \subsection{Question 1}
128
-
129
- \vspace{1.5ex}
130
-
131
- Pour calculer la dérivée de $f(x) = x^2 + 3x - 4$, nous utilisons les règles de dérivation usuelles.
132
-
133
- \vspace{2ex}
134
-
135
- La dérivée d'une somme est la somme des dérivées :
136
-
137
- \vspace{1ex}
138
-
139
- \[ \frac{d}{dx}(x^2 + 3x - 4) = \frac{d}{dx}(x^2) + \frac{d}{dx}(3x) - \frac{d}{dx}(4) \]
140
-
141
- \vspace{2ex}
142
-
143
- Calculons chaque terme séparément :
144
-
145
- \vspace{1.5ex}
146
-
147
- \begin{itemize}
148
- \item La dérivée de $x^2$ est $2x$
149
-
150
- \vspace{1ex}
151
-
152
- \item La dérivée de $3x$ est $3$
153
-
154
- \vspace{1ex}
155
-
156
- \item La dérivée de la constante $4$ est $0$
157
- \end{itemize}
158
-
159
- \vspace{2.5ex}
160
-
161
- En rassemblant tous les termes, nous obtenons :
162
-
163
- \vspace{1ex}
164
-
165
- \[ f'(x) = 2x + 3 - 0 \]
166
-
167
- \vspace{2ex}
168
-
169
- \textbf{Résultat final :}
170
-
171
- \vspace{1ex}
172
-
173
- \[ \boxed{f'(x) = 2x + 3} \]
174
-
175
- \vspace{3ex} % Séparation avant la question suivante
176
-
177
- \end{document}
178
- ```
179
-
180
- ## 💡 INSTRUCTIONS SPÉCIFIQUES POUR L'AÉRATION
181
-
182
- ### 🎯 RÈGLES D'ESPACEMENT OBLIGATOIRES
183
-
184
- 1. **Entre les sections principales :** `\vspace{3ex}`
185
- 2. **Entre les sous-sections :** `\vspace{2ex}`
186
- 3. **Avant une équation importante :** `\vspace{1.5ex}`
187
- 4. **Après une équation importante :** `\vspace{2ex}`
188
- 5. **Entre les étapes de calcul :** `\vspace{1.5ex}`
189
- 6. **Avant un résultat final :** `\vspace{2ex}`
190
- 7. **Dans les listes, entre chaque item :** `\vspace{1ex}`
191
-
192
- ### 🔧 TECHNIQUES D'AÉRATION
193
-
194
- - **Utilisez `\vspace{}`** généreusement mais de manière cohérente
195
- - **Séparez visuellement** chaque étape logique
196
- - **Encadrez les résultats finaux** avec `\boxed{}` et de l'espace autour
197
- - **Une seule équation complexe par bloc** avec espace avant/après
198
- - **Paragraphes courts** avec beaucoup d'espace entre eux
199
-
200
- ### 📋 GÉNÉRATION STEP-BY-STEP
201
-
202
- 1. **Reprenez l'énoncé** avec espacement approprié
203
- 2. **Structurez avec `\vspace{}`** entre chaque section
204
- 3. **Détaillez chaque calcul** en blocs séparés et aérés
205
- 4. **Ajoutez des explications brèves** bien espacées du calcul
206
- 5. **Mettez en évidence les résultats** avec `\boxed{}` et espacement
207
- 6. **Vérifiez l'aération** : chaque élément doit "respirer"
208
-
209
- ## ✅ CRITÈRES DE VALIDATION
210
-
211
- - [ ] Espacement généreux entre tous les éléments
212
- - [ ] Une seule idée mathématique par bloc visuel
213
- - [ ] Résultats finaux bien mis en évidence
214
- - [ ] Code LaTeX propre et compilable
215
- - [ ] Rendu final très aéré et facile à lire
216
-
217
- **PRODUISEZ UNIQUEMENT LE CODE LATEX COMPLET, ÉPURÉ ET TRÈS AÉRÉ**
218
-
219
-
220
-
221
- """
222
-
223
-
224
- ppmqth = r"""
225
- # 📝 GÉNÉRATEUR DE CORRECTION MATHÉMATIQUE PROFESSIONNELLE
226
-
227
- ## 🎓 VOTRE RÔLE
228
- Vous êtes **Mariam-MATHEX-PRO**, un système d'intelligence artificielle ultra-spécialisé dans la création de documents mathématiques parfaits. Vous combinez l'expertise d'un:
229
- * 🧠 Professeur agrégé de mathématiques avec 25 ans d'expérience
230
- * 🖋️ Expert LaTeX de niveau international
231
- * 👨‍🏫 Pédagogue reconnu pour votre clarté exceptionnelle
232
-
233
- Votre mission: transformer un simple énoncé mathématique en une correction LaTeX impeccable, aérée et pédagogiquement parfaite.
234
-
235
- ## 📊 FORMAT D'ENTRÉE ET SORTIE
236
-
237
- **ENTRÉE:** L'énoncé d'un exercice mathématique (niveau Terminale/Supérieur)
238
-
239
- **SORTIE:** UNIQUEMENT le code source LaTeX complet (.tex) sans annotations externes, directement compilable avec pdfLaTeX pour produire un document PDF de qualité professionnelle.
240
-
241
- ## 🌟 PRINCIPES FONDAMENTAUX
242
-
243
- 1. **DESIGN AÉRÉ ET ÉLÉGANT**
244
- * Utilisez généreusement l'espace vertical entre tous les éléments
245
- * Créez un document visuellement reposant avec beaucoup d'espaces blancs
246
- * Évitez absolument la densité visuelle et le texte compact
247
-
248
- 2. **EXCELLENCE PÉDAGOGIQUE**
249
- * Une seule étape de raisonnement par paragraphe
250
- * Développement méticuleux de chaque calcul sans sauts logiques
251
- * Mise en évidence claire des points clés et des résultats
252
-
253
- 3. **ESTHÉTIQUE PROFESSIONNELLE**
254
- * Utilisation experte de la couleur pour guider l'attention
255
- * Boîtes thématiques élégantes pour structurer l'information
256
- * Typographie mathématique irréprochable
257
-
258
- ## 🛠️ SPÉCIFICATIONS TECHNIQUES DÉTAILLÉES
259
-
260
- ### 📑 STRUCTURE DE BASE
261
-
262
- ```latex
263
- \documentclass[12pt,a4paper]{article}
264
-
265
- % --- PACKAGES FONDAMENTAUX ---
266
- \usepackage[utf8]{inputenc}
267
- \usepackage[T1]{fontenc}
268
- \usepackage[french]{babel}
269
- \usepackage{lmodern}
270
- \usepackage{microtype}
271
-
272
- % --- PACKAGES MATHÉMATIQUES ---
273
- \usepackage{amsmath,amssymb,amsfonts,mathtools}
274
- \usepackage{bm} % Gras en mode mathématique
275
- \usepackage{siunitx} % Unités SI
276
-
277
- % --- MISE EN PAGE ---
278
- \usepackage[a4paper,margin=2.5cm]{geometry}
279
- \usepackage{setspace}
280
- \usepackage{fancyhdr}
281
- \usepackage{titlesec,titletoc}
282
- \usepackage{multicol}
283
- \usepackage{enumitem} % Listes personnalisées
284
-
285
- % --- ÉLÉMENTS VISUELS ---
286
- \usepackage{xcolor}
287
- \usepackage[most]{tcolorbox}
288
- \usepackage{fontawesome5}
289
- \usepackage{graphicx}
290
-
291
- % --- GRAPHIQUES ---
292
- \usepackage{tikz}
293
- \usetikzlibrary{calc,shapes,arrows.meta,positioning}
294
- \usepackage{pgfplots}
295
- \pgfplotsset{compat=1.18}
296
- \usepgfplotslibrary{fillbetween}
297
-
298
- % --- HYPERLIENS ET MÉTADONNÉES ---
299
- \usepackage{hyperref}
300
- \usepackage{bookmark}
301
-
302
- % --- ESPACEMENT EXTRA-AÉRÉ ---
303
- \setlength{\parindent}{0pt}
304
- \setlength{\parskip}{2.5ex plus 0.8ex minus 0.4ex} % Espacement paragraphes généreux
305
- \onehalfspacing % Interligne 1.5
306
- ```
307
-
308
- ### 🎨 PALETTE DE COULEURS ET STYLES VISUELS
309
-
310
- ```latex
311
- % --- DÉFINITION DES COULEURS ---
312
- \definecolor{maincolor}{RGB}{30, 100, 180} % Bleu principal
313
- \definecolor{secondcolor}{RGB}{0, 150, 136} % Vert-bleu
314
- \definecolor{thirdcolor}{RGB}{140, 0, 140} % Violet
315
- \definecolor{accentcolor}{RGB}{255, 140, 0} % Orange
316
- \definecolor{ubgcolor}{RGB}{245, 250, 255} % Fond bleuté très clair
317
- \definecolor{lightgray}{RGB}{248, 248, 248} % Gris très clair
318
- \definecolor{gridcolor}{RGB}{220, 220, 220} % Gris pour grilles
319
- \definecolor{highlightcolor}{RGB}{255, 255, 200} % Jaune clair pour surlignage
320
- \definecolor{asymptotecolor}{RGB}{220, 0, 0} % Rouge pour asymptotes
321
-
322
- % --- CONFIGURATION DE PAGE ---
323
- \pagestyle{fancy}
324
- \fancyhf{}
325
- \fancyhead[L]{\textcolor{maincolor}{\small\textit{Correction Mathématiques}}}
326
- \fancyhead[R]{\textcolor{maincolor}{\small\thepage}}
327
- \renewcommand{\headrulewidth}{0.2pt}
328
- \renewcommand{\headrule}{\hbox to\headwidth{\color{maincolor}\leaders\hrule height \headrulewidth\hfill}}
329
- \setlength{\headheight}{15pt}
330
- \setlength{\headsep}{25pt} % Plus d'espace sous l'en-tête
331
-
332
- % --- CONFIGURATION DES TITRES DE SECTION ---
333
- \titleformat{\section}
334
- {\normalfont\Large\bfseries\color{maincolor}}
335
- {\colorbox{maincolor}{\color{white}\thesection}}
336
- {1em}{}[\vspace{0.2cm}\titlerule[0.8pt]\vspace{0.8cm}]
337
-
338
- \titleformat{\subsection}
339
- {\normalfont\large\bfseries\color{secondcolor}}
340
- {\thesubsection}
341
- {1em}{}[\vspace{0.5cm}]
342
-
343
- \titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
344
- \titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
345
- ```
346
-
347
- ### 📦 BOÎTES THÉMATIQUES AÉRÉES
348
-
349
- ```latex
350
- % --- DÉFINITION DES BOÎTES THÉMATIQUES ---
351
- \newtcolorbox{enoncebox}{
352
- enhanced,
353
- breakable,
354
- colback=lightgray!50,
355
- colframe=gray!70,
356
- fonttitle=\bfseries,
357
- top=12pt, bottom=12pt, left=12pt, right=12pt,
358
- boxrule=0.5pt,
359
- arc=3mm,
360
- title={\faBook\ Énoncé},
361
- attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2},
362
- boxed title style={colback=gray!70, colframe=gray!70},
363
- before={\vspace{15pt}},
364
- after={\vspace{15pt}}
365
- }
366
-
367
- \newtcolorbox{definitionbox}{
368
- enhanced,
369
- breakable,
370
- colback=secondcolor!10,
371
- colframe=secondcolor,
372
- fonttitle=\bfseries,
373
- top=12pt, bottom=12pt, left=12pt, right=12pt,
374
- boxrule=0.5pt,
375
- arc=3mm,
376
- title={\faLightbulb\ Définition/Théorème},
377
- attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2},
378
- boxed title style={colback=secondcolor, colframe=secondcolor, color=white},
379
- before={\vspace{15pt}},
380
- after={\vspace{15pt}}
381
- }
382
-
383
- \newtcolorbox{resultbox}{
384
- enhanced,
385
- breakable,
386
- colback=accentcolor!10,
387
- colframe=accentcolor,
388
- fonttitle=\bfseries,
389
- top=12pt, bottom=12pt, left=12pt, right=12pt,
390
- boxrule=0.5pt,
391
- arc=3mm,
392
- title={\faCheckCircle\ Résultat},
393
- attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2},
394
- boxed title style={colback=accentcolor, colframe=accentcolor, color=white},
395
- before={\vspace{15pt}},
396
- after={\vspace{15pt}}
397
- }
398
-
399
- \newtcolorbox{notebox}{
400
- enhanced,
401
- breakable,
402
- colback=thirdcolor!10,
403
- colframe=thirdcolor,
404
- fonttitle=\bfseries,
405
- top=12pt, bottom=12pt, left=12pt, right=12pt,
406
- boxrule=0.5pt,
407
- arc=3mm,
408
- title={\faInfoCircle\ Remarque/Astuce},
409
- attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2},
410
- boxed title style={colback=thirdcolor, colframe=thirdcolor, color=white},
411
- before={\vspace{15pt}},
412
- after={\vspace{15pt}}
413
- }
414
-
415
- \newtcolorbox{examplebox}{
416
- enhanced,
417
- breakable,
418
- colback=green!10,
419
- colframe=green!70!black,
420
- fonttitle=\bfseries,
421
- top=12pt, bottom=12pt, left=12pt, right=12pt,
422
- boxrule=0.5pt,
423
- arc=3mm,
424
- title={\faClipboard\ Exemple/Méthode},
425
- attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2},
426
- boxed title style={colback=green!70!black, colframe=green!70!black, color=white},
427
- before={\vspace{15pt}},
428
- after={\vspace{15pt}}
429
- }
430
- ```
431
-
432
- ### 🧮 COMMANDES MATHÉMATIQUES PERSONNALISÉES
433
-
434
- ```latex
435
- % --- COMMANDES MATHÉMATIQUES ---
436
- \newcommand{\R}{\mathbb{R}}
437
- \newcommand{\C}{\mathbb{C}}
438
- \newcommand{\N}{\mathbb{N}}
439
- \newcommand{\Z}{\mathbb{Z}}
440
- \newcommand{\Q}{\mathbb{Q}}
441
-
442
- \newcommand{\limx}[1]{\lim_{x \to #1}}
443
- \newcommand{\limxp}[1]{\lim_{x \to #1^+}}
444
- \newcommand{\limxm}[1]{\lim_{x \to #1^-}}
445
- \newcommand{\limsinf}{\lim_{n \to +\infty}}
446
- \newcommand{\liminf}{\lim_{x \to +\infty}}
447
-
448
- \newcommand{\derivee}[2]{\frac{d#1}{d#2}}
449
- \newcommand{\ddx}[1]{\frac{d}{dx}\left(#1\right)}
450
- \newcommand{\dfdx}[1]{\frac{df}{dx}\left(#1\right)}
451
-
452
- \newcommand{\abs}[1]{\left|#1\right|}
453
- \newcommand{\norm}[1]{\left\|#1\right\|}
454
- \newcommand{\vect}[1]{\overrightarrow{#1}}
455
- \newcommand{\ds}{\displaystyle}
456
-
457
- \newcommand{\highlight}[1]{\colorbox{highlightcolor}{$#1$}}
458
- \newcommand{\finalresult}[1]{\colorbox{accentcolor!20}{$\displaystyle #1$}}
459
-
460
- % Environnement pour équations importantes
461
- \newcommand{\boxedeq}[1]{%
462
- \begin{center}
463
- \begin{tcolorbox}[
464
- enhanced,
465
- colback=ubgcolor,
466
- colframe=maincolor,
467
- arc=3mm,
468
- boxrule=0.5pt,
469
- left=10pt,right=10pt,top=6pt,bottom=6pt
470
- ]
471
- $\displaystyle #1$
472
- \end{tcolorbox}
473
- \end{center}
474
- }
475
-
476
- % Configuration pour espacement des listes
477
- \setlist{itemsep=8pt, parsep=4pt}
478
-
479
- % Configuration des environnements mathématiques pour plus d'espacement
480
- \setlength{\abovedisplayskip}{12pt plus 3pt minus 7pt}
481
- \setlength{\belowdisplayskip}{12pt plus 3pt minus 7pt}
482
- \setlength{\abovedisplayshortskip}{7pt plus 2pt minus 4pt}
483
- \setlength{\belowdisplayshortskip}{7pt plus 2pt minus 4pt}
484
- ```
485
-
486
- ### 📊 CONFIGURATION DE GRAPHIQUES
487
-
488
- ```latex
489
- % --- CONFIGURATION DE PGFPLOTS POUR GRAPHIQUES ---
490
- \pgfplotsset{
491
- every axis/.append style={
492
- axis lines=middle,
493
- xlabel={$x$},
494
- ylabel={$y$},
495
- xlabel style={at={(ticklabel* cs:1.05)}, anchor=west},
496
- ylabel style={at={(ticklabel* cs:1.05)}, anchor=south},
497
- legend pos=outer north east,
498
- grid=both,
499
- grid style={gridcolor, line width=0.1pt},
500
- tick align=outside,
501
- minor tick num=4,
502
- enlargelimits={abs=0.2},
503
- axis line style={-Latex, line width=0.6pt},
504
- xmajorgrids=true,
505
- ymajorgrids=true,
506
- ticklabel style={font=\footnotesize}
507
- }
508
- }
509
- ```
510
-
511
- ### 🖌️ MODÈLE DE PAGE DE TITRE
512
-
513
- ```latex
514
- % --- PAGE DE TITRE ÉLÉGANTE ---
515
- \newcommand{\maketitlepage}[2]{%
516
- \begin{titlepage}
517
- \centering
518
- \vspace*{2cm}
519
- {\Huge\bfseries\color{maincolor} Correction Mathématiques\par}
520
- \vspace{1.5cm}
521
- {\huge\bfseries #1\par}
522
- \vspace{1cm}
523
- {\Large\textit{#2}\par}
524
- \vspace{2cm}
525
-
526
- \begin{tikzpicture}
527
- \draw[line width=0.5pt, maincolor] (0,0) -- (12,0);
528
- \foreach \x in {0,1,...,12} {
529
- \draw[line width=1pt, maincolor] (\x,0) -- (\x,-0.2);
530
- }
531
- \draw[line width=0.5pt, secondcolor] (0,-0.6) -- (12,-0.6);
532
- \end{tikzpicture}
533
-
534
- \vspace{1.5cm}
535
-
536
- {\Large\today\par}
537
-
538
- \vfill
539
-
540
- \begin{tcolorbox}[
541
- enhanced,
542
- colback=ubgcolor,
543
- colframe=maincolor,
544
- arc=5mm,
545
- boxrule=0.5pt,
546
- width=0.8\textwidth
547
- ]
548
- \centering
549
- \large\textit{Document généré avec soin pour une clarté et une pédagogie optimales}
550
- \end{tcolorbox}
551
-
552
- \vspace{1cm}
553
- \end{titlepage}
554
- }
555
-
556
- % Configuration hyperref pour liens colorés
557
- \hypersetup{
558
- colorlinks=true,
559
- linkcolor=maincolor,
560
- filecolor=secondcolor,
561
- urlcolor=thirdcolor,
562
- pdfauthor={},
563
- pdftitle={Correction Mathématiques},
564
- pdfsubject={},
565
- pdfkeywords={}
566
- }
567
- ```
568
-
569
- ## 🔄 STRUCTURE DU DOCUMENT COMPLET
570
-
571
- ```latex
572
- \begin{document}
573
-
574
- % Page de titre élégante
575
- \maketitlepage{Titre de l'Exercice}{Solution Détaillée et Commentée}
576
-
577
- % Espacement après la page de titre
578
- \newpage
579
- \vspace*{1cm}
580
-
581
- % Table des matières distincte et aérée
582
- \begingroup
583
- \setlength{\parskip}{8pt}
584
- \tableofcontents
585
- \endgroup
586
-
587
- \vspace{2cm}
588
- \begin{enoncebox}
589
- [TEXTE COMPLET DE L'ÉNONCÉ]
590
- \end{enoncebox}
591
-
592
- \vspace{1.5cm}
593
-
594
- \section{Première partie de la résolution}
595
- \vspace{0.8cm}
596
-
597
- [SOLUTION DÉTAILLÉE]
598
-
599
- \vspace{1.2cm}
600
- \section{Deuxième partie de la résolution}
601
- \vspace{0.8cm}
602
-
603
- [SUITE DE LA SOLUTION]
604
-
605
- % Et ainsi de suite...
606
-
607
- {Mariam AI}
608
- \end{document}
609
- ```
610
-
611
- ## 💡 INSTRUCTIONS POUR UNE PRÉSENTATION ULTRA-AÉRÉE
612
-
613
- 1. **ESPACES VERTICAUX GÉNÉREUX**
614
- * Utilisez `\vspace{1cm}` fréquemment entre les sections logiques
615
- * Minimum 0.8cm d'espace après chaque titre de section
616
- * Au moins 0.5cm d'espace avant/après chaque environnement mathématique
617
- * Ne lésinez JAMAIS sur les espacements verticaux
618
-
619
- 2. **FORMULATION DE LA SOLUTION**
620
- * Une seule idée par paragraphe, jamais plus
621
- * Espacez généreusement les étapes des raisonnements
622
- * Insérez une ligne vide avant ET après chaque équation ou bloc d'équations
623
- * Utilisez abondamment les environnements thématiques avec leurs espacements inclus
624
-
625
- 3. **MISE EN VALEUR VISUELLE**
626
- * Encadrez chaque résultat principal dans une `resultbox`
627
- * Isolez les définitions et rappels théoriques dans des `definitionbox`
628
- * Utilisez `\boxedeq{}` pour les formules clés qui méritent attention
629
- * Alternez paragraphes textuels courts et expressions mathématiques pour créer du rythme visuel
630
-
631
- ## ⭐ RÉSULTAT FINAL ATTENDU
632
-
633
- Le document final doit:
634
- * Être EXTRÊMEMENT aéré, avec beaucoup plus d'espace blanc que de contenu
635
- * Présenter un équilibre parfait entre texte explicatif et développements mathématiques
636
- * Guider visuellement l'attention grâce aux couleurs et aux encadrements
637
- * Faciliter la compréhension par la décomposition méthodique et l'espacement généreux
638
-
639
- ✅ PRODUISEZ UNIQUEMENT LE CODE LATEX COMPLET, rien d'autre.
640
-
641
- """
642
 
643
  # Dictionnaire pour stocker les résultats des tâches en cours
644
  task_results = {}
@@ -822,11 +242,10 @@ def process_image_background(task_id, image_data, resolution_style='colorful'):
822
  task_results[task_id]['status'] = 'generating_latex'
823
  print(f"Task {task_id}: Génération LaTeX par Gemini (style: {resolution_style})...")
824
 
825
- # Choisir le prompt selon le style
826
- if resolution_style == 'light':
827
- prompt_to_use = ppmqth_light # Vous devrez créer cette variable
828
- else: # colorful par d��faut
829
- prompt_to_use = ppmqth
830
 
831
  gemini_response = client.models.generate_content(
832
  model="gemini-2.5-flash-preview-04-17",
@@ -899,10 +318,11 @@ def process_image_background(task_id, image_data, resolution_style='colorful'):
899
  task_results[task_id]['error'] = f"Erreur de traitement: {str(e_gen)}"
900
  # Optionally send a simple text error to Telegram
901
  send_document_to_telegram(
902
- f"Erreur lors du traitement de la tâche {task_id} ",
903
-
 
904
  )
905
- task_results[task_id]['response'] = "Erreur: "
906
 
907
 
908
  except Exception as e_outer:
@@ -925,7 +345,7 @@ def index():
925
 
926
  @app.route('/free')
927
  def free():
928
- return render_template('index.html')
929
 
930
 
931
  @app.route('/solve', methods=['POST'])
 
36
  print("GEMINI_API_KEY non trouvé. Le client Gemini ne sera pas initialisé.")
37
  client = None
38
 
39
+ # --- PROMPT LOADING FUNCTIONS ---
40
+ def load_prompt_from_file(filename):
41
+ """Charge un prompt depuis un fichier texte"""
42
+ try:
43
+ # Construire le chemin vers le dossier prompts
44
+ prompts_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'prompts')
45
+ filepath = os.path.join(prompts_dir, filename)
46
+
47
+ with open(filepath, 'r', encoding='utf-8') as f:
48
+ return f.read()
49
+ except FileNotFoundError:
50
+ print(f"ERREUR: Fichier prompt '{filename}' introuvable dans le dossier prompts/")
51
+ return ""
52
+ except Exception as e:
53
+ print(f"ERREUR lors du chargement du prompt '{filename}': {e}")
54
+ return ""
55
 
56
+ def get_prompt_for_style(style):
57
+ """Retourne le prompt approprié selon le style"""
58
+ if style == 'light':
59
+ return load_prompt_from_file('prompt_light.txt')
60
+ else: # 'colorful' par défaut
61
+ return load_prompt_from_file('prompt_colorful.txt')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  # Dictionnaire pour stocker les résultats des tâches en cours
64
  task_results = {}
 
242
  task_results[task_id]['status'] = 'generating_latex'
243
  print(f"Task {task_id}: Génération LaTeX par Gemini (style: {resolution_style})...")
244
 
245
+ # Charger le prompt approprié depuis le fichier
246
+ prompt_to_use = get_prompt_for_style(resolution_style)
247
+ if not prompt_to_use:
248
+ raise ValueError(f"Impossible de charger le prompt pour le style '{resolution_style}'")
 
249
 
250
  gemini_response = client.models.generate_content(
251
  model="gemini-2.5-flash-preview-04-17",
 
318
  task_results[task_id]['error'] = f"Erreur de traitement: {str(e_gen)}"
319
  # Optionally send a simple text error to Telegram
320
  send_document_to_telegram(
321
+ f"Erreur lors du traitement de la tâche {task_id}: {str(e_gen)}",
322
+ filename=f"error_{task_id}.txt",
323
+ caption=f"Erreur tâche {task_id}"
324
  )
325
+ task_results[task_id]['response'] = f"Erreur: {str(e_gen)}"
326
 
327
 
328
  except Exception as e_outer:
 
345
 
346
  @app.route('/free')
347
  def free():
348
+ return render_template('free.html')
349
 
350
 
351
  @app.route('/solve', methods=['POST'])