Docfile commited on
Commit
87e553e
·
verified ·
1 Parent(s): be583ae

Update templates/philosophie.html

Browse files
Files changed (1) hide show
  1. templates/philosophie.html +1001 -167
templates/philosophie.html CHANGED
@@ -1,189 +1,1023 @@
1
  <!DOCTYPE html>
2
- <html lang="fr">
3
  <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
- <title>Assistant de Philosophie (Vue.js)</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- <script src="https://unpkg.com/vue@3"></script>
9
- <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
 
 
 
 
 
 
 
 
10
 
11
- <!-- Ajout du crossorigin pour aider le chargement des fonts dans html2canvas -->
12
- <link rel="preconnect" href="https://fonts.googleapis.com">
13
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
14
- <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Lato:wght@400;700&display=swap" rel="stylesheet" crossorigin="anonymous">
15
 
16
- <style>
17
- body { font-family: 'Lato', sans-serif; background-color: #f4f4f9; margin: 0; padding: 20px; color: #333; }
18
- .container { max-width: 900px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
19
- h1 { text-align: center; color: #2c3e50; }
20
- textarea { width: 100%; padding: 10px; border-radius: 4px; border: 1px solid #ddd; min-height: 80px; margin-bottom: 10px; font-size: 16px; }
21
- button { display: block; width: 100%; padding: 15px; background-color: #2980b9; color: white; border: none; border-radius: 5px; font-size: 18px; cursor: pointer; transition: background-color 0.3s; }
22
- button:hover { background-color: #3498db; }
23
- button:disabled { background-color: #95a5a6; cursor: not-allowed; }
24
- .loader { display: block; border: 8px solid #f3f3f3; border-top: 8px solid #3498db; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; }
25
- @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
26
- .error { color: #c0392b; text-align: center; margin-top: 20px; font-weight: bold; }
27
-
28
- /* Paper style */
29
- .dissertation-paper {
30
- font-family: 'Kalam', cursive;
31
- font-size: 20px;
32
- color: #1a2a4c;
33
- background-color: #fdfaf4;
34
- line-height: 1.8;
35
- background-image: linear-gradient(transparent 97%, #d8e2ee 98%);
36
- background-size: 100% 36px;
37
- border-left: 2px solid #ffaaab;
38
- padding-left: 4em;
39
- margin: 40px -30px -30px -30px;
40
- padding-top: 30px;
41
- padding-bottom: 30px;
42
- padding-right: 30px;
43
- /* for better printing */
44
- -webkit-print-color-adjust: exact;
45
- print-color-adjust: exact;
46
- -webkit-font-smoothing: antialiased;
47
- /* Force white background for canvas capture (avoid transparent PNG-like issues) */
48
- background-clip: padding-box;
49
- }
50
- .dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.8em; }
51
- .dissertation-paper h3 { font-size: 1.2em; margin-top: 3.6em; margin-bottom: 1.8em; text-transform: uppercase; text-decoration: underline; }
52
- .dissertation-paper .development-block { margin-top: 3.6em; }
53
- .dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
54
- .dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 1.8em; }
55
- .dissertation-paper .indented { text-indent: 3em; }
56
- .dissertation-paper .transition { margin-top: 1.8em; margin-bottom: 1.8em; font-style: italic; color: #4a6a9c; }
57
- .dissertation-paper .pdf-button-container { text-align: center; margin-top: 3.6em; }
58
- .dissertation-paper .pdf-button { font-family: 'Lato', sans-serif; font-size: 16px; padding: 10px 20px; width: auto; }
59
-
60
- /* Evite que des blocs soient cassés au mauvais endroit */
61
- .dissertation-paper, .dissertation-paper * { box-sizing: border-box; }
62
- .avoid-page-break { page-break-inside: avoid; break-inside: avoid; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  </style>
64
  </head>
65
- <body>
66
- <div id="app" class="container">
67
- <!-- contenu Vue -->
68
- <h1>Assistant de Dissertation Philosophique</h1>
69
-
70
- <form @submit.prevent="generateDissertation">
71
- <textarea v-model="question" placeholder="Entrez votre sujet de dissertation ici..."></textarea>
72
- <button type="submit" :disabled="isLoading">
73
- {{ isLoading ? 'Génération en cours...' : 'Générer la dissertation' }}
74
- </button>
75
- </form>
76
-
77
- <div v-if="isLoading" class="loader"></div>
78
- <p v-if="errorMessage" class="error">{{ errorMessage }}</p>
79
-
80
- <div v-if="dissertation" id="dissertation-content" class="dissertation-paper">
81
- <h2>Sujet : {{ dissertation.sujet }}</h2>
82
- <p class="prof">Prof : {{ dissertation.prof }}</p>
83
-
84
- <h3>Introduction</h3>
85
- <p class="indented">{{ dissertation.introduction }}</p>
86
-
87
- <div v-for="partie in dissertation.parties" :key="partie.chapeau" class="avoid-page-break">
88
- <div class="development-block">
89
- <p class="indented">{{ partie.chapeau }}</p>
90
- <p v-for="(arg, idx) in partie.arguments" :key="idx" class="indented">
91
- {{ arg.paragraphe_argumentatif }}
92
- </p>
93
  </div>
94
- <p v-if="partie.transition" class="indented transition">{{ partie.transition }}</p>
95
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
- <h3>Conclusion</h3>
98
- <p class="indented">{{ dissertation.conclusion }}</p>
 
 
 
 
 
 
 
99
 
100
- <div class="pdf-button-container" data-html2canvas-ignore="true">
101
- <!-- data-html2canvas-ignore empêchera le bouton d'être rendu dans le canvas -->
102
- <button class="pdf-button" @click="generatePDF">Télécharger en PDF</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  </div>
104
  </div>
105
- <!-- fin contenu Vue -->
106
- </div>
107
-
108
- <script>
109
- const { createApp } = Vue;
110
-
111
- createApp({
112
- data() {
113
- return {
114
- question: '',
115
- isLoading: false,
116
- errorMessage: null,
117
- dissertation: null
118
- }
119
- },
120
- methods: {
121
- async generateDissertation() {
122
- if (!this.question.trim()) {
123
- this.errorMessage = "Veuillez entrer un sujet de dissertation.";
124
- return;
125
- }
126
- this.isLoading = true;
127
- this.errorMessage = null;
128
- this.dissertation = null;
129
- try {
130
- const response = await fetch('/api/generate_dissertation', {
131
- method: 'POST',
132
- headers: { 'Content-Type': 'application/json' },
133
- body: JSON.stringify({ question: this.question })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  });
135
- const data = await response.json();
136
- if (!response.ok) {
137
- throw new Error(data.error || "Une erreur inconnue est survenue.");
 
 
 
 
 
 
 
 
 
138
  }
139
- this.dissertation = data;
140
- // petit timeout facultatif pour s'assurer que le DOM est posé
141
- await new Promise(r => setTimeout(r, 50));
142
- } catch (error) {
143
- this.errorMessage = error.message;
144
- } finally {
145
- this.isLoading = false;
146
- }
147
- },
148
 
149
- async generatePDF() {
150
- const element = document.getElementById('dissertation-content');
151
- if (!element) {
152
- this.errorMessage = "Contenu introuvable pour le PDF.";
153
- return;
154
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
- try {
157
- // attendre que les polices web soient chargées (important pour html2canvas)
158
- if (document.fonts && document.fonts.ready) {
159
- await document.fonts.ready;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
- // mettre la page en haut (prévenir offset / découpage)
163
- window.scrollTo(0, 0);
164
-
165
- const options = {
166
- margin: [10, 10, 10, 10], // mm
167
- filename: 'dissertation-philosophie.pdf',
168
- image: { type: 'jpeg', quality: 0.98 },
169
- html2canvas: {
170
- scale: 2,
171
- useCORS: true,
172
- logging: true,
173
- backgroundColor: '#ffffff' // important si l'élément a un fond semi-transparent
174
- },
175
- jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
176
- };
177
-
178
- // génération
179
- await html2pdf().set(options).from(element).save();
180
- } catch (err) {
181
- console.error('Erreur html2pdf:', err);
182
- this.errorMessage = "Erreur lors de la génération du PDF. Vérifiez la console pour plus de détails (CORS / ressources externes).";
183
- }
 
 
 
184
  }
185
- }
186
- }).mount('#app');
187
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  </body>
189
  </html>
 
1
  <!DOCTYPE html>
2
+ <html lang="fr" class="scroll-smooth">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Mariam AI - Assistant Philosophique</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
9
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.all.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
12
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
13
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/locale/fr.js"></script>
14
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.min.css" rel="stylesheet">
15
+ <script src="https://cdn.tailwindcss.com"></script>
16
+ <link rel="stylesheet" href="https://rsms.me/inter/inter.css">
17
+ <style>
18
+ /* Styles pour le Glow Up */
19
+ :root {
20
+ font-family: 'Inter', sans-serif;
21
+ --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
22
+ --transition-fast: all 0.15s ease-out;
23
+ --violet-gradient: linear-gradient(135deg, #8b5cf6 0%, #a855f7 50%, #c084fc 100%);
24
+ }
25
+
26
+ html {
27
+ scroll-behavior: smooth;
28
+ -webkit-overflow-scrolling: touch;
29
+ }
30
+
31
+ body {
32
+ will-change: scroll-position;
33
+ -webkit-font-smoothing: antialiased;
34
+ -moz-osx-font-smoothing: grayscale;
35
+ }
36
+
37
+ /* Loader magnifique avec animations */
38
+ .progress-container {
39
+ background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
40
+ border: 2px solid #e2e8f0;
41
+ position: relative;
42
+ overflow: hidden;
43
+ }
44
 
45
+ .progress-container::before {
46
+ content: '';
47
+ position: absolute;
48
+ top: 0;
49
+ left: -100%;
50
+ width: 100%;
51
+ height: 100%;
52
+ background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.1), transparent);
53
+ animation: shimmer 2s infinite;
54
+ }
55
 
56
+ @keyframes shimmer {
57
+ 0% { left: -100%; }
58
+ 100% { left: 100%; }
59
+ }
60
 
61
+ .progress-bar {
62
+ background: var(--violet-gradient);
63
+ height: 100%;
64
+ transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
65
+ position: relative;
66
+ overflow: hidden;
67
+ box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
68
+ }
69
+
70
+ .progress-bar::after {
71
+ content: '';
72
+ position: absolute;
73
+ top: 0;
74
+ left: 0;
75
+ right: 0;
76
+ bottom: 0;
77
+ background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.3) 50%, transparent 70%);
78
+ animation: progressGlow 2s ease-in-out infinite;
79
+ }
80
+
81
+ @keyframes progressGlow {
82
+ 0%, 100% { transform: translateX(-100%) skewX(-15deg); }
83
+ 50% { transform: translateX(200%) skewX(-15deg); }
84
+ }
85
+
86
+ .loading-dots {
87
+ display: inline-flex;
88
+ align-items: center;
89
+ }
90
+
91
+ .loading-dots span {
92
+ width: 8px;
93
+ height: 8px;
94
+ border-radius: 50%;
95
+ background: #8b5cf6;
96
+ margin: 0 2px;
97
+ animation: loadingDots 1.4s infinite ease-in-out both;
98
+ }
99
+
100
+ .loading-dots span:nth-child(1) { animation-delay: -0.32s; }
101
+ .loading-dots span:nth-child(2) { animation-delay: -0.16s; }
102
+
103
+ @keyframes loadingDots {
104
+ 0%, 80%, 100% {
105
+ transform: scale(0.8);
106
+ opacity: 0.5;
107
+ }
108
+ 40% {
109
+ transform: scale(1.2);
110
+ opacity: 1;
111
+ }
112
+ }
113
+
114
+ /* Animation de fondu pour le streaming */
115
+ .streaming-text {
116
+ opacity: 0;
117
+ animation: fadeInUp 0.6s ease-out forwards;
118
+ }
119
+
120
+ @keyframes fadeInUp {
121
+ from {
122
+ opacity: 0;
123
+ transform: translateY(20px);
124
+ }
125
+ to {
126
+ opacity: 1;
127
+ transform: translateY(0);
128
+ }
129
+ }
130
+
131
+ .word-by-word {
132
+ display: inline;
133
+ opacity: 0;
134
+ animation: wordFadeIn 0.3s ease-out forwards;
135
+ }
136
+
137
+ @keyframes wordFadeIn {
138
+ from {
139
+ opacity: 0;
140
+ transform: translateY(10px) scale(0.95);
141
+ }
142
+ to {
143
+ opacity: 1;
144
+ transform: translateY(0) scale(1);
145
+ }
146
+ }
147
+
148
+ /* Pulse effect pour le contenu en cours de génération */
149
+ .generating-pulse {
150
+ animation: pulseGlow 2s ease-in-out infinite;
151
+ }
152
+
153
+ @keyframes pulseGlow {
154
+ 0%, 100% {
155
+ box-shadow: 0 0 20px rgba(139, 92, 246, 0.1);
156
+ transform: scale(1);
157
+ }
158
+ 50% {
159
+ box-shadow: 0 0 30px rgba(139, 92, 246, 0.2);
160
+ transform: scale(1.01);
161
+ }
162
+ }
163
+
164
+ /* Styles pour le texte en cours de streaming */
165
+ .streaming-cursor::after {
166
+ content: '|';
167
+ animation: cursorBlink 1s infinite;
168
+ color: #8b5cf6;
169
+ margin-left: 2px;
170
+ }
171
+
172
+ @keyframes cursorBlink {
173
+ 0%, 50% { opacity: 1; }
174
+ 51%, 100% { opacity: 0; }
175
+ }
176
+
177
+ .collapsible {
178
+ cursor: pointer;
179
+ padding: 1rem;
180
+ width: 100%;
181
+ border: none;
182
+ text-align: left;
183
+ outline: none;
184
+ transition: var(--transition-fast);
185
+ touch-action: manipulation;
186
+ -webkit-tap-highlight-color: transparent;
187
+ }
188
+
189
+ .collapsible:hover {
190
+ background-color: #f9fafb;
191
+ }
192
+
193
+ .content {
194
+ padding: 0 1rem;
195
+ display: none;
196
+ overflow: hidden;
197
+ background-color: white;
198
+ transition: var(--transition-smooth);
199
+ }
200
+
201
+ .prose {
202
+ max-width: 100% !important;
203
+ text-rendering: optimizeLegibility;
204
+ }
205
+
206
+ #response .prose {
207
+ color: #374151;
208
+ word-wrap: break-word;
209
+ overflow-wrap: break-word;
210
+ hyphens: auto;
211
+ -webkit-hyphens: auto;
212
+ -moz-hyphens: auto;
213
+ }
214
+
215
+ .prose p, .prose ul, .prose ol, .prose li {
216
+ line-height: 1.75;
217
+ }
218
+
219
+ .prose h1, .prose h2, .prose h3 {
220
+ margin-top: 1.5em;
221
+ margin-bottom: 0.8em;
222
+ line-height: 1.3;
223
+ }
224
+
225
+ .animate-fadeIn {
226
+ animation: fadeIn 0.4s ease-out forwards;
227
+ transform: translateZ(0);
228
+ will-change: opacity, transform;
229
+ }
230
+
231
+ @keyframes fadeIn {
232
+ from {
233
+ opacity: 0;
234
+ transform: translateY(15px) translateZ(0);
235
+ }
236
+ to {
237
+ opacity: 1;
238
+ transform: translateY(0) translateZ(0);
239
+ }
240
+ }
241
+
242
+ .select2-container--default .select2-selection--single {
243
+ border: 1px solid #d1d5db;
244
+ border-radius: 0.75rem;
245
+ height: auto;
246
+ padding: 0.75rem 1rem;
247
+ background-color: white;
248
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
249
+ }
250
+
251
+ .select2-container--default .select2-selection--single .select2-selection__rendered {
252
+ color: #111827;
253
+ line-height: inherit;
254
+ padding-right: 1.5rem;
255
+ }
256
+
257
+ .select2-results__option .course-author {
258
+ font-size: 0.875rem;
259
+ color: #6b7280;
260
+ display: block;
261
+ margin-top: 0.1rem;
262
+ }
263
+
264
+ .select2-dropdown {
265
+ border-radius: 0.75rem;
266
+ border: 1px solid #d1d5db;
267
+ box-shadow: 0 4px 6px -1px rgba(0,0,0,.1);
268
+ }
269
+
270
+ #image-preview {
271
+ max-height: 200px;
272
+ border-radius: 0.75rem;
273
+ box-shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
274
+ }
275
+
276
+ summary {
277
+ list-style: none;
278
+ }
279
+
280
+ summary::-webkit-details-marker {
281
+ display: none;
282
+ }
283
+
284
+ @media (max-width: 640px) {
285
+ .max-w-3xl {
286
+ max-width: 100%;
287
+ margin-left: 0.5rem;
288
+ margin-right: 0.5rem;
289
+ }
290
+
291
+ #response, #thinking-wrapper {
292
+ overflow-x: hidden;
293
+ }
294
+
295
+ .prose {
296
+ font-size: 0.95rem;
297
+ line-height: 1.6;
298
+ }
299
+
300
+ .animate-fadeIn {
301
+ animation-duration: 0.2s;
302
+ }
303
+ }
304
+
305
+ .generation-container {
306
+ contain: layout style;
307
+ transform: translateZ(0);
308
+ }
309
+
310
+ textarea {
311
+ resize: none;
312
+ -webkit-appearance: none;
313
+ }
314
+
315
+ button {
316
+ touch-action: manipulation;
317
+ -webkit-tap-highlight-color: transparent;
318
+ transition: var(--transition-fast);
319
+ }
320
+
321
+ .content-scrollable {
322
+ -webkit-overflow-scrolling: touch;
323
+ scroll-behavior: smooth;
324
+ }
325
  </style>
326
  </head>
327
+ <body class="bg-gray-50 text-gray-900">
328
+ <!-- Navbar -->
329
+ <nav class="bg-white/90 backdrop-blur-lg border-b border-gray-200 fixed w-full z-50">
330
+ <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
331
+ <div class="flex justify-between items-center h-16">
332
+ <div class="flex items-center space-x-3">
333
+ <svg class="h-8 w-auto text-violet-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
334
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 18v-5.25m0 0a6.01 6.01 0 001.5-.189m-1.5.189a6.01 6.01 0 01-1.5-.189m3.75 7.478a12.06 12.06 0 01-4.5 0m3.75 2.311a15.045 15.045 0 01-7.5 0C4.508 19.663 2.25 15.184 2.25 10.5 2.25 5.816 5.816 2.25 10.5 2.25c4.684 0 8.25 3.566 8.25 8.25 0 4.684-2.258 9.163-5.25 11.584z" />
335
+ </svg>
336
+ <div class="text-xl font-bold text-gray-800">Mariam AI</div>
337
+ </div>
338
+ <div class="flex items-center">
339
+ <span class="inline-flex items-center px-3 py-1.5 rounded-full text-xs font-medium bg-violet-100 text-violet-800">
340
+ Assistant Philosophique
341
+ </span>
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  </div>
 
343
  </div>
344
+ </div>
345
+ </nav>
346
+
347
+ <!-- Main Content -->
348
+ <main class="pt-24 pb-16 px-4 sm:px-6 lg:px-8">
349
+ <div class="max-w-3xl mx-auto">
350
+ <div class="bg-white rounded-2xl shadow-lg border border-gray-100 overflow-hidden">
351
+ <div class="p-6 sm:p-8">
352
+ <div class="text-center">
353
+ <h1 class="text-3xl font-bold text-gray-900">Gen'Dissertation</h1>
354
+ <p class="mt-2 text-md text-gray-600">Créez des dissertations et analyses pertinentes et structurées.</p>
355
+ </div>
356
+ </div>
357
+
358
+ <div class="p-6 sm:p-8 border-t border-gray-200 space-y-6">
359
+ <!-- Type Selection -->
360
+ <div class="space-y-2">
361
+ <label for="type-select" class="block text-sm font-medium text-gray-700">Type de travail</label>
362
+ <select id="type-select" class="w-full rounded-xl border-gray-300 shadow-sm focus:border-violet-500 focus:ring-violet-500 bg-white py-3 px-4">
363
+ <option value="1">Sujet Type 1</option>
364
+ <option value="2">Sujet Type 2 (Citation)</option>
365
+ <option value="3">Sujet Type 3</option>
366
+ </select>
367
+ </div>
368
+
369
+ <!-- Conteneur pour les champs texte -->
370
+ <div id="text-input-container">
371
+ <!-- Course Selection -->
372
+ <div class="space-y-2">
373
+ <label for="course-select" class="block text-sm font-medium text-gray-700">Utiliser un cours comme contexte</label>
374
+ <select id="course-select" class="w-full">
375
+ <option value="">Choisir un cours...</option>
376
+ </select>
377
+ </div>
378
+ <!-- Question Input -->
379
+ <div class="space-y-2 mt-4">
380
+ <label for="question" class="block text-sm font-medium text-gray-700">Sujet de dissertation</label>
381
+ <textarea id="question" rows="4" class="w-full rounded-xl border-gray-300 shadow-sm focus:border-violet-500 focus:ring-violet-500 resize-none bg-white py-3 px-4" placeholder="Saisissez votre sujet de dissertation... ex: 'La liberté consiste-t-elle à faire tout ce que l'on veut ?'"></textarea>
382
+ </div>
383
+ </div>
384
+
385
+ <!-- Conteneur pour l'upload d'image -->
386
+ <div id="image-input-container" class="hidden">
387
+ <div class="space-y-2">
388
+ <label for="image-upload" class="block text-sm font-medium text-gray-700">Charger un document pour analyse</label>
389
+ <input type="file" id="image-upload" accept="image/jpeg, image/png, image/webp" class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-violet-50 file:text-violet-700 hover:file:bg-violet-100 cursor-pointer"/>
390
+ <div class="mt-4 flex justify-center"><img id="image-preview" src="" alt="Aperçu de l'image" class="hidden"/></div>
391
+ </div>
392
+ </div>
393
 
394
+ <!-- Submit Button -->
395
+ <div class="pt-4">
396
+ <button id="submit-btn" class="w-full flex items-center justify-center py-3.5 px-6 rounded-xl bg-violet-600 text-white font-semibold shadow-md shadow-violet-200 hover:bg-violet-700 transform hover:-translate-y-0.5 transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-violet-500 focus:ring-offset-2">
397
+ <svg class="h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm.75-13a.75.75 0 00-1.5 0v5c0 .414.336.75.75.75h4a.75.75 0 000-1.5h-3.25V5z" clip-rule="evenodd" /></svg>
398
+ Générer la dissertation
399
+ </button>
400
+ </div>
401
+ </div>
402
+ </div>
403
 
404
+ <!-- Loading Section -->
405
+ <div id="loading-section" class="hidden mt-8 generation-container">
406
+ <div class="bg-white border border-gray-200 rounded-xl shadow-lg p-8 generating-pulse">
407
+ <div class="text-center space-y-6">
408
+ <div class="mx-auto w-16 h-16 relative">
409
+ <svg class="w-16 h-16 text-violet-600 animate-spin" fill="none" viewBox="0 0 24 24">
410
+ <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
411
+ <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
412
+ </svg>
413
+ </div>
414
+
415
+ <div class="space-y-3">
416
+ <h3 class="text-xl font-semibold text-gray-800">Génération en cours</h3>
417
+ <p id="loading-message" class="text-gray-600">Initialisation de l'IA philosophique</p>
418
+ <div class="loading-dots">
419
+ <span></span>
420
+ <span></span>
421
+ <span></span>
422
+ </div>
423
+ </div>
424
+
425
+ <!-- Barre de progression -->
426
+ <div class="space-y-2">
427
+ <div class="flex justify-between text-sm text-gray-600">
428
+ <span>Progression</span>
429
+ <span id="progress-percentage">0%</span>
430
+ </div>
431
+ <div class="progress-container w-full h-3 rounded-full">
432
+ <div id="progress-bar" class="progress-bar w-0 rounded-full"></div>
433
+ </div>
434
+ </div>
435
+ </div>
436
+ </div>
437
+ </div>
438
+
439
+ <!-- Thinking Process Section -->
440
+ <div id="thinking-wrapper" class="hidden mt-8 generation-container">
441
+ <details id="thinking-container" class="bg-white border border-gray-200 rounded-xl shadow-sm">
442
+ <summary class="flex justify-between items-center p-4 cursor-pointer">
443
+ <h3 class="text-md font-semibold text-gray-700">Processus de pensée de l'IA</h3>
444
+ <svg class="h-5 w-5 text-gray-500 transition-transform transform open:rotate-180" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
445
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
446
+ </svg>
447
+ </summary>
448
+ <div id="thinking-process" class="p-4 border-t border-gray-200 text-sm text-gray-600 prose prose-sm max-w-none max-h-64 overflow-y-auto content-scrollable">
449
+ </div>
450
+ </details>
451
+ </div>
452
+
453
+ <!-- Response Section -->
454
+ <div id="response" class="hidden mt-6 generation-container">
455
+ <div class="bg-white border border-gray-200 rounded-xl shadow-sm p-6 sm:p-8 prose prose-violet max-w-none">
456
+ </div>
457
+ </div>
458
+
459
+ <!-- Action Buttons -->
460
+ <div id="action-buttons" class="hidden mt-6 grid grid-cols-1 sm:grid-cols-2 gap-4">
461
+ <button id="copy-btn" class="w-full flex items-center justify-center py-3 px-6 rounded-xl bg-gray-100 text-gray-800 font-medium border border-gray-200 hover:bg-gray-200 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-offset-2">
462
+ <svg class="h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75" /></svg>
463
+ Copier le texte
464
+ </button>
465
+ </div>
466
+
467
+ <!-- Saved Dissertations Section -->
468
+ <div class="mt-12">
469
+ <h3 class="text-xl font-bold text-gray-800 mb-4">Historique</h3>
470
+ <div id="dissertations-list" class="space-y-3">
471
+ </div>
472
  </div>
473
  </div>
474
+ </main>
475
+
476
+ <!-- Bouton flottant DeepThink -->
477
+ <button id="deepthink-btn" class="fixed bottom-6 right-6 z-50 flex items-center bg-indigo-600 text-white px-5 py-3 rounded-full shadow-lg hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition-transform hover:scale-105">
478
+ <svg class="h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.898 20.562L16.25 22.5l-.648-1.938a3.375 3.375 0 00-2.672-2.672L11.25 18l1.938-.648a3.375 3.375 0 002.672-2.672L16.25 13.5l.648 1.938a3.375 3.375 0 002.672 2.672L21.75 18l-1.938.648a3.375 3.375 0 00-2.672 2.672z" /></svg>
479
+ DeepThink
480
+ </button>
481
+
482
+ <script>
483
+ $(document).ready(function() {
484
+ // --- Initialisations ---
485
+ $('#course-select').select2({
486
+ placeholder: 'Optionnel : choisir un cours...',
487
+ allowClear: true,
488
+ templateResult: function (course) {
489
+ if (!course.id) { return course.text; }
490
+ return $(`<span>${course.text}</span><span class="course-author">Pr. ${$(course.element).data('author')}</span>`);
491
+ },
492
+ templateSelection: function (course) { return course.text; },
493
+ });
494
+ marked.setOptions({ breaks: true, gfm: true, headerIds: false, mangle: false });
495
+ moment.locale('fr');
496
+ const Toast = Swal.mixin({ toast: true, position: 'top-end', showConfirmButton: false, timer: 3000, timerProgressBar: true });
497
+
498
+ // Variables pour le loader et streaming
499
+ let currentProgress = 0;
500
+ let progressInterval;
501
+ let streamingTimeout;
502
+
503
+ // Messages de chargement rotatifs
504
+ const loadingMessages = [
505
+ "Initialisation de l'IA philosophique",
506
+ "Analyse du sujet proposé",
507
+ "Recherche des concepts clés",
508
+ "Construction de l'argumentation",
509
+ "Structuration de la dissertation",
510
+ "Vérification de la cohérence",
511
+ "Finalisation de la réponse"
512
+ ];
513
+
514
+ // Fonction pour simuler le progress loader
515
+ function startProgressLoader() {
516
+ currentProgress = 0;
517
+ let messageIndex = 0;
518
+
519
+ $('#loading-section').removeClass('hidden').addClass('animate-fadeIn');
520
+ $('#progress-bar').css('width', '0%');
521
+ $('#progress-percentage').text('0%');
522
+
523
+ // Animation du message
524
+ const messageInterval = setInterval(() => {
525
+ $('#loading-message').fadeOut(300, function() {
526
+ $(this).text(loadingMessages[messageIndex]).fadeIn(300);
527
+ messageIndex = (messageIndex + 1) % loadingMessages.length;
528
  });
529
+ }, 2000);
530
+
531
+ // Animation de la barre de progression
532
+ progressInterval = setInterval(() => {
533
+ if (currentProgress < 95) {
534
+ // Progression plus rapide au début, plus lente vers la fin
535
+ const increment = currentProgress < 30 ? Math.random() * 8 + 3 :
536
+ currentProgress < 60 ? Math.random() * 4 + 2 :
537
+ Math.random() * 2 + 0.5;
538
+
539
+ currentProgress = Math.min(currentProgress + increment, 95);
540
+ updateProgressBar(currentProgress);
541
  }
542
+ }, 300);
 
 
 
 
 
 
 
 
543
 
544
+ // Nettoyer après 30 secondes max
545
+ setTimeout(() => {
546
+ clearInterval(messageInterval);
547
+ clearInterval(progressInterval);
548
+ completeProgress();
549
+ }, 30000);
550
+ }
551
+
552
+ function updateProgressBar(progress) {
553
+ $('#progress-bar').css('width', progress + '%');
554
+ $('#progress-percentage').text(Math.round(progress) + '%');
555
+ }
556
+
557
+ function completeProgress() {
558
+ clearInterval(progressInterval);
559
+ currentProgress = 100;
560
+ updateProgressBar(100);
561
+
562
+ setTimeout(() => {
563
+ $('#loading-section').fadeOut(500, function() {
564
+ startStreamingDisplay();
565
+ });
566
+ }, 800);
567
+ }
568
+
569
+ // Fonction pour démarrer l'affichage en streaming avec effet de fondu
570
+ function startStreamingDisplay() {
571
+ // Simuler des données reçues (remplacer par vraies données de l'API)
572
+ simulateStreamingData();
573
+ }
574
+
575
+ // Simulation du streaming avec de vraies données (remplacer par l'appel API réel)
576
+ function simulateStreamingData() {
577
+ // Exemple de données - remplacer par les vraies données de votre API
578
+ const sampleThinking = `## Analyse du sujet
579
+
580
+ Le sujet "La liberté consiste-t-elle à faire tout ce que l'on veut ?" interroge la nature même de la liberté. Il faut distinguer entre liberté et licence, entre pouvoir et droit.
581
+
582
+ ## Plan envisagé
583
+ 1. La liberté comme absence de contraintes
584
+ 2. Les limites nécessaires à la liberté
585
+ 3. La liberté authentique comme autodétermination`;
586
+
587
+ const sampleResponse = `# La liberté consiste-t-elle à faire tout ce que l'on veut ?
588
+
589
+ ## Introduction
590
+
591
+ La question de la liberté traverse toute l'histoire de la philosophie. À première vue, être libre semble signifier pouvoir agir selon ses désirs, sans contrainte. Cependant, cette conception spontanée de la liberté pose problème : peut-on vraiment identifier liberté et licence ? La liberté véritable ne suppose-t-elle pas au contraire certaines limites ?
592
+
593
+ ## I. La liberté comme absence de contraintes
594
+
595
+ ### A. La conception commune de la liberté
596
+
597
+ Dans l'usage courant, être libre c'est faire ce que l'on veut, quand on le veut. Cette conception négative de la liberté la définit par l'absence d'obstacles extérieurs à nos actions.
598
+
599
+ ### B. La liberté naturelle selon Hobbes
600
+
601
+ Thomas Hobbes définit la liberté comme "l'absence d'obstacles extérieurs". Dans l'état de nature, chaque individu a le droit à tout, y compris au corps d'autrui.
602
+
603
+ ## II. Les limites nécessaires à la liberté
604
+
605
+ ### A. La liberté des uns s'arrête où commence celle des autres
606
+
607
+ John Stuart Mill, dans "De la liberté", établit le principe de non-nuisance : ma liberté ne doit pas porter atteinte à celle d'autrui.
608
+
609
+ ### B. Les contraintes comme conditions de la liberté
610
+
611
+ Paradoxalement, certaines contraintes peuvent être libératrices. Les règles du jeu au tennis ne limitent pas le joueur, elles rendent le jeu possible.
612
+
613
+ ## III. La liberté authentique comme autodétermination
614
+
615
+ ### A. La liberté selon Kant
616
+
617
+ Pour Kant, la vraie liberté n'est pas de suivre ses inclinations, mais d'agir selon des principes rationnels que l'on s'est donnés à soi-même.
618
+
619
+ ### B. L'autonomie comme essence de la liberté
620
+
621
+ Être libre, c'est être autonome, c'est-à-dire se donner ses propres lois. Cela implique une maîtrise de soi et une réflexion sur ses actes.
622
+
623
+ ## Conclusion
624
+
625
+ La liberté ne peut se réduire à la simple capacité de faire tout ce que l'on veut. Une telle conception conduirait au chaos et à la négation même de la liberté. La véritable liberté réside dans l'autodétermination rationnelle, dans la capacité à agir selon des principes que l'on s'est librement choisis. Ainsi, les contraintes ne s'opposent pas nécessairement à la liberté ; elles peuvent même la rendre possible.`;
626
+
627
+ // Démarrer le streaming avec effet de fondu
628
+ startWordByWordStreaming(sampleThinking, sampleResponse);
629
+ }
630
+
631
+ // Fonction pour l'affichage mot par mot avec effet de fondu
632
+ function startWordByWordStreaming(thinkingText, responseText) {
633
+ // Afficher d'abord la section de pensée
634
+ $('#thinking-wrapper').removeClass('hidden').addClass('animate-fadeIn');
635
+ streamTextWordByWord('#thinking-process', thinkingText, 50, () => {
636
+ // Une fois la pensée terminée, afficher la réponse
637
+ $('#response').removeClass('hidden').addClass('animate-fadeIn');
638
+ streamTextWordByWord('#response > div', responseText, 30, () => {
639
+ // Une fois terminé, afficher les boutons d'action
640
+ $('#action-buttons').removeClass('hidden').addClass('animate-fadeIn');
641
+ Toast.fire({ icon: 'success', title: 'Génération terminée !' });
642
+
643
+ // Sauvegarder la dissertation
644
+ let title;
645
+ if ($('#type-select').val() === '3') {
646
+ const fileName = $('#image-upload')[0].files[0]?.name || "Analyse de document";
647
+ title = `Analyse (Sujet Type 3): ${fileName}`;
648
+ } else {
649
+ title = $('#question').val().trim();
650
+ }
651
+ saveDissertation(title, responseText);
652
+ });
653
+ });
654
+ }
655
 
656
+ // Fonction pour streamer le texte mot par mot
657
+ function streamTextWordByWord(selector, text, delay = 50, callback) {
658
+ const container = $(selector);
659
+ container.empty();
660
+
661
+ // Convertir le markdown en HTML
662
+ const htmlContent = marked.parse(text);
663
+
664
+ // Créer un élément temporaire pour extraire le texte
665
+ const tempDiv = $('<div>').html(htmlContent);
666
+
667
+ // Fonction récursive pour traiter chaque nœud
668
+ function processNode(node, targetContainer) {
669
+ if (node.nodeType === Node.TEXT_NODE) {
670
+ // Nœud texte - streamer mot par mot
671
+ const words = node.textContent.split(/(\s+)/);
672
+ let wordIndex = 0;
673
+
674
+ function addNextWord() {
675
+ if (wordIndex < words.length) {
676
+ const word = words[wordIndex];
677
+ const span = $('<span>').addClass('word-by-word').text(word);
678
+ span.css('animation-delay', '0s');
679
+ targetContainer.append(span);
680
+
681
+ setTimeout(() => {
682
+ wordIndex++;
683
+ addNextWord();
684
+ }, delay);
685
+ } else if (callback && node === tempDiv.get(0).lastChild) {
686
+ setTimeout(callback, 500);
687
+ }
688
+ }
689
+
690
+ addNextWord();
691
+
692
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
693
+ // Nœud élément - recréer l'élément et traiter ses enfants
694
+ const newElement = $(`<${node.tagName.toLowerCase()}>`);
695
+
696
+ // Copier les attributs
697
+ Array.from(node.attributes).forEach(attr => {
698
+ newElement.attr(attr.name, attr.value);
699
+ });
700
+
701
+ targetContainer.append(newElement);
702
+
703
+ // Traiter les enfants
704
+ Array.from(node.childNodes).forEach(child => {
705
+ processNode(child, newElement);
706
+ });
707
  }
708
+ }
709
+
710
+ // Démarrer le traitement
711
+ Array.from(tempDiv.get(0).childNodes).forEach(child => {
712
+ processNode(child, container);
713
+ });
714
+
715
+ // Auto-scroll pendant le streaming
716
+ const scrollInterval = setInterval(() => {
717
+ smoothScrollToBottom();
718
+ }, 200);
719
+
720
+ setTimeout(() => {
721
+ clearInterval(scrollInterval);
722
+ }, (text.split(' ').length * delay) + 2000);
723
+ }
724
 
725
+ // Fonction de scroll optimisée
726
+ function smoothScrollToBottom() {
727
+ const targetScrollTop = Math.max(0, document.documentElement.scrollHeight - window.innerHeight - 50);
728
+ window.scrollTo({
729
+ top: targetScrollTop,
730
+ behavior: 'smooth'
731
+ });
732
+ }
733
+
734
+ // --- Gestion de l'interface ---
735
+ $('#type-select').change(function() {
736
+ const type = $(this).val();
737
+ // Cacher les sections de résultat lors du changement de type
738
+ $('#loading-section, #thinking-wrapper, #response, #action-buttons').addClass('hidden');
739
+
740
+ if (type === '3') { // Sujet Type 3
741
+ $('#text-input-container').hide();
742
+ $('#image-input-container').show().addClass('animate-fadeIn');
743
+ $('#deepthink-btn').hide();
744
+ $('#submit-btn').html('<svg class="h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z" /></svg>Analyser le sujet');
745
+ } else { // Dissertation texte
746
+ $('#text-input-container').show().addClass('animate-fadeIn');
747
+ $('#image-input-container').hide();
748
+ $('#deepthink-btn').show();
749
+ $('#submit-btn').html('<svg class="h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm.75-13a.75.75 0 00-1.5 0v5c0 .414.336.75.75.75h4a.75.75 0 000-1.5h-3.25V5z" clip-rule="evenodd" /></svg>Générer la dissertation');
750
  }
751
+ }).trigger('change');
752
+
753
+ $('#image-upload').change(function(e) {
754
+ if (e.target.files && e.target.files[0]) {
755
+ const reader = new FileReader();
756
+ reader.onload = (event) => $('#image-preview').attr('src', event.target.result).removeClass('hidden').addClass('animate-fadeIn');
757
+ reader.readAsDataURL(e.target.files[0]);
758
+ }
759
+ });
760
+
761
+ // --- Gestion des clics pour démarrer la génération ---
762
+ $('#submit-btn, #deepthink-btn').click(function() {
763
+ const type = $('#type-select').val();
764
+ const isDeepThink = $(this).attr('id') === 'deepthink-btn';
765
+
766
+ if (type === '3') {
767
+ const imageFile = $('#image-upload')[0].files[0];
768
+ if (!imageFile) {
769
+ Swal.fire('Erreur', 'Veuillez sélectionner un document.', 'error');
770
+ return;
771
+ }
772
+ } else {
773
+ const question = $('#question').val().trim();
774
+ if (!question) {
775
+ Swal.fire('Erreur', 'Veuillez saisir un sujet.', 'error');
776
+ return;
777
+ }
778
+ }
779
+
780
+ // Cacher les sections précédentes et démarrer le loader
781
+ $('#thinking-wrapper, #response, #action-buttons').addClass('hidden');
782
+ startProgressLoader();
783
+
784
+ // Simuler une génération (remplacer par l'appel API réel)
785
+ setTimeout(() => {
786
+ completeProgress();
787
+ }, Math.random() * 3000 + 2000); // Entre 2 et 5 secondes
788
+
789
+ /*
790
+ // Code pour l'appel API réel (décommenter et adapter) :
791
+ const data = type === '3' ?
792
+ new FormData().append('image', $('#image-upload')[0].files[0]) :
793
+ { question: $('#question').val().trim(), type, courseId: $('#course-select').val() || null };
794
+
795
+ const url = type === '3' ? '/stream_philo_image' :
796
+ isDeepThink ? '/stream_philo_deepthink' : '/stream_philo';
797
+
798
+ handleRealStreamedGeneration(url, {
799
+ method: 'POST',
800
+ headers: type !== '3' ? { 'Content-Type': 'application/json' } : undefined,
801
+ body: type === '3' ? data : JSON.stringify(data)
802
+ });
803
+ */
804
+ });
805
+
806
+ // Fonction pour les vrais appels API streamés (à utiliser quand l'API est prête)
807
+ async function handleRealStreamedGeneration(url, options) {
808
+ startProgressLoader();
809
+
810
+ let fullResponseText = '', fullThinkingText = '';
811
+
812
+ try {
813
+ const response = await fetch(url, options);
814
+ if (!response.ok) throw new Error(await response.text());
815
+
816
+ // Compléter la barre de progression
817
+ completeProgress();
818
+
819
+ const reader = response.body.getReader();
820
+ const decoder = new TextDecoder();
821
+ let buffer = '';
822
+
823
+ while (true) {
824
+ const { value, done } = await reader.read();
825
+ if (done) break;
826
+
827
+ buffer += decoder.decode(value, { stream: true });
828
+ const lines = buffer.split('\n');
829
+ buffer = lines.pop();
830
+
831
+ for (const line of lines) {
832
+ if (line.trim() === '') continue;
833
+ try {
834
+ const data = JSON.parse(line.trim());
835
+
836
+ if (data.type === 'thought') {
837
+ fullThinkingText += data.content;
838
+ } else if (data.type === 'answer') {
839
+ fullResponseText += data.content;
840
+ } else if (data.type === 'error') {
841
+ throw new Error(data.content);
842
+ }
843
+ } catch (e) {
844
+ console.error("Erreur JSON parse:", line, e);
845
+ }
846
+ }
847
+ }
848
+
849
+ // Démarrer l'affichage streaming avec les vraies données
850
+ startWordByWordStreaming(fullThinkingText, fullResponseText);
851
+
852
+ } catch (error) {
853
+ $('#loading-section').addClass('hidden');
854
+ Swal.fire({ icon: 'error', title: 'Erreur', text: error.message || "Une erreur inconnue est survenue." });
855
+ }
856
+ }
857
+
858
+ // --- Fonctions de gestion de l'historique ---
859
+ function loadCourses() {
860
+ // Simuler le chargement des cours
861
+ const sampleCourses = [
862
+ { id: '1', title: 'Introduction à la philosophie politique', author: 'Martin' },
863
+ { id: '2', title: 'Éthique et morale', author: 'Dubois' },
864
+ { id: '3', title: 'Métaphysique contemporaine', author: 'Laurent' }
865
+ ];
866
+
867
+ const select = $('#course-select');
868
+ sampleCourses.forEach(course => {
869
+ const newOption = new Option(course.title, course.id, false, false);
870
+ $(newOption).data('author', course.author);
871
+ select.append(newOption);
872
+ });
873
+ select.trigger('change');
874
+
875
+ /*
876
+ // Code pour l'appel API réel :
877
+ $.ajax({
878
+ url: '/api/philosophy/courses',
879
+ method: 'GET',
880
+ }).done(function(courses) {
881
+ const select = $('#course-select');
882
+ courses.forEach(course => {
883
+ const newOption = new Option(course.title, course.id, false, false);
884
+ $(newOption).data('author', course.author);
885
+ select.append(newOption);
886
+ });
887
+ select.trigger('change');
888
+ }).fail(function() {
889
+ Toast.fire({ icon: 'error', title: 'Erreur de chargement des cours' });
890
+ });
891
+ */
892
+ }
893
+
894
+ function saveDissertation(title, content) {
895
+ if (!title || !content) return;
896
+ let saved = JSON.parse(localStorage.getItem('dissertations')) || [];
897
+ saved.unshift({ title, content, timestamp: Date.now() });
898
+ if(saved.length > 10) saved.pop();
899
+ localStorage.setItem('dissertations', JSON.stringify(saved));
900
+ updateSavedDissertationsList();
901
+ }
902
+
903
+ function deleteDissertation(index) {
904
+ let saved = JSON.parse(localStorage.getItem('dissertations')) || [];
905
+ saved.splice(index, 1);
906
+ localStorage.setItem('dissertations', JSON.stringify(saved));
907
+ updateSavedDissertationsList();
908
+ Toast.fire({ icon: 'info', title: 'Dissertation supprimée' });
909
+ }
910
+
911
+ function updateSavedDissertationsList() {
912
+ const list = $('#dissertations-list');
913
+ list.empty();
914
+ let saved = JSON.parse(localStorage.getItem('dissertations')) || [];
915
+ if (saved.length === 0) {
916
+ list.append('<p class="text-gray-500 text-center py-4">Aucune dissertation dans l\'historique.</p>');
917
+ return;
918
+ }
919
+ saved.forEach((diss, index) => {
920
+ const date = moment(diss.timestamp).fromNow();
921
+ const title = diss.title.length > 60 ? diss.title.substring(0, 60) + '...' : diss.title;
922
+ const item = $(`
923
+ <div class="border border-gray-200 bg-white rounded-xl shadow-sm transition-shadow hover:shadow-md">
924
+ <button class="collapsible rounded-t-xl w-full text-left">
925
+ <div class="flex justify-between items-center w-full p-4">
926
+ <span class="font-medium text-gray-800">${title}</span>
927
+ <span class="text-gray-500 text-sm flex-shrink-0 ml-4">${date}</span>
928
+ </div>
929
+ </button>
930
+ <div class="content prose max-w-none border-t border-gray-200">
931
+ <div class="inner-content p-4 content-scrollable"></div>
932
+ <div class="p-4 border-t border-gray-200 bg-gray-50 rounded-b-xl">
933
+ <button class="delete-btn text-sm text-red-600 hover:text-red-800 font-medium" data-index="${index}">Supprimer</button>
934
+ </div>
935
+ </div>
936
+ </div>
937
+ `);
938
+ item.find('.inner-content').html(marked.parse(diss.content));
939
+ list.append(item);
940
+ });
941
+ }
942
+
943
+ // Gestion des interactions avec l'historique
944
+ $('#dissertations-list').on('click', '.collapsible', function() {
945
+ const content = $(this).next('.content');
946
+ const isVisible = content.is(':visible');
947
+
948
+ content.stop(true, true).slideToggle({
949
+ duration: 300,
950
+ easing: 'swing',
951
+ start: function() {
952
+ $(this).css('overflow', 'hidden');
953
+ },
954
+ complete: function() {
955
+ $(this).css('overflow', isVisible ? 'hidden' : 'visible');
956
+ }
957
+ });
958
+
959
+ $(this).toggleClass("active");
960
+ });
961
+
962
+ $('#dissertations-list').on('click', '.delete-btn', function(e) {
963
+ e.stopPropagation();
964
+ const index = $(this).data('index');
965
+ deleteDissertation(index);
966
+ });
967
+
968
+ $('#copy-btn').click(function() {
969
+ const htmlToCopy = $('#response > div').html();
970
+ const textToCopy = new DOMParser().parseFromString(htmlToCopy, 'text/html').body.textContent || "";
971
+ navigator.clipboard.writeText(textToCopy).then(() => {
972
+ Toast.fire({ icon: 'success', title: 'Copié dans le presse-papiers!' });
973
+ }).catch(() => {
974
+ Toast.fire({ icon: 'error', title: 'Erreur de copie' });
975
+ });
976
+ });
977
+
978
+ // Optimisations mobiles
979
+ let ticking = false;
980
+
981
+ function updateScrollPosition() {
982
+ ticking = false;
983
+ }
984
+
985
+ window.addEventListener('scroll', function() {
986
+ if (!ticking) {
987
+ requestAnimationFrame(updateScrollPosition);
988
+ ticking = true;
989
+ }
990
+ }, { passive: true });
991
+
992
+ let resizeTimer;
993
+ window.addEventListener('resize', function() {
994
+ clearTimeout(resizeTimer);
995
+ resizeTimer = setTimeout(function() {
996
+ if (window.innerWidth <= 640) {
997
+ $('body').addClass('mobile-optimized');
998
+ } else {
999
+ $('body').removeClass('mobile-optimized');
1000
+ }
1001
+ }, 250);
1002
+ }, { passive: true });
1003
+
1004
+ if ('ontouchstart' in window) {
1005
+ $('body').addClass('touch-device');
1006
+
1007
+ $(document).on('touchstart', 'button, .collapsible', function() {
1008
+ $(this).addClass('touch-active');
1009
+ });
1010
+
1011
+ $(document).on('touchend', 'button, .collapsible', function() {
1012
+ const element = $(this);
1013
+ setTimeout(() => element.removeClass('touch-active'), 150);
1014
+ });
1015
+ }
1016
+
1017
+ // Initialisation
1018
+ loadCourses();
1019
+ updateSavedDissertationsList();
1020
+ });
1021
+ </script>
1022
  </body>
1023
  </html>