Docfile commited on
Commit
928e77d
·
verified ·
1 Parent(s): 3c62ec1

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +182 -0
templates/index.html ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 AI</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
9
+ <style>
10
+ .message-transition {
11
+ transition: all 0.3s ease-in-out;
12
+ }
13
+ .gradient-background {
14
+ background: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
15
+ }
16
+ </style>
17
+ </head>
18
+ <body class="bg-gray-50 min-h-screen">
19
+ <div class="container mx-auto px-4 py-8 max-w-4xl">
20
+ <!-- Header -->
21
+ <div class="text-center mb-8">
22
+ <h1 class="text-4xl font-bold text-gray-800 mb-2">Mariam AI</h1>
23
+ <p class="text-gray-600">Votre assistant intelligent personnel</p>
24
+ </div>
25
+
26
+ <!-- Settings Panel -->
27
+ <div class="mb-6 p-4 bg-white rounded-lg shadow-md">
28
+ <div class="flex items-center justify-between">
29
+ <div class="flex items-center space-x-4">
30
+ <label class="flex items-center space-x-2 cursor-pointer">
31
+ <input type="checkbox" id="webSearchToggle" class="form-checkbox h-5 w-5 text-blue-600">
32
+ <span class="text-gray-700">Activer la recherche web</span>
33
+ </label>
34
+ </div>
35
+ <div class="relative">
36
+ <input type="file" id="fileInput" class="hidden" accept="image/*,.pdf,.txt">
37
+ <button onclick="document.getElementById('fileInput').click()" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition duration-200">
38
+ <i class="fas fa-upload mr-2"></i>Télécharger un fichier
39
+ </button>
40
+ </div>
41
+ </div>
42
+ </div>
43
+
44
+ <!-- Chat Container -->
45
+ <div class="bg-white rounded-lg shadow-md h-[600px] flex flex-col">
46
+ <!-- Messages Area -->
47
+ <div id="chatMessages" class="flex-1 overflow-y-auto p-4 space-y-4">
48
+ <!-- Messages will be inserted here -->
49
+ </div>
50
+
51
+ <!-- Input Area -->
52
+ <div class="border-t p-4">
53
+ <form id="chatForm" class="flex space-x-2">
54
+ <input type="text" id="messageInput" class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:border-blue-500" placeholder="Posez votre question...">
55
+ <button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded-lg transition duration-200">
56
+ <i class="fas fa-paper-plane"></i>
57
+ </button>
58
+ </form>
59
+ </div>
60
+ </div>
61
+ </div>
62
+
63
+ <script>
64
+ let currentFile = null;
65
+
66
+ document.getElementById('fileInput').addEventListener('change', async (e) => {
67
+ const file = e.target.files[0];
68
+ if (!file) return;
69
+
70
+ const formData = new FormData();
71
+ formData.append('file', file);
72
+
73
+ try {
74
+ const response = await fetch('/upload', {
75
+ method: 'POST',
76
+ body: formData
77
+ });
78
+ const data = await response.json();
79
+
80
+ if (data.success) {
81
+ currentFile = data.filename;
82
+ alert('Fichier téléchargé avec succès !');
83
+ } else {
84
+ alert('Erreur lors du téléchargement du fichier');
85
+ }
86
+ } catch (error) {
87
+ console.error('Error:', error);
88
+ alert('Erreur lors du téléchargement du fichier');
89
+ }
90
+ });
91
+
92
+ document.getElementById('chatForm').addEventListener('submit', async (e) => {
93
+ e.preventDefault();
94
+
95
+ const messageInput = document.getElementById('messageInput');
96
+ const message = messageInput.value.trim();
97
+ if (!message) return;
98
+
99
+ // Add user message to chat
100
+ addMessage('user', message);
101
+ messageInput.value = '';
102
+
103
+ // Show typing indicator
104
+ addTypingIndicator();
105
+
106
+ try {
107
+ const response = await fetch('/chat', {
108
+ method: 'POST',
109
+ headers: {
110
+ 'Content-Type': 'application/json',
111
+ },
112
+ body: JSON.stringify({
113
+ message: message,
114
+ web_search: document.getElementById('webSearchToggle').checked,
115
+ file: currentFile
116
+ }),
117
+ });
118
+
119
+ const data = await response.json();
120
+
121
+ // Remove typing indicator
122
+ removeTypingIndicator();
123
+
124
+ if (data.error) {
125
+ addMessage('assistant', `Erreur: ${data.error}`);
126
+ } else {
127
+ addMessage('assistant', data.response);
128
+ }
129
+
130
+ // Reset current file
131
+ currentFile = null;
132
+ } catch (error) {
133
+ removeTypingIndicator();
134
+ addMessage('assistant', 'Désolé, une erreur est survenue.');
135
+ }
136
+ });
137
+
138
+ function addMessage(role, content) {
139
+ const messagesContainer = document.getElementById('chatMessages');
140
+ const messageDiv = document.createElement('div');
141
+ messageDiv.className = `flex ${role === 'user' ? 'justify-end' : 'justify-start'} message-transition`;
142
+
143
+ const messageBubble = document.createElement('div');
144
+ messageBubble.className = `max-w-[70%] p-3 rounded-lg ${
145
+ role === 'user'
146
+ ? 'bg-blue-500 text-white rounded-br-none'
147
+ : 'bg-gray-100 text-gray-800 rounded-bl-none'
148
+ }`;
149
+ messageBubble.textContent = content;
150
+
151
+ messageDiv.appendChild(messageBubble);
152
+ messagesContainer.appendChild(messageDiv);
153
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
154
+ }
155
+
156
+ function addTypingIndicator() {
157
+ const messagesContainer = document.getElementById('chatMessages');
158
+ const indicatorDiv = document.createElement('div');
159
+ indicatorDiv.id = 'typingIndicator';
160
+ indicatorDiv.className = 'flex justify-start message-transition';
161
+ indicatorDiv.innerHTML = `
162
+ <div class="bg-gray-100 p-3 rounded-lg rounded-bl-none">
163
+ <div class="flex space-x-2">
164
+ <div class="w-2 h-2 bg-gray-400 rounded-full animate-bounce"></div>
165
+ <div class="w-2 h-2 bg-gray-400 rounded-full animate-bounce" style="animation-delay: 0.2s"></div>
166
+ <div class="w-2 h-2 bg-gray-400 rounded-full animate-bounce" style="animation-delay: 0.4s"></div>
167
+ </div>
168
+ </div>
169
+ `;
170
+ messagesContainer.appendChild(indicatorDiv);
171
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
172
+ }
173
+
174
+ function removeTypingIndicator() {
175
+ const indicator = document.getElementById('typingIndicator');
176
+ if (indicator) {
177
+ indicator.remove();
178
+ }
179
+ }
180
+ </script>
181
+ </body>
182
+ </html>