Spaces:
Running
Running
Upload philosophie.html
Browse files- templates/philosophie.html +65 -52
templates/philosophie.html
CHANGED
|
@@ -110,7 +110,6 @@
|
|
| 110 |
font-size: 0.875em;
|
| 111 |
}
|
| 112 |
|
| 113 |
-
|
| 114 |
.active, .collapsible:hover {
|
| 115 |
background-color: #ddd;
|
| 116 |
}
|
|
@@ -186,7 +185,6 @@
|
|
| 186 |
padding: 0.5rem 0.75rem;
|
| 187 |
}
|
| 188 |
|
| 189 |
-
|
| 190 |
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable{
|
| 191 |
background-color: #ede9fe;
|
| 192 |
color:#374151;
|
|
@@ -289,7 +287,6 @@
|
|
| 289 |
</div>
|
| 290 |
</div>
|
| 291 |
|
| 292 |
-
|
| 293 |
<!-- Question Input -->
|
| 294 |
<div class="space-y-3">
|
| 295 |
<label class="block text-sm font-medium text-gray-700">Sujet de dissertation</label>
|
|
@@ -490,38 +487,38 @@
|
|
| 490 |
|
| 491 |
});
|
| 492 |
|
| 493 |
-
|
| 494 |
-
|
| 495 |
const question = $('#question').val().trim();
|
| 496 |
|
| 497 |
if (!question) {
|
| 498 |
-
// Gestion de l'erreur si la question est vide
|
| 499 |
return;
|
| 500 |
}
|
| 501 |
|
| 502 |
// Animation de chargement sophistiquée
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
</div>
|
| 512 |
-
</div>
|
| 513 |
-
<div class="text-gray-600">
|
| 514 |
-
<p class="animate-pulse">Analyse philosophique en cours...</p>
|
| 515 |
-
<p class="text-sm mt-2 text-gray-500">Veuillez patienter quelques instants</p>
|
| 516 |
</div>
|
| 517 |
</div>
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
const data = {
|
| 527 |
question: question,
|
|
@@ -529,43 +526,59 @@
|
|
| 529 |
courseId: $('#course-select').val() || null
|
| 530 |
};
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
method: 'POST',
|
| 535 |
-
contentType: 'application/json',
|
| 536 |
-
data: JSON.stringify(data),
|
| 537 |
-
success: function(data) {
|
| 538 |
-
Swal.close();
|
| 539 |
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
$('#copy-btn').removeClass('hidden').addClass('animate-slideUp');
|
| 545 |
|
| 546 |
-
|
| 547 |
-
|
| 548 |
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
timer: 2000
|
| 553 |
-
});
|
| 554 |
-
},
|
| 555 |
-
error: function() {
|
| 556 |
-
Swal.fire({
|
| 557 |
icon: 'error',
|
| 558 |
title: 'Erreur de génération',
|
| 559 |
-
text:
|
| 560 |
customClass: {
|
| 561 |
popup: 'rounded-2xl',
|
| 562 |
confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'
|
| 563 |
}
|
| 564 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
}
|
| 566 |
-
}
|
| 567 |
-
});
|
| 568 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
|
| 570 |
function saveDissertation(title, content) {
|
| 571 |
let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];
|
|
@@ -727,7 +740,7 @@
|
|
| 727 |
Toast.fire({
|
| 728 |
icon: 'error',
|
| 729 |
title: 'Erreur de copie',
|
| 730 |
-
|
| 731 |
timer: 3000
|
| 732 |
});
|
| 733 |
}
|
|
|
|
| 110 |
font-size: 0.875em;
|
| 111 |
}
|
| 112 |
|
|
|
|
| 113 |
.active, .collapsible:hover {
|
| 114 |
background-color: #ddd;
|
| 115 |
}
|
|
|
|
| 185 |
padding: 0.5rem 0.75rem;
|
| 186 |
}
|
| 187 |
|
|
|
|
| 188 |
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable{
|
| 189 |
background-color: #ede9fe;
|
| 190 |
color:#374151;
|
|
|
|
| 287 |
</div>
|
| 288 |
</div>
|
| 289 |
|
|
|
|
| 290 |
<!-- Question Input -->
|
| 291 |
<div class="space-y-3">
|
| 292 |
<label class="block text-sm font-medium text-gray-700">Sujet de dissertation</label>
|
|
|
|
| 487 |
|
| 488 |
});
|
| 489 |
|
| 490 |
+
// Gestion de la soumission avec streaming
|
| 491 |
+
$('#submit-btn').click(function() {
|
| 492 |
const question = $('#question').val().trim();
|
| 493 |
|
| 494 |
if (!question) {
|
| 495 |
+
// Gestion de l'erreur si la question est vide
|
| 496 |
return;
|
| 497 |
}
|
| 498 |
|
| 499 |
// Animation de chargement sophistiquée
|
| 500 |
+
Swal.fire({
|
| 501 |
+
title: 'Génération en cours',
|
| 502 |
+
html: `
|
| 503 |
+
<div class="space-y-4">
|
| 504 |
+
<div class="flex justify-center">
|
| 505 |
+
<div class="w-16 h-16 relative">
|
| 506 |
+
<div class="absolute inset-0 rounded-full border-4 border-violet-200 animate-ping"></div>
|
| 507 |
+
<div class="absolute inset-0 rounded-full border-4 border-violet-500 animate-pulse"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
</div>
|
| 509 |
</div>
|
| 510 |
+
<div class="text-gray-600">
|
| 511 |
+
<p class="animate-pulse">Analyse philosophique en cours...</p>
|
| 512 |
+
<p class="text-sm mt-2 text-gray-500">Veuillez patienter quelques instants</p>
|
| 513 |
+
</div>
|
| 514 |
+
</div>
|
| 515 |
+
`,
|
| 516 |
+
allowOutsideClick: false,
|
| 517 |
+
showConfirmButton: false,
|
| 518 |
+
customClass: {
|
| 519 |
+
popup: 'rounded-2xl'
|
| 520 |
+
}
|
| 521 |
+
});
|
| 522 |
|
| 523 |
const data = {
|
| 524 |
question: question,
|
|
|
|
| 526 |
courseId: $('#course-select').val() || null
|
| 527 |
};
|
| 528 |
|
| 529 |
+
// Utilisation de EventSource pour le streaming
|
| 530 |
+
const source = new EventSource('/submit_philo?data=' + encodeURIComponent(JSON.stringify(data)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
|
| 532 |
+
let fullResponse = '';
|
| 533 |
+
$('#response > div').html(''); // Effacer le contenu précédent
|
| 534 |
+
$('#response').removeClass('hidden').addClass('animate-fadeIn');
|
| 535 |
+
$('#copy-btn').removeClass('hidden').addClass('animate-slideUp');
|
|
|
|
| 536 |
|
| 537 |
+
source.onmessage = function(event) {
|
| 538 |
+
const parsedData = JSON.parse(event.data);
|
| 539 |
|
| 540 |
+
if (parsedData.error) {
|
| 541 |
+
source.close();
|
| 542 |
+
Swal.fire({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
icon: 'error',
|
| 544 |
title: 'Erreur de génération',
|
| 545 |
+
text: parsedData.error,
|
| 546 |
customClass: {
|
| 547 |
popup: 'rounded-2xl',
|
| 548 |
confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'
|
| 549 |
}
|
| 550 |
});
|
| 551 |
+
} else {
|
| 552 |
+
fullResponse += parsedData.response;
|
| 553 |
+
const htmlContent = marked.parse(fullResponse);
|
| 554 |
+
$('#response > div').html(htmlContent);
|
| 555 |
}
|
| 556 |
+
};
|
|
|
|
| 557 |
|
| 558 |
+
source.onerror = function(err) {
|
| 559 |
+
console.error("EventSource failed:", err);
|
| 560 |
+
source.close();
|
| 561 |
+
Swal.fire({
|
| 562 |
+
icon: 'error',
|
| 563 |
+
title: 'Erreur de connexion',
|
| 564 |
+
text: 'Une erreur est survenue lors de la connexion au serveur.',
|
| 565 |
+
customClass: {
|
| 566 |
+
popup: 'rounded-2xl',
|
| 567 |
+
confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'
|
| 568 |
+
}
|
| 569 |
+
});
|
| 570 |
+
};
|
| 571 |
+
|
| 572 |
+
source.onclose = function() {
|
| 573 |
+
Swal.close();
|
| 574 |
+
saveDissertation(question, fullResponse);
|
| 575 |
+
Toast.fire({
|
| 576 |
+
icon: 'success',
|
| 577 |
+
title: 'Dissertation générée et sauvegardée avec succès',
|
| 578 |
+
timer: 2000
|
| 579 |
+
});
|
| 580 |
+
}
|
| 581 |
+
});
|
| 582 |
|
| 583 |
function saveDissertation(title, content) {
|
| 584 |
let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];
|
|
|
|
| 740 |
Toast.fire({
|
| 741 |
icon: 'error',
|
| 742 |
title: 'Erreur de copie',
|
| 743 |
+
text: 'Impossible de copier le contenu',
|
| 744 |
timer: 3000
|
| 745 |
});
|
| 746 |
}
|