Docfile commited on
Commit
d8201c9
·
verified ·
1 Parent(s): cf07f0f

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +130 -0
templates/index.html ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <style>
9
+ @keyframes gradient {
10
+ 0% { background-position: 0% 50%; }
11
+ 50% { background-position: 100% 50%; }
12
+ 100% { background-position: 0% 50%; }
13
+ }
14
+ .gradient-bg {
15
+ background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
16
+ background-size: 400% 400%;
17
+ animation: gradient 15s ease infinite;
18
+ }
19
+ </style>
20
+ </head>
21
+ <body class="min-h-screen bg-gray-50">
22
+ <div class="gradient-bg h-2 w-full fixed top-0"></div>
23
+
24
+ <div class="max-w-4xl mx-auto px-4 py-8">
25
+ <header class="text-center mb-12">
26
+ <h1 class="text-4xl font-bold text-gray-800 mb-2">Mariam M-0</h1>
27
+ <p class="text-gray-600">Votre assistant IA personnel</p>
28
+ </header>
29
+
30
+ <div class="bg-white rounded-xl shadow-lg p-6 mb-8">
31
+ <textarea
32
+ id="question"
33
+ 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"
34
+ placeholder="Posez votre question ici..."
35
+ ></textarea>
36
+ <button
37
+ id="submitBtn"
38
+ 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"
39
+ >
40
+ <span>Obtenir une réponse</span>
41
+ <div id="spinner" class="hidden ml-3 animate-spin rounded-full h-5 w-5 border-b-2 border-white"></div>
42
+ </button>
43
+ </div>
44
+
45
+ <div id="responseContainer" class="space-y-6">
46
+ <div id="answerBox" class="hidden bg-white rounded-xl shadow-lg p-6">
47
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">Réponse</h2>
48
+ <div id="answer" class="text-gray-700 prose prose-sm max-w-none"></div>
49
+ </div>
50
+
51
+ <div id="thinkingBox" class="hidden bg-white rounded-xl shadow-lg p-6">
52
+ <div class="flex items-center justify-between mb-4">
53
+ <h2 class="text-xl font-semibold text-gray-800">Raisonnement</h2>
54
+ <button id="toggleThinking" class="text-blue-500 hover:text-blue-600">
55
+ Afficher
56
+ </button>
57
+ </div>
58
+ <div id="thinking" class="hidden text-gray-600 prose prose-sm max-w-none"></div>
59
+ </div>
60
+ </div>
61
+ </div>
62
+
63
+ <script>
64
+ const submitBtn = document.getElementById('submitBtn');
65
+ const spinner = document.getElementById('spinner');
66
+ const answerBox = document.getElementById('answerBox');
67
+ const thinkingBox = document.getElementById('thinkingBox');
68
+ const answer = document.getElementById('answer');
69
+ const thinking = document.getElementById('thinking');
70
+ const toggleThinking = document.getElementById('toggleThinking');
71
+
72
+ toggleThinking.addEventListener('click', () => {
73
+ const isHidden = thinking.classList.contains('hidden');
74
+ thinking.classList.toggle('hidden');
75
+ toggleThinking.textContent = isHidden ? 'Masquer' : 'Afficher';
76
+ });
77
+
78
+ submitBtn.addEventListener('click', async () => {
79
+ const question = document.getElementById('question').value;
80
+ if (!question.trim()) return;
81
+
82
+ // Reset UI
83
+ answer.textContent = '';
84
+ thinking.textContent = '';
85
+ submitBtn.disabled = true;
86
+ spinner.classList.remove('hidden');
87
+ answerBox.classList.add('hidden');
88
+ thinkingBox.classList.add('hidden');
89
+
90
+ try {
91
+ const response = await fetch('/ask', {
92
+ method: 'POST',
93
+ headers: {
94
+ 'Content-Type': 'application/json',
95
+ },
96
+ body: JSON.stringify({ question }),
97
+ });
98
+
99
+ const reader = response.body.getReader();
100
+ const decoder = new TextDecoder();
101
+
102
+ while (true) {
103
+ const { done, value } = await reader.read();
104
+ if (done) break;
105
+
106
+ const chunks = decoder.decode(value).split('\n');
107
+ chunks.forEach(chunk => {
108
+ if (!chunk) return;
109
+
110
+ const data = JSON.parse(chunk);
111
+ if (data.type === 'thinking') {
112
+ thinkingBox.classList.remove('hidden');
113
+ thinking.textContent = data.content;
114
+ } else if (data.type === 'answer') {
115
+ answerBox.classList.remove('hidden');
116
+ answer.textContent = data.content;
117
+ }
118
+ });
119
+ }
120
+ } catch (error) {
121
+ console.error('Error:', error);
122
+ answer.textContent = "Une erreur est survenue. Veuillez réessayer.";
123
+ } finally {
124
+ submitBtn.disabled = false;
125
+ spinner.classList.add('hidden');
126
+ }
127
+ });
128
+ </script>
129
+ </body>
130
+ </html>