Docfile commited on
Commit
6bbd77b
·
verified ·
1 Parent(s): f850b88

Update templates/index.html

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