Docfile commited on
Commit
da1d472
·
verified ·
1 Parent(s): 73808fe

Create templates /index.html

Browse files
Files changed (1) hide show
  1. templates /index.html +222 -0
templates /index.html ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Mariam M-0</title>
7
+
8
+ <!-- Intégration de Tailwind CSS -->
9
+ <script defer src="https://cdn.tailwindcss.com"></script>
10
+
11
+ <!-- Marked pour le rendu Markdown -->
12
+ <script defer src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
13
+
14
+ <!-- DOMPurify pour sécuriser le rendu HTML -->
15
+ <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/purify.min.js"></script>
16
+
17
+ <!-- Highlight.js pour la coloration syntaxique -->
18
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
19
+ <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
20
+
21
+ <style>
22
+ @keyframes gradient {
23
+ 0% { background-position: 0% 50%; }
24
+ 50% { background-position: 100% 50%; }
25
+ 100% { background-position: 0% 50%; }
26
+ }
27
+ .gradient-bg {
28
+ background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
29
+ background-size: 400% 400%;
30
+ animation: gradient 15s ease infinite;
31
+ }
32
+
33
+ /* Assurer un affichage correct des espaces et retours à la ligne sur mobile */
34
+ .markdown-content {
35
+ white-space: pre-wrap;
36
+ }
37
+
38
+ /* Utilisation des directives @apply de Tailwind pour le contenu Markdown */
39
+ .markdown-content h1 { @apply text-2xl font-bold mb-4 mt-6; }
40
+ .markdown-content h2 { @apply text-xl font-bold mb-3 mt-5; }
41
+ .markdown-content h3 { @apply text-lg font-bold mb-2 mt-4; }
42
+ .markdown-content p { @apply mb-4 leading-relaxed; }
43
+ .markdown-content ul { @apply list-disc ml-6 mb-4; }
44
+ .markdown-content ol { @apply list-decimal ml-6 mb-4; }
45
+ .markdown-content li { @apply mb-1; }
46
+ .markdown-content a { @apply text-blue-600 hover:text-blue-800 underline; }
47
+ .markdown-content blockquote { @apply pl-4 border-l-4 border-gray-300 italic my-4; }
48
+ .markdown-content code:not(pre code) { @apply bg-gray-100 px-1 rounded text-sm font-mono; }
49
+ .markdown-content pre { @apply bg-gray-100 p-4 rounded-lg mb-4 overflow-x-auto; }
50
+ .markdown-content table { @apply min-w-full border border-gray-300 mb-4; }
51
+ .markdown-content th { @apply bg-gray-100 border-b border-gray-300 px-4 py-2 text-left; }
52
+ .markdown-content td { @apply border-b border-gray-300 px-4 py-2; }
53
+ .markdown-content img { @apply max-w-full h-auto my-4 rounded-lg; }
54
+ </style>
55
+ </head>
56
+ <body class="min-h-screen bg-gray-50">
57
+ <!-- Barre de gradient fixe en haut de page -->
58
+ <div class="gradient-bg h-2 w-full fixed top-0"></div>
59
+
60
+ <div class="max-w-4xl mx-auto px-4 py-8">
61
+ <header class="text-center mb-12">
62
+ <h1 class="text-4xl font-bold text-gray-800 mb-2">Mariam M-0</h1>
63
+ <p class="text-gray-600">Votre assistant IA personnel</p>
64
+ </header>
65
+
66
+ <main>
67
+ <section class="bg-white rounded-xl shadow-lg p-6 mb-8">
68
+ <textarea
69
+ id="question"
70
+ class="w-full h-32 p-4 border border-gray-200 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"
71
+ placeholder="Posez votre question ici..."
72
+ aria-label="Zone de saisie de la question"
73
+ ></textarea>
74
+ <button
75
+ id="submitBtn"
76
+ class="mt-4 px-6 py-3 bg-gradient-to-r from-blue-500 to-blue-600 text-white rounded-lg hover:from-blue-600 hover:to-blue-700 transition-all duration-200 flex items-center justify-center w-full sm:w-auto"
77
+ aria-label="Obtenir une réponse"
78
+ >
79
+ <span>Obtenir une réponse</span>
80
+ <div id="spinner" class="hidden ml-3 animate-spin rounded-full h-5 w-5 border-b-2 border-white" aria-hidden="true"></div>
81
+ </button>
82
+ </section>
83
+
84
+ <section id="responseContainer" class="space-y-6">
85
+ <article id="answerBox" class="hidden bg-white rounded-xl shadow-lg p-6">
86
+ <div class="flex items-center justify-between mb-4">
87
+ <h2 class="text-xl font-semibold text-gray-800">Réponse</h2>
88
+ <button
89
+ id="copyAnswer"
90
+ class="px-3 py-1 bg-gray-200 rounded hover:bg-gray-300 transition-colors duration-200 text-sm"
91
+ aria-label="Copier la réponse"
92
+ >
93
+ Copier
94
+ </button>
95
+ </div>
96
+ <div id="answer" class="markdown-content text-gray-700"></div>
97
+ </article>
98
+
99
+ <article id="thinkingBox" class="hidden bg-white rounded-xl shadow-lg p-6">
100
+ <div class="flex items-center justify-between mb-4">
101
+ <h2 class="text-xl font-semibold text-gray-800">Raisonnement</h2>
102
+ <button
103
+ id="toggleThinking"
104
+ class="text-blue-500 hover:text-blue-600 focus:outline-none"
105
+ aria-expanded="false"
106
+ aria-controls="thinking"
107
+ >
108
+ Afficher
109
+ </button>
110
+ </div>
111
+ <div id="thinking" class="hidden markdown-content text-gray-600"></div>
112
+ </article>
113
+ </section>
114
+ </main>
115
+ </div>
116
+
117
+ <script defer>
118
+ // Configuration de marked pour le rendu Markdown
119
+ marked.setOptions({
120
+ highlight: function(code, lang) {
121
+ if (lang && hljs.getLanguage(lang)) {
122
+ return hljs.highlight(code, { language: lang }).value;
123
+ }
124
+ return hljs.highlightAuto(code).value;
125
+ },
126
+ breaks: true,
127
+ gfm: true
128
+ });
129
+
130
+ /**
131
+ * Fonction pour rendre le Markdown de manière sécurisée.
132
+ * @param {string} content - Le contenu en Markdown.
133
+ * @returns {string} Le HTML rendu et sécurisé.
134
+ */
135
+ function renderMarkdown(content) {
136
+ const rawHtml = marked.parse(content);
137
+ return DOMPurify.sanitize(rawHtml);
138
+ }
139
+
140
+ const submitBtn = document.getElementById('submitBtn');
141
+ const spinner = document.getElementById('spinner');
142
+ const answerBox = document.getElementById('answerBox');
143
+ const thinkingBox = document.getElementById('thinkingBox');
144
+ const answer = document.getElementById('answer');
145
+ const thinking = document.getElementById('thinking');
146
+ const toggleThinking = document.getElementById('toggleThinking');
147
+ const copyAnswer = document.getElementById('copyAnswer');
148
+
149
+ toggleThinking.addEventListener('click', () => {
150
+ const isHidden = thinking.classList.contains('hidden');
151
+ thinking.classList.toggle('hidden');
152
+ toggleThinking.textContent = isHidden ? 'Masquer' : 'Afficher';
153
+ toggleThinking.setAttribute('aria-expanded', isHidden);
154
+ });
155
+
156
+ copyAnswer.addEventListener('click', () => {
157
+ const textToCopy = answer.innerText;
158
+ navigator.clipboard.writeText(textToCopy).then(() => {
159
+ copyAnswer.textContent = 'Copié';
160
+ setTimeout(() => {
161
+ copyAnswer.textContent = 'Copier';
162
+ }, 2000);
163
+ }).catch(err => {
164
+ console.error('Erreur lors de la copie :', err);
165
+ });
166
+ });
167
+
168
+ submitBtn.addEventListener('click', async () => {
169
+ const question = document.getElementById('question').value;
170
+ if (!question.trim()) return;
171
+
172
+ // Réinitialisation de l'interface utilisateur
173
+ answer.innerHTML = '';
174
+ thinking.innerHTML = '';
175
+ submitBtn.disabled = true;
176
+ spinner.classList.remove('hidden');
177
+ answerBox.classList.add('hidden');
178
+ thinkingBox.classList.add('hidden');
179
+
180
+ try {
181
+ const response = await fetch('/ask', {
182
+ method: 'POST',
183
+ headers: { 'Content-Type': 'application/json' },
184
+ body: JSON.stringify({ question })
185
+ });
186
+
187
+ // Lecture du flux de réponse en continu
188
+ const reader = response.body.getReader();
189
+ const decoder = new TextDecoder();
190
+
191
+ while (true) {
192
+ const { done, value } = await reader.read();
193
+ if (done) break;
194
+ const chunks = decoder.decode(value).split('\n');
195
+ chunks.forEach(chunk => {
196
+ if (!chunk) return;
197
+ const data = JSON.parse(chunk);
198
+ if (data.type === 'thinking') {
199
+ thinkingBox.classList.remove('hidden');
200
+ thinking.innerHTML = renderMarkdown(data.content);
201
+ } else if (data.type === 'answer') {
202
+ answerBox.classList.remove('hidden');
203
+ answer.innerHTML = renderMarkdown(data.content);
204
+ // Rafraîchissement de la coloration syntaxique pour les blocs de code
205
+ answer.querySelectorAll('pre code').forEach(block => {
206
+ hljs.highlightElement(block);
207
+ });
208
+ }
209
+ });
210
+ }
211
+ } catch (error) {
212
+ console.error('Erreur :', error);
213
+ answer.innerHTML = renderMarkdown("❌ Une erreur est survenue. Veuillez réessayer.");
214
+ answerBox.classList.remove('hidden');
215
+ } finally {
216
+ submitBtn.disabled = false;
217
+ spinner.classList.add('hidden');
218
+ }
219
+ });
220
+ </script>
221
+ </body>
222
+ </html>