Docfile commited on
Commit
6a072ec
·
verified ·
1 Parent(s): 5c5997d

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +174 -120
templates/index.html CHANGED
@@ -6,9 +6,15 @@
6
  <title>Mariam Espagnol - Analyse de Documents</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://unpkg.com/[email protected]/marked.min.js"></script>
9
- <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.24.1/prism.min.js" integrity="sha512-a63LMgq4XH5N+DXkrHCxBUC9vOlflXd+hNt6sJOUFr10a9IFJd3r1J52W3Ak296j7b5fVz/AhJK5dGgLNZwdtw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
10
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.24.1/themes/prism-tomorrow.min.css" integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXOyEVrd0XB9aLhtFOUUjLz90GzvnBCgXWLSntyo7w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
11
- <!-- Using Prism Tomorrow theme for better contrast -->
 
 
 
 
 
 
12
  <style>
13
  @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Poppins:wght@300;400;500;600&display=swap');
14
 
@@ -31,61 +37,84 @@
31
  color: transparent;
32
  }
33
  .upload-zone {
34
- background: linear-gradient(145deg, #f9fafb, #f3f4f6); /* Slightly adjusted gradient */
35
- box-shadow: 5px 5px 15px #d1d9e6, -5px -5px 15px #ffffff; /* Adjusted shadow */
36
  transition: all 0.3s ease;
37
  }
38
- .upload-zone.dragover { /* Style when dragging over */
39
- border-color: #4f46e5; /* Indigo */
40
- background: #e0e7ff; /* Lighter Indigo */
41
  transform: scale(1.02);
42
  }
43
  .waves { position: absolute; bottom: 0; left: 0; width: 100%; overflow: hidden; line-height: 0; transform: rotate(180deg); z-index: 0; }
44
  .waves svg { position: relative; display: block; width: calc(100% + 1.3px); height: 150px; }
45
- .waves .fill-indigo-50 { fill: #eef2ff; } /* Ensure Tailwind color is applied */
46
 
47
- /* --- Responsive Analysis Box --- */
48
- /* Ensure prose content wraps and code blocks are scrollable if needed */
49
- .prose { max-width: 100%; /* Allow prose to fill container */ }
50
- .prose pre {
51
- background-color: #2d2d2d; /* Match Prism Tomorrow */
52
  color: #ccc;
53
  padding: 1em;
54
- overflow-x: auto; /* Allow horizontal scroll for code */
55
- border-radius: 0.375rem; /* Tailwind's rounded-md */
 
 
56
  }
57
- .prose code[class*="language-"] {
58
- font-family: 'Courier New', Courier, monospace; /* Consistent code font */
59
  color: #ccc;
60
- background: none; /* Prism handles background */
61
  text-shadow: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
  .prose h1, .prose h2, .prose h3 { color: #1F2937; margin-top: 1.5em; margin-bottom: 0.8em; padding-bottom: 0.3em; border-bottom: 1px solid #e5e7eb; }
64
  .prose p { margin-bottom: 1.25em; line-height: 1.7; }
65
  .prose ul, .prose ol { margin-left: 1.5em; margin-bottom: 1.25em; }
66
- .prose li > p { margin-bottom: 0.5em; } /* Less space inside list items */
67
- /* Style pour le bouton désactivé */
68
  button:disabled {
69
  opacity: 0.5;
70
  cursor: not-allowed;
71
- background-color: #a5b4fc; /* Lighter indigo when disabled */
72
  }
73
- /* Ensure Prism highlights correctly */
74
  :not(pre) > code[class*="language-"], pre[class*="language-"] {
75
- background: #2d2d2d; /* Match theme */
76
  }
77
  </style>
78
  </head>
79
- <body class="bg-gradient-to-br from-gray-50 to-gray-100 min-h-screen relative overflow-x-hidden"> <!-- Prevent body scrollbars -->
80
  <div class="waves">
81
  <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
82
  <path d="M321.39,56.44c58-10.79,114.16-30.13,172-41.86,82.39-16.72,168.19-17.73,250.45-.39C823.78,31,906.67,72,985.66,92.83c70.05,18.48,146.53,26.09,214.34,3V0H0V27.35A600.21,600.21,0,0,0,321.39,56.44Z" class="fill-indigo-50"></path>
83
  </svg>
84
  </div>
85
 
86
- <div class="max-w-4xl mx-auto px-4 py-12 relative z-10"> <!-- Reduced max-width for better focus -->
87
  <!-- Header -->
88
- <header class="text-center mb-12 fade-in"> <!-- Reduced margin -->
89
  <h1 class="text-4xl md:text-5xl font-bold mb-3 font-['Playfair_Display'] gradient-text">
90
  Mariam Espagnol
91
  </h1>
@@ -119,7 +148,7 @@
119
  <div class="mb-6">
120
  <label class="block text-base font-medium text-gray-700 mb-3">2. Sélectionnez votre fichier</label>
121
  <div id="upload-zone" class="upload-zone border-2 border-dashed border-gray-300 rounded-xl p-6 text-center cursor-pointer transition-all duration-300 relative overflow-hidden">
122
- <input id="file-upload" name="file" type="file" class="sr-only" accept="image/*"> <!-- Accept attribute will be updated by JS -->
123
  <div class="space-y-3">
124
  <div class="w-16 h-16 mx-auto rounded-full bg-indigo-100 flex items-center justify-center border-4 border-white shadow-sm">
125
  <svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -141,10 +170,10 @@
141
  <!-- Preview -->
142
  <div id="preview" class="mt-6 hidden slide-up">
143
  <h3 class="text-base font-medium text-gray-800 mb-3">Aperçu</h3>
144
- <div class="preview-container border rounded-lg p-4 bg-gray-50 max-h-72 overflow-auto relative"> <!-- Added max-height and overflow -->
145
- <img id="image-preview" class="max-w-full h-auto hidden rounded block mx-auto" alt="Aperçu Image"> <!-- Centered image -->
146
  <pre id="text-preview" class="text-sm text-gray-700 whitespace-pre-wrap hidden bg-white p-3 rounded shadow-inner"></pre>
147
- <p id="file-info" class="text-xs text-gray-500 mt-2 text-center"></p> <!-- Centered file info -->
148
  <button id="remove-file-button" class="absolute top-2 right-2 bg-red-100 text-red-600 hover:bg-red-200 rounded-full p-1 text-xs hidden" title="Retirer le fichier">
149
  <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
150
  <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
@@ -160,7 +189,7 @@
160
  class="bg-indigo-600 text-white font-medium py-2.5 px-6 rounded-lg shadow hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition duration-150 ease-in-out disabled:opacity-50 disabled:cursor-not-allowed disabled:bg-indigo-300">
161
  <span id="submit-button-text">3. Lancer l'analyse</span>
162
  <span id="submit-button-spinner" class="hidden">
163
- <svg class="animate-spin inline-block h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
164
  <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
165
  <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>
166
  </svg>
@@ -170,13 +199,12 @@
170
  </div>
171
 
172
  <!-- Analysis Results -->
173
- <div id="results" class="mt-10 hidden slide-up"> <!-- Increased margin -->
174
  <h3 class="text-lg font-semibold text-gray-900 mb-4 border-b pb-2">Analyse détaillée</h3>
175
- <!-- Added overflow-x-auto here -->
176
  <div class="bg-gray-50 rounded-lg p-4 md:p-6 shadow-inner overflow-x-auto border border-gray-200">
 
177
  <div id="analysis-content" class="prose prose-sm sm:prose-base max-w-none prose-indigo">
178
- <!-- Analysis will be inserted here -->
179
- <p class="text-gray-500">L'analyse apparaîtra ici...</p> <!-- Placeholder -->
180
  </div>
181
  </div>
182
  <div class="mt-4 text-right">
@@ -193,11 +221,6 @@
193
 
194
  </div> <!-- End max-width container -->
195
 
196
- <!-- Global Loading/Alert (Optional, could replace simple loading) -->
197
- <!-- <div id="global-message" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden backdrop-blur-sm z-50 p-4"> -->
198
- <!-- Content for loading or alerts -->
199
- <!-- </div> -->
200
-
201
  <script>
202
  document.addEventListener('DOMContentLoaded', function() {
203
  const uploadZone = document.getElementById('upload-zone');
@@ -213,24 +236,29 @@
213
  const results = document.getElementById('results');
214
  const analysisContent = document.getElementById('analysis-content');
215
  const copyAnalysisButton = document.getElementById('copy-analysis-button');
216
- // const loading = document.getElementById('loading'); // Using spinner in button now
217
  const fileTypeRadios = document.querySelectorAll('.file-type-radio');
218
  const fileTypesInfo = document.getElementById('file-types-info');
219
 
220
  let selectedFile = null;
221
 
222
- // Configure marked
223
  marked.setOptions({
224
- breaks: true, // Convert GFM line breaks to <br>
225
- gfm: true, // Use GitHub Flavored Markdown
226
- headerIds: false, // Don't add IDs to headers automatically
227
- mangle: false, // Don't obscure email addresses
228
  highlight: function(code, lang) {
229
- const language = Prism.languages[lang] || Prism.languages.markup;
230
- if (language) {
231
- return Prism.highlight(code, language, lang);
 
 
 
 
 
232
  }
233
- return code; // Return unhighlighted code if language not found
 
234
  }
235
  });
236
 
@@ -243,25 +271,25 @@
243
  } else {
244
  submitButtonText.classList.remove('hidden');
245
  submitButtonSpinner.classList.add('hidden');
246
- submitButton.disabled = (selectedFile === null); // Only enable if file is selected
247
  }
248
  }
249
 
250
- function resetUI() {
251
  selectedFile = null;
252
- fileInput.value = ''; // Clear the file input
253
  preview.classList.add('hidden');
254
  imagePreview.classList.add('hidden');
255
  textPreview.classList.add('hidden');
256
- imagePreview.src = '#'; // Reset image source
257
  textPreview.textContent = '';
258
  fileInfo.textContent = '';
259
  removeFileButton.classList.add('hidden');
260
  results.classList.add('hidden');
261
- analysisContent.innerHTML = '<p class="text-gray-500">L\'analyse apparaîtra ici...</p>'; // Reset analysis area
262
  submitButton.disabled = true;
263
- showLoading(false); // Ensure loading state is reset
264
- updateAcceptAttribute(); // Reset accept attribute
265
  }
266
 
267
  function updateAcceptAttribute() {
@@ -269,26 +297,32 @@
269
  if (selectedType === 'image') {
270
  fileInput.accept = "image/png, image/jpeg, image/gif, image/webp";
271
  fileTypesInfo.textContent = "Images (PNG, JPG, GIF, WEBP) - Max 16MB";
272
- } else { // text
273
- fileInput.accept = "text/plain, application/pdf, .txt"; // Allow PDF and TXT
274
  fileTypesInfo.textContent = "Textes (TXT, PDF lisible) - Max 16MB";
275
  }
276
- // Reset if type changes after selecting a file
277
  if (selectedFile) {
278
- resetUI();
279
- alert("Le type de document a été changé. Veuillez resélectionner votre fichier.");
 
 
 
 
 
 
 
 
 
 
 
280
  }
281
  }
282
 
283
 
284
  // --- Event Listeners ---
285
-
286
- // File Type Change
287
  fileTypeRadios.forEach(radio => {
288
  radio.addEventListener('change', updateAcceptAttribute);
289
  });
290
-
291
- // Upload Zone Interactions
292
  uploadZone.addEventListener('click', () => fileInput.click());
293
  uploadZone.addEventListener('dragover', (e) => {
294
  e.preventDefault();
@@ -304,21 +338,13 @@
304
  handleFileSelection(e.dataTransfer.files[0]);
305
  }
306
  });
307
-
308
- // File Input Change
309
  fileInput.addEventListener('change', (e) => {
310
  if (e.target.files.length) {
311
  handleFileSelection(e.target.files[0]);
312
  }
313
  });
314
-
315
- // Remove File Button
316
  removeFileButton.addEventListener('click', resetUI);
317
-
318
- // Submit Button Click
319
  submitButton.addEventListener('click', handleSubmit);
320
-
321
- // Copy Button Click
322
  copyAnalysisButton.addEventListener('click', copyAnalysisToClipboard);
323
 
324
 
@@ -326,11 +352,14 @@
326
 
327
  function handleFileSelection(file) {
328
  const fileType = document.querySelector('input[name="fileType"]:checked').value;
329
- const maxFileSize = 16 * 1024 * 1024; // 16 MB
330
 
331
- // Basic Validation (Type based on selection, Size)
332
  if (file.size > maxFileSize) {
333
- alert(`Le fichier est trop volumineux (${(file.size / 1024 / 1024).toFixed(1)} Mo). La taille maximale est de 16 Mo.`);
 
 
 
 
334
  resetUI();
335
  return;
336
  }
@@ -339,18 +368,24 @@
339
  const allowedTextTypes = ['text/plain', 'application/pdf'];
340
 
341
  if (fileType === 'image' && !allowedImageTypes.includes(file.type)) {
342
- // Allow if no type but ends with common image extension (browser might not set type correctly)
343
  const isImageTypeByName = /\.(jpe?g|png|gif|webp)$/i.test(file.name);
344
  if (!isImageTypeByName) {
345
- alert("Type de fichier invalide. Veuillez sélectionner une image (PNG, JPG, GIF, WEBP).");
 
 
 
 
346
  resetUI();
347
  return;
348
  }
349
  } else if (fileType === 'text' && !allowedTextTypes.includes(file.type)) {
350
- // Allow if no type but ends with .txt (PDF type is usually reliable)
351
  const isTextTypeByName = /\.txt$/i.test(file.name);
352
  if (!isTextTypeByName && file.type !== 'application/pdf') {
353
- alert("Type de fichier invalide. Veuillez sélectionner un fichier texte (TXT) ou PDF.");
 
 
 
 
354
  resetUI();
355
  return;
356
  }
@@ -360,19 +395,18 @@
360
  selectedFile = file;
361
  preview.classList.remove('hidden');
362
  preview.classList.add('fade-in');
363
- results.classList.add('hidden'); // Hide previous results
364
- analysisContent.innerHTML = '<p class="text-gray-500">L\'analyse apparaîtra ici...</p>'; // Reset placeholder
365
  fileInfo.textContent = `${file.name} (${(file.size / 1024).toFixed(1)} Ko)`;
366
  removeFileButton.classList.remove('hidden');
367
 
368
- // Show preview based on selected type
369
  if (fileType === 'image') {
370
  imagePreview.classList.remove('hidden');
371
  textPreview.classList.add('hidden');
372
  const reader = new FileReader();
373
  reader.onload = (e) => imagePreview.src = e.target.result;
374
  reader.readAsDataURL(file);
375
- } else { // text
376
  imagePreview.classList.add('hidden');
377
  textPreview.classList.remove('hidden');
378
  if (file.type === 'application/pdf') {
@@ -383,13 +417,12 @@
383
  reader.readAsText(file);
384
  }
385
  }
386
-
387
- submitButton.disabled = false; // Enable submit button
388
  }
389
 
390
  function handleSubmit() {
391
  if (!selectedFile) {
392
- alert("Veuillez sélectionner un fichier.");
393
  return;
394
  }
395
 
@@ -399,20 +432,17 @@
399
  formData.append('fileType', fileType);
400
 
401
  showLoading(true);
402
- results.classList.add('hidden'); // Hide old results before new request
403
 
404
- // *** THE ACTUAL FETCH CALL ***
405
  fetch('/upload', {
406
  method: 'POST',
407
  body: formData
408
  })
409
  .then(response => {
410
  if (!response.ok) {
411
- // Try to get error message from backend JSON response
412
  return response.json().then(errData => {
413
  throw new Error(errData.error || `Erreur HTTP: ${response.status}`);
414
  }).catch(() => {
415
- // Fallback if response is not JSON or doesn't have 'error' key
416
  throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`);
417
  });
418
  }
@@ -423,63 +453,87 @@
423
  if (data.success && data.analysis) {
424
  results.classList.remove('hidden');
425
  results.classList.add('slide-up');
426
- // Use marked to parse the Markdown response
427
  analysisContent.innerHTML = marked.parse(data.analysis);
428
- // Re-apply Prism highlighting AFTER content is added
429
- Prism.highlightAllUnder(analysisContent);
430
- // Optional: Scroll to results
 
 
 
 
 
 
 
 
 
 
431
  results.scrollIntoView({ behavior: 'smooth', block: 'start' });
432
  } else {
433
- // Handle cases where backend responds with success:false or missing analysis
434
  throw new Error(data.error || "L'analyse n'a pas pu être générée.");
435
  }
436
- // Decide if you want to reset after success
437
- // resetUI(); // Or keep the file selected
438
  })
439
  .catch(error => {
440
  showLoading(false);
441
- // Display error message to the user
442
- analysisContent.innerHTML = `<p class="text-red-600 font-medium">Erreur lors de l'analyse :</p><p class="text-red-500 text-sm">${error.message}</p>`;
443
- results.classList.remove('hidden'); // Show the results area to display the error
 
 
 
 
444
  console.error('Error during analysis:', error);
445
- // Don't reset the file input on error, allow retry
446
- submitButton.disabled = false; // Re-enable button on error
447
  });
448
- // *** END OF FETCH CALL ***
449
  }
450
 
451
  function copyAnalysisToClipboard() {
452
  const analysisHtml = analysisContent.innerHTML;
453
- // Convert HTML to plain text for better clipboard compatibility
 
 
 
 
454
  const tempDiv = document.createElement('div');
455
  tempDiv.innerHTML = analysisHtml;
456
- // Basic text extraction, might need refinement depending on Markdown complexity
457
  let textToCopy = tempDiv.textContent || tempDiv.innerText || "";
458
 
459
- // Attempt to preserve some Markdown structure (like line breaks)
460
  textToCopy = analysisHtml
461
- .replace(/<br\s*\/?>/gi, '\n') // HTML breaks to newlines
462
- .replace(/<\/p>/gi, '\n') // End of paragraphs to newlines
463
- .replace(/<\/li>/gi, '\n') // End of list items to newlines
464
- .replace(/<\/(h[1-6])>/gi, '\n\n') // Headers get double newline
465
- .replace(/<[^>]+>/g, '') // Remove remaining HTML tags
466
- .replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&') // Decode HTML entities
467
- .trim(); // Trim whitespace
 
468
 
469
  navigator.clipboard.writeText(textToCopy)
470
  .then(() => {
471
- alert('Analyse copiée dans le presse-papiers !');
 
 
 
 
 
 
 
472
  })
473
  .catch(err => {
474
  console.error('Erreur de copie: ', err);
475
- alert('Impossible de copier l\'analyse.');
 
 
 
 
 
476
  });
477
  }
478
 
479
 
480
  // --- Initial Setup ---
481
- updateAcceptAttribute(); // Set initial accept value
482
- resetUI(); // Start with a clean state
483
 
484
  }); // End DOMContentLoaded
485
  </script>
 
6
  <title>Mariam Espagnol - Analyse de Documents</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://unpkg.com/[email protected]/marked.min.js"></script>
9
+ <!-- SweetAlert2 -->
10
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
11
+ <!-- PrismJS Core & Theme -->
12
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/prism.min.js" integrity="sha512-7Z9J3l1+EYfeaPKcGXu3MS/7SluIYINAaicZN83z9/9XjUhIYU/YHwZxpTBIlXgy9XEOXRJW1QQkAcLpbzm7hA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
13
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/themes/prism-tomorrow.min.css" integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXOyEVrd0XB9aLhtFOUUjLz90GzvnBCgXWLSntyo7w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
14
+ <!-- PrismJS Languages (Load components individually if needed, or use autoloader) -->
15
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-core.min.js" integrity="sha512-9khQRAUBYEJDCDVP2ywQ0LRUbnjL3ZfrPJorj7MF8+KEvn3chLJniiG9LUDXTQGshyrGXxGzvSgKyYad7is+7Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
16
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-GP4x8UWxWyh4BMbyJGOGneiTbUdnpcBtDbJcdM8XcSzaHjMTzOL/zENvu6QRGxzNssVSKHncmXbvH/SsqR2nLw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
17
+
18
  <style>
19
  @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Poppins:wght@300;400;500;600&display=swap');
20
 
 
37
  color: transparent;
38
  }
39
  .upload-zone {
40
+ background: linear-gradient(145deg, #f9fafb, #f3f4f6);
41
+ box-shadow: 5px 5px 15px #d1d9e6, -5px -5px 15px #ffffff;
42
  transition: all 0.3s ease;
43
  }
44
+ .upload-zone.dragover {
45
+ border-color: #4f46e5;
46
+ background: #e0e7ff;
47
  transform: scale(1.02);
48
  }
49
  .waves { position: absolute; bottom: 0; left: 0; width: 100%; overflow: hidden; line-height: 0; transform: rotate(180deg); z-index: 0; }
50
  .waves svg { position: relative; display: block; width: calc(100% + 1.3px); height: 150px; }
51
+ .waves .fill-indigo-50 { fill: #eef2ff; }
52
 
53
+ /* Responsive Analysis Box & Prose */
54
+ .prose { max-width: 100%; }
55
+ .prose pre[class*="language-"] { /* Target only Prism <pre> blocks */
56
+ background-color: #2d2d2d !important; /* Match Prism Tomorrow, use !important if needed */
 
57
  color: #ccc;
58
  padding: 1em;
59
+ margin: 1.5em 0;
60
+ overflow-x: auto;
61
+ border-radius: 0.375rem;
62
+ border: 1px solid #444; /* Subtle border */
63
  }
64
+ .prose code[class*="language-"] { /* Target only Prism <code> blocks */
65
+ font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; /* Monospace font */
66
  color: #ccc;
67
+ background: none;
68
  text-shadow: none;
69
+ font-size: 0.9em; /* Slightly smaller code font */
70
+ direction: ltr;
71
+ text-align: left;
72
+ white-space: pre;
73
+ word-spacing: normal;
74
+ word-break: normal;
75
+ line-height: 1.5;
76
+ -moz-tab-size: 4;
77
+ -o-tab-size: 4;
78
+ tab-size: 4;
79
+ -webkit-hyphens: none;
80
+ -moz-hyphens: none;
81
+ -ms-hyphens: none;
82
+ hyphens: none;
83
+ }
84
+ /* Ensure inline code also gets styled if needed, but differently */
85
+ .prose :not(pre) > code {
86
+ background-color: #f3f4f6; /* Light gray background for inline code */
87
+ color: #4b5563; /* Darker gray text */
88
+ padding: 0.2em 0.4em;
89
+ border-radius: 0.25rem;
90
+ font-size: 0.9em;
91
  }
92
  .prose h1, .prose h2, .prose h3 { color: #1F2937; margin-top: 1.5em; margin-bottom: 0.8em; padding-bottom: 0.3em; border-bottom: 1px solid #e5e7eb; }
93
  .prose p { margin-bottom: 1.25em; line-height: 1.7; }
94
  .prose ul, .prose ol { margin-left: 1.5em; margin-bottom: 1.25em; }
95
+ .prose li > p { margin-bottom: 0.5em; }
96
+ /* Button disabled state */
97
  button:disabled {
98
  opacity: 0.5;
99
  cursor: not-allowed;
100
+ background-color: #a5b4fc;
101
  }
102
+ /* Fix potential Prism theme override from Tailwind */
103
  :not(pre) > code[class*="language-"], pre[class*="language-"] {
104
+ background: #2d2d2d;
105
  }
106
  </style>
107
  </head>
108
+ <body class="bg-gradient-to-br from-gray-50 to-gray-100 min-h-screen relative overflow-x-hidden">
109
  <div class="waves">
110
  <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
111
  <path d="M321.39,56.44c58-10.79,114.16-30.13,172-41.86,82.39-16.72,168.19-17.73,250.45-.39C823.78,31,906.67,72,985.66,92.83c70.05,18.48,146.53,26.09,214.34,3V0H0V27.35A600.21,600.21,0,0,0,321.39,56.44Z" class="fill-indigo-50"></path>
112
  </svg>
113
  </div>
114
 
115
+ <div class="max-w-4xl mx-auto px-4 py-12 relative z-10">
116
  <!-- Header -->
117
+ <header class="text-center mb-12 fade-in">
118
  <h1 class="text-4xl md:text-5xl font-bold mb-3 font-['Playfair_Display'] gradient-text">
119
  Mariam Espagnol
120
  </h1>
 
148
  <div class="mb-6">
149
  <label class="block text-base font-medium text-gray-700 mb-3">2. Sélectionnez votre fichier</label>
150
  <div id="upload-zone" class="upload-zone border-2 border-dashed border-gray-300 rounded-xl p-6 text-center cursor-pointer transition-all duration-300 relative overflow-hidden">
151
+ <input id="file-upload" name="file" type="file" class="sr-only" accept="image/*">
152
  <div class="space-y-3">
153
  <div class="w-16 h-16 mx-auto rounded-full bg-indigo-100 flex items-center justify-center border-4 border-white shadow-sm">
154
  <svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
 
170
  <!-- Preview -->
171
  <div id="preview" class="mt-6 hidden slide-up">
172
  <h3 class="text-base font-medium text-gray-800 mb-3">Aperçu</h3>
173
+ <div class="preview-container border rounded-lg p-4 bg-gray-50 max-h-72 overflow-auto relative">
174
+ <img id="image-preview" class="max-w-full h-auto hidden rounded block mx-auto" alt="Aperçu Image">
175
  <pre id="text-preview" class="text-sm text-gray-700 whitespace-pre-wrap hidden bg-white p-3 rounded shadow-inner"></pre>
176
+ <p id="file-info" class="text-xs text-gray-500 mt-2 text-center"></p>
177
  <button id="remove-file-button" class="absolute top-2 right-2 bg-red-100 text-red-600 hover:bg-red-200 rounded-full p-1 text-xs hidden" title="Retirer le fichier">
178
  <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
179
  <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
 
189
  class="bg-indigo-600 text-white font-medium py-2.5 px-6 rounded-lg shadow hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition duration-150 ease-in-out disabled:opacity-50 disabled:cursor-not-allowed disabled:bg-indigo-300">
190
  <span id="submit-button-text">3. Lancer l'analyse</span>
191
  <span id="submit-button-spinner" class="hidden">
192
+ <svg class="animate-spin inline-block -ml-1 mr-2 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
193
  <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
194
  <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>
195
  </svg>
 
199
  </div>
200
 
201
  <!-- Analysis Results -->
202
+ <div id="results" class="mt-10 hidden slide-up">
203
  <h3 class="text-lg font-semibold text-gray-900 mb-4 border-b pb-2">Analyse détaillée</h3>
 
204
  <div class="bg-gray-50 rounded-lg p-4 md:p-6 shadow-inner overflow-x-auto border border-gray-200">
205
+ <!-- Applying prose styles here -->
206
  <div id="analysis-content" class="prose prose-sm sm:prose-base max-w-none prose-indigo">
207
+ <p class="text-gray-500">L'analyse apparaîtra ici...</p>
 
208
  </div>
209
  </div>
210
  <div class="mt-4 text-right">
 
221
 
222
  </div> <!-- End max-width container -->
223
 
 
 
 
 
 
224
  <script>
225
  document.addEventListener('DOMContentLoaded', function() {
226
  const uploadZone = document.getElementById('upload-zone');
 
236
  const results = document.getElementById('results');
237
  const analysisContent = document.getElementById('analysis-content');
238
  const copyAnalysisButton = document.getElementById('copy-analysis-button');
 
239
  const fileTypeRadios = document.querySelectorAll('.file-type-radio');
240
  const fileTypesInfo = document.getElementById('file-types-info');
241
 
242
  let selectedFile = null;
243
 
244
+ // Configure marked with Prism check
245
  marked.setOptions({
246
+ breaks: true,
247
+ gfm: true,
248
+ headerIds: false,
249
+ mangle: false,
250
  highlight: function(code, lang) {
251
+ // ** Check if Prism and the language are loaded **
252
+ if (typeof Prism !== 'undefined' && Prism.languages[lang]) {
253
+ try {
254
+ return Prism.highlight(code, Prism.languages[lang], lang);
255
+ } catch (error) {
256
+ console.warn(`Prism highlighting failed for language ${lang}:`, error)
257
+ return code; // Return unhighlighted on error
258
+ }
259
  }
260
+ // ** Fallback if Prism or language not available **
261
+ return code;
262
  }
263
  });
264
 
 
271
  } else {
272
  submitButtonText.classList.remove('hidden');
273
  submitButtonSpinner.classList.add('hidden');
274
+ submitButton.disabled = (selectedFile === null);
275
  }
276
  }
277
 
278
+ function resetUI() {
279
  selectedFile = null;
280
+ fileInput.value = '';
281
  preview.classList.add('hidden');
282
  imagePreview.classList.add('hidden');
283
  textPreview.classList.add('hidden');
284
+ imagePreview.src = '#';
285
  textPreview.textContent = '';
286
  fileInfo.textContent = '';
287
  removeFileButton.classList.add('hidden');
288
  results.classList.add('hidden');
289
+ analysisContent.innerHTML = '<p class="text-gray-500">L\'analyse apparaîtra ici...</p>';
290
  submitButton.disabled = true;
291
+ showLoading(false);
292
+ updateAcceptAttribute();
293
  }
294
 
295
  function updateAcceptAttribute() {
 
297
  if (selectedType === 'image') {
298
  fileInput.accept = "image/png, image/jpeg, image/gif, image/webp";
299
  fileTypesInfo.textContent = "Images (PNG, JPG, GIF, WEBP) - Max 16MB";
300
+ } else {
301
+ fileInput.accept = "text/plain, application/pdf, .txt";
302
  fileTypesInfo.textContent = "Textes (TXT, PDF lisible) - Max 16MB";
303
  }
 
304
  if (selectedFile) {
305
+ const currentFileTypeMatchesSelection =
306
+ (selectedType === 'image' && selectedFile.type.startsWith('image/')) ||
307
+ (selectedType === 'text' && (selectedFile.type === 'text/plain' || selectedFile.type === 'application/pdf' || selectedFile.name.endsWith('.txt')));
308
+
309
+ if(!currentFileTypeMatchesSelection) {
310
+ resetUI();
311
+ // Use SweetAlert for this message too
312
+ Swal.fire({
313
+ icon: 'warning',
314
+ title: 'Type de fichier changé',
315
+ text: 'Le type de document a été modifié. Veuillez resélectionner votre fichier.',
316
+ });
317
+ }
318
  }
319
  }
320
 
321
 
322
  // --- Event Listeners ---
 
 
323
  fileTypeRadios.forEach(radio => {
324
  radio.addEventListener('change', updateAcceptAttribute);
325
  });
 
 
326
  uploadZone.addEventListener('click', () => fileInput.click());
327
  uploadZone.addEventListener('dragover', (e) => {
328
  e.preventDefault();
 
338
  handleFileSelection(e.dataTransfer.files[0]);
339
  }
340
  });
 
 
341
  fileInput.addEventListener('change', (e) => {
342
  if (e.target.files.length) {
343
  handleFileSelection(e.target.files[0]);
344
  }
345
  });
 
 
346
  removeFileButton.addEventListener('click', resetUI);
 
 
347
  submitButton.addEventListener('click', handleSubmit);
 
 
348
  copyAnalysisButton.addEventListener('click', copyAnalysisToClipboard);
349
 
350
 
 
352
 
353
  function handleFileSelection(file) {
354
  const fileType = document.querySelector('input[name="fileType"]:checked').value;
355
+ const maxFileSize = 16 * 1024 * 1024;
356
 
 
357
  if (file.size > maxFileSize) {
358
+ Swal.fire({ // Use SweetAlert
359
+ icon: 'error',
360
+ title: 'Fichier trop volumineux',
361
+ text: `La taille maximale autorisée est de 16 Mo. Votre fichier fait ${(file.size / 1024 / 1024).toFixed(1)} Mo.`,
362
+ });
363
  resetUI();
364
  return;
365
  }
 
368
  const allowedTextTypes = ['text/plain', 'application/pdf'];
369
 
370
  if (fileType === 'image' && !allowedImageTypes.includes(file.type)) {
 
371
  const isImageTypeByName = /\.(jpe?g|png|gif|webp)$/i.test(file.name);
372
  if (!isImageTypeByName) {
373
+ Swal.fire({ // Use SweetAlert
374
+ icon: 'error',
375
+ title: 'Type de fichier invalide',
376
+ text: 'Veuillez sélectionner une image (PNG, JPG, GIF, WEBP).'
377
+ });
378
  resetUI();
379
  return;
380
  }
381
  } else if (fileType === 'text' && !allowedTextTypes.includes(file.type)) {
 
382
  const isTextTypeByName = /\.txt$/i.test(file.name);
383
  if (!isTextTypeByName && file.type !== 'application/pdf') {
384
+ Swal.fire({ // Use SweetAlert
385
+ icon: 'error',
386
+ title: 'Type de fichier invalide',
387
+ text: 'Veuillez sélectionner un fichier texte (TXT) ou PDF.'
388
+ });
389
  resetUI();
390
  return;
391
  }
 
395
  selectedFile = file;
396
  preview.classList.remove('hidden');
397
  preview.classList.add('fade-in');
398
+ results.classList.add('hidden');
399
+ analysisContent.innerHTML = '<p class="text-gray-500">L\'analyse apparaîtra ici...</p>';
400
  fileInfo.textContent = `${file.name} (${(file.size / 1024).toFixed(1)} Ko)`;
401
  removeFileButton.classList.remove('hidden');
402
 
 
403
  if (fileType === 'image') {
404
  imagePreview.classList.remove('hidden');
405
  textPreview.classList.add('hidden');
406
  const reader = new FileReader();
407
  reader.onload = (e) => imagePreview.src = e.target.result;
408
  reader.readAsDataURL(file);
409
+ } else {
410
  imagePreview.classList.add('hidden');
411
  textPreview.classList.remove('hidden');
412
  if (file.type === 'application/pdf') {
 
417
  reader.readAsText(file);
418
  }
419
  }
420
+ submitButton.disabled = false;
 
421
  }
422
 
423
  function handleSubmit() {
424
  if (!selectedFile) {
425
+ Swal.fire('Aucun fichier', 'Veuillez sélectionner un fichier avant de lancer l\'analyse.', 'warning');
426
  return;
427
  }
428
 
 
432
  formData.append('fileType', fileType);
433
 
434
  showLoading(true);
435
+ results.classList.add('hidden');
436
 
 
437
  fetch('/upload', {
438
  method: 'POST',
439
  body: formData
440
  })
441
  .then(response => {
442
  if (!response.ok) {
 
443
  return response.json().then(errData => {
444
  throw new Error(errData.error || `Erreur HTTP: ${response.status}`);
445
  }).catch(() => {
 
446
  throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`);
447
  });
448
  }
 
453
  if (data.success && data.analysis) {
454
  results.classList.remove('hidden');
455
  results.classList.add('slide-up');
 
456
  analysisContent.innerHTML = marked.parse(data.analysis);
457
+
458
+ // ** Check if Prism is loaded before highlighting **
459
+ if (typeof Prism !== 'undefined') {
460
+ // Use Prism's autoloader or highlightAllUnder
461
+ // Prism.highlightAllUnder(analysisContent); // Might work with autoloader
462
+ // Or manually trigger highlighting on specific elements if autoloader fails:
463
+ analysisContent.querySelectorAll('pre code').forEach((block) => {
464
+ Prism.highlightElement(block);
465
+ });
466
+ } else {
467
+ console.warn("Prism n'est pas chargé, impossible de colorer la syntaxe.");
468
+ }
469
+
470
  results.scrollIntoView({ behavior: 'smooth', block: 'start' });
471
  } else {
 
472
  throw new Error(data.error || "L'analyse n'a pas pu être générée.");
473
  }
 
 
474
  })
475
  .catch(error => {
476
  showLoading(false);
477
+ // Use SweetAlert for error display
478
+ Swal.fire({
479
+ icon: 'error',
480
+ title: 'Erreur lors de l\'analyse',
481
+ text: error.message || 'Une erreur inconnue est survenue.',
482
+ });
483
+ // Optionally log detailed error
484
  console.error('Error during analysis:', error);
485
+ submitButton.disabled = false; // Re-enable on error
 
486
  });
 
487
  }
488
 
489
  function copyAnalysisToClipboard() {
490
  const analysisHtml = analysisContent.innerHTML;
491
+ if (!analysisHtml || analysisHtml.includes('L\'analyse apparaîtra ici...')) {
492
+ Swal.fire('Rien à copier', 'Aucune analyse n\'a été générée pour le moment.', 'info');
493
+ return;
494
+ }
495
+
496
  const tempDiv = document.createElement('div');
497
  tempDiv.innerHTML = analysisHtml;
 
498
  let textToCopy = tempDiv.textContent || tempDiv.innerText || "";
499
 
500
+ // Basic conversion for better text format
501
  textToCopy = analysisHtml
502
+ .replace(/<br\s*\/?>/gi, '\n')
503
+ .replace(/<\/p>/gi, '\n')
504
+ .replace(/<\/li>/gi, '\n')
505
+ .replace(/<\/(h[1-6])>/gi, '\n\n')
506
+ .replace(/<pre.*?><code.*?>([\s\S]*?)<\/code><\/pre>/gi, '\n```\n$1\n```\n') // Attempt to format code blocks
507
+ .replace(/<[^>]+>/g, '') // Remove remaining tags
508
+ .replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&') // Decode entities
509
+ .trim();
510
 
511
  navigator.clipboard.writeText(textToCopy)
512
  .then(() => {
513
+ // Use SweetAlert for success
514
+ Swal.fire({
515
+ icon: 'success',
516
+ title: 'Copié !',
517
+ text: 'L\'analyse a été copiée dans le presse-papiers.',
518
+ timer: 1500, // Auto-close after 1.5 seconds
519
+ showConfirmButton: false // Hide the confirmation button
520
+ });
521
  })
522
  .catch(err => {
523
  console.error('Erreur de copie: ', err);
524
+ // Use SweetAlert for error
525
+ Swal.fire({
526
+ icon: 'error',
527
+ title: 'Erreur de copie',
528
+ text: 'Impossible de copier l\'analyse automatiquement. Vous pouvez essayer de la sélectionner manuellement.',
529
+ });
530
  });
531
  }
532
 
533
 
534
  // --- Initial Setup ---
535
+ updateAcceptAttribute();
536
+ resetUI();
537
 
538
  }); // End DOMContentLoaded
539
  </script>