HuggyGuyJo01 commited on
Commit
c8449af
·
verified ·
1 Parent(s): 4a83a32

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +302 -19
index.html CHANGED
@@ -1,19 +1,302 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html><head><base href="https://WhatsApp/ai.com">
2
+ <title>AI-Powered WhatsApp Chat with Image Upload</title>
3
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
4
+ <meta name="theme-color" content="#075e54">
5
+ <meta name="apple-mobile-web-app-capable" content="yes">
6
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
7
+ <style>
8
+ /* Styles restent identiques */
9
+ body, html {
10
+ margin: 0;
11
+ padding: 0;
12
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
13
+ background-color: #e5ddd5;
14
+ height: 100%;
15
+ overflow: hidden;
16
+ }
17
+ #chat-container {
18
+ max-width: 100%;
19
+ height: 100%;
20
+ margin: 0 auto;
21
+ background-color: #fff;
22
+ display: flex;
23
+ flex-direction: column;
24
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.06), 0 2px 5px 0 rgba(0,0,0,.2);
25
+ }
26
+ #chat-header {
27
+ background-color: #075e54;
28
+ color: #fff;
29
+ padding: 10px;
30
+ display: flex;
31
+ align-items: center;
32
+ }
33
+ #chat-header img {
34
+ width: 40px;
35
+ height: 40px;
36
+ border-radius: 50%;
37
+ margin-right: 10px;
38
+ }
39
+ #chat-header h1 {
40
+ margin: 0;
41
+ font-size: 16px;
42
+ }
43
+ #chat-messages {
44
+ flex: 1;
45
+ overflow-y: auto;
46
+ padding: 20px;
47
+ background-image: url('https://web.whatsapp.com/img/bg-chat-tile-dark_a4be512e7195b6b733d9110b408f075d.png');
48
+ background-repeat: repeat;
49
+ }
50
+ .message {
51
+ max-width: 80%;
52
+ margin-bottom: 10px;
53
+ padding: 8px 12px;
54
+ border-radius: 7.5px;
55
+ position: relative;
56
+ }
57
+ .user-message {
58
+ background-color: #dcf8c6;
59
+ align-self: flex-end;
60
+ margin-left: auto;
61
+ }
62
+ .ai-message {
63
+ background-color: #fff;
64
+ align-self: flex-start;
65
+ }
66
+ #chat-input {
67
+ display: flex;
68
+ padding: 10px;
69
+ background-color: #f0f0f0;
70
+ }
71
+ #user-input {
72
+ flex: 1;
73
+ border: none;
74
+ padding: 10px;
75
+ border-radius: 20px;
76
+ margin-right: 10px;
77
+ }
78
+ #send-button, #file-button {
79
+ background-color: #075e54;
80
+ color: #fff;
81
+ border: none;
82
+ padding: 10px;
83
+ border-radius: 50%;
84
+ cursor: pointer;
85
+ margin-left: 5px;
86
+ display: flex;
87
+ align-items: center;
88
+ justify-content: center;
89
+ }
90
+ #send-button svg, #file-button svg {
91
+ width: 24px;
92
+ height: 24px;
93
+ fill: #fff;
94
+ }
95
+ #file-input {
96
+ display: none;
97
+ }
98
+ .message img {
99
+ max-width: 100%;
100
+ height: auto;
101
+ border-radius: 7.5px;
102
+ margin-top: 5px;
103
+ }
104
+ .typing-indicator {
105
+ padding: 8px 12px;
106
+ background-color: #fff;
107
+ border-radius: 7.5px;
108
+ margin-bottom: 10px;
109
+ display: none;
110
+ }
111
+ .typing-indicator span {
112
+ display: inline-block;
113
+ width: 8px;
114
+ height: 8px;
115
+ background-color: #90a4ae;
116
+ border-radius: 50%;
117
+ margin-right: 5px;
118
+ animation: typing 1s infinite;
119
+ }
120
+ @keyframes typing {
121
+ 0%, 100% { transform: translateY(0); }
122
+ 50% { transform: translateY(-5px); }
123
+ }
124
+ @media (min-width: 768px) {
125
+ #chat-container {
126
+ max-width: 600px;
127
+ }
128
+ }
129
+ </style>
130
+
131
+ <script>
132
+ window.CONFIG = {
133
+ companyName: 'Guy+22656888879',
134
+ apiUrl: 'https://huggyguyjo01-testbakend.hf.space',
135
+ dashboardUrl: 'https://huggyguyjo01-testdashbord.static.hf.space',
136
+ chatUrl: 'https://huggyguyjo01-testchat.static.hf.space'
137
+ };
138
+ </script>
139
+ </head>
140
+
141
+ <body>
142
+ <div id="chat-container">
143
+ <div id="chat-header">
144
+ <img src="https://cdn-icons-png.flaticon.com/512/4712/4712109.png" alt="Clipart of a customer assistant with headset">
145
+ <h1>
146
+ AI Assistant
147
+ <span style="display: inline-block; margin-left: 5px; background-color: #0099ff; color: white; font-size: 0.6em; padding: 2px 5px; border-radius: 50%; vertical-align: middle;" title="Verified AI Assistant">✓</span>
148
+ </h1>
149
+ </div>
150
+ <div id="chat-messages">
151
+ <div class="typing-indicator" id="typing-indicator">
152
+ <span></span>
153
+ <span></span>
154
+ <span></span>
155
+ </div>
156
+ </div>
157
+ <div id="chat-input">
158
+ <input type="text" id="user-input" placeholder="Type a message">
159
+ <button id="file-button">
160
+ <svg viewBox="0 0 24 24">
161
+ <path d="M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5a2.5 2.5 0 0 1 5 0v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5a2.5 2.5 0 0 0 5 0V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z"></path>
162
+ </svg>
163
+ </button>
164
+ <input type="file" id="file-input" accept="image/*">
165
+ <button id="send-button">
166
+ <svg viewBox="0 0 24 24">
167
+ <path d="M1.101 21.757 23.8 12.028 1.101 2.3l.011 7.912 13.623 1.816-13.623 1.817-.011 7.912z"></path>
168
+ </svg>
169
+ </button>
170
+ </div>
171
+ </div>
172
+
173
+ <script>
174
+ const chatMessages = document.getElementById('chat-messages');
175
+ const userInput = document.getElementById('user-input');
176
+ const sendButton = document.getElementById('send-button');
177
+ const fileButton = document.getElementById('file-button');
178
+ const fileInput = document.getElementById('file-input');
179
+ const typingIndicator = document.getElementById('typing-indicator');
180
+
181
+ // URL du backend Python
182
+ const BACKEND_URL = 'http://your-backend-url/api';
183
+
184
+ // Fonction pour afficher l'indicateur de frappe
185
+ function showTypingIndicator() {
186
+ typingIndicator.style.display = 'block';
187
+ chatMessages.scrollTop = chatMessages.scrollHeight;
188
+ }
189
+
190
+ // Fonction pour masquer l'indicateur de frappe
191
+ function hideTypingIndicator() {
192
+ typingIndicator.style.display = 'none';
193
+ }
194
+
195
+ function addMessage(content, isUser, imageData = null) {
196
+ const messageDiv = document.createElement('div');
197
+ messageDiv.classList.add('message');
198
+ messageDiv.classList.add(isUser ? 'user-message' : 'ai-message');
199
+
200
+ if (imageData) {
201
+ const img = document.createElement('img');
202
+ img.src = imageData;
203
+ img.alt = 'Uploaded image';
204
+ messageDiv.appendChild(img);
205
+ } else {
206
+ messageDiv.textContent = content;
207
+ }
208
+
209
+ chatMessages.appendChild(messageDiv);
210
+ chatMessages.scrollTop = chatMessages.scrollHeight;
211
+ }
212
+
213
+ async function sendMessageToBackend(message, imageData = null) {
214
+ try {
215
+ showTypingIndicator();
216
+
217
+ const formData = new FormData();
218
+ formData.append('message', message);
219
+ if (imageData) {
220
+ formData.append('image', imageData);
221
+ }
222
+
223
+ const response = await fetch(`${BACKEND_URL}/chat`, {
224
+ method: 'POST',
225
+ body: formData
226
+ });
227
+
228
+ if (!response.ok) {
229
+ throw new Error('Network response was not ok');
230
+ }
231
+
232
+ const data = await response.json();
233
+ hideTypingIndicator();
234
+
235
+ if (data.response) {
236
+ addMessage(data.response, false);
237
+ }
238
+ } catch (error) {
239
+ console.error('Error:', error);
240
+ hideTypingIndicator();
241
+ addMessage("Je suis désolé, une erreur s'est produite. Veuillez réessayer.", false);
242
+ }
243
+ }
244
+
245
+ async function sendMessage() {
246
+ const userMessage = userInput.value.trim();
247
+ if (!userMessage) return;
248
+
249
+ addMessage(userMessage, true);
250
+ userInput.value = '';
251
+
252
+ await sendMessageToBackend(userMessage);
253
+ }
254
+
255
+ function handleImageUpload(file) {
256
+ if (file) {
257
+ const reader = new FileReader();
258
+ reader.onload = async function(e) {
259
+ addMessage('', true, e.target.result);
260
+ await sendMessageToBackend('', file);
261
+ };
262
+ reader.readAsDataURL(file);
263
+ }
264
+ }
265
+
266
+ // Event Listeners
267
+ sendButton.addEventListener('click', sendMessage);
268
+
269
+ userInput.addEventListener('keypress', (e) => {
270
+ if (e.key === 'Enter') {
271
+ sendMessage();
272
+ }
273
+ });
274
+
275
+ fileButton.addEventListener('click', () => fileInput.click());
276
+
277
+ fileInput.addEventListener('change', (event) => {
278
+ handleImageUpload(event.target.files[0]);
279
+ });
280
+
281
+ // Gestion du drag and drop
282
+ chatMessages.addEventListener('dragover', (e) => {
283
+ e.preventDefault();
284
+ e.stopPropagation();
285
+ });
286
+
287
+ chatMessages.addEventListener('drop', (e) => {
288
+ e.preventDefault();
289
+ e.stopPropagation();
290
+ const file = e.dataTransfer.files[0];
291
+ if (file && file.type.startsWith('image/')) {
292
+ handleImageUpload(file);
293
+ }
294
+ });
295
+
296
+ // Initialisation
297
+ window.onload = () => {
298
+ // Vous pouvez ajouter ici un message de bienvenue initial si nécessaire
299
+ addMessage("Bonjour ! Je suis votre assistant virtuel. Comment puis-je vous aider aujourd'hui ?", false);
300
+ };
301
+ </script>
302
+ </body></html>