Docfile commited on
Commit
b809fdd
·
verified ·
1 Parent(s): b80baf0

Create index.html

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