zontos commited on
Commit
aaadd75
Β·
verified Β·
1 Parent(s): a133c42

create a bootstrap chatbot. it must supports :

Browse files

- light/dark version
- multirow html texteditor
- modal to choose model and history
- voice
- emoji
- upload files and images (with preview)

Files changed (2) hide show
  1. README.md +8 -5
  2. index.html +400 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Chatpal Ai Companion Bot
3
- emoji: πŸ“Š
4
- colorFrom: green
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: ChatPal - AI Companion Bot πŸ€–
3
+ colorFrom: blue
4
+ colorTo: blue
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).
index.html CHANGED
@@ -1,19 +1,401 @@
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
+ <!DOCTYPE html>
2
+ <html lang="en" class="h-full">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>ChatPal - AI Companion</title>
7
+ <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script>
10
+ tailwind.config = {
11
+ darkMode: 'class',
12
+ theme: {
13
+ extend: {
14
+ colors: {
15
+ primary: {
16
+ light: '#6366f1',
17
+ dark: '#818cf8'
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ </script>
24
+ <script src="https://unpkg.com/feather-icons"></script>
25
+ <script src="https://cdn.jsdelivr.net/npm/emoji-picker-element@^1/index.js"></script>
26
+ <script src="https://unpkg.com/@pqina/flip/dist/flip.min.js"></script>
27
+ <script src="https://unpkg.com/filepond/dist/filepond.min.js"></script>
28
+ <script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.js"></script>
29
+ <script src="https://unpkg.com/filepond-plugin-file-validate-type/dist/filepond-plugin-file-validate-type.min.js"></script>
30
+ <link href="https://unpkg.com/filepond/dist/filepond.min.css" rel="stylesheet">
31
+ <link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css" rel="stylesheet">
32
+ <style>
33
+ .chat-container {
34
+ height: calc(100vh - 160px);
35
+ }
36
+ .message-content img {
37
+ max-width: 200px;
38
+ max-height: 200px;
39
+ border-radius: 8px;
40
+ margin-top: 8px;
41
+ }
42
+ .message-content pre {
43
+ background-color: rgba(0,0,0,0.1);
44
+ padding: 8px;
45
+ border-radius: 4px;
46
+ overflow-x: auto;
47
+ }
48
+ .dark .message-content pre {
49
+ background-color: rgba(255,255,255,0.1);
50
+ }
51
+ .emoji-btn:focus {
52
+ outline: none;
53
+ }
54
+ .filepond--root {
55
+ margin-bottom: 0;
56
+ }
57
+ </style>
58
+ </head>
59
+ <body class="h-full bg-gray-100 dark:bg-gray-900 transition-colors duration-200">
60
+ <div class="flex flex-col h-full max-w-4xl mx-auto">
61
+ <!-- Header -->
62
+ <header class="bg-white dark:bg-gray-800 shadow-sm p-4 flex justify-between items-center">
63
+ <h1 class="text-xl font-bold text-gray-800 dark:text-white">ChatPal πŸ€–</h1>
64
+ <div class="flex items-center space-x-4">
65
+ <button id="historyBtn" class="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700">
66
+ <i data-feather="clock"></i>
67
+ </button>
68
+ <button id="settingsBtn" class="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700">
69
+ <i data-feather="settings"></i>
70
+ </button>
71
+ <button id="themeBtn" class="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700">
72
+ <i data-feather="moon" class="dark:hidden"></i>
73
+ <i data-feather="sun" class="hidden dark:block"></i>
74
+ </button>
75
+ </div>
76
+ </header>
77
+
78
+ <!-- Chat Area -->
79
+ <div class="chat-container overflow-y-auto p-4 bg-white dark:bg-gray-800 flex-1">
80
+ <div class="flex flex-col space-y-4" id="chatMessages">
81
+ <!-- Welcome message -->
82
+ <div class="flex items-start space-x-3">
83
+ <div class="flex-shrink-0 bg-primary-light dark:bg-primary-dark rounded-full w-8 h-8 flex items-center justify-center text-white">
84
+ <i data-feather="bot" class="w-4 h-4"></i>
85
+ </div>
86
+ <div class="bg-gray-100 dark:bg-gray-700 p-3 rounded-lg max-w-[80%]">
87
+ <p class="text-gray-800 dark:text-gray-200">Hello! I'm your AI assistant. How can I help you today?</p>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </div>
92
+
93
+ <!-- Input Area -->
94
+ <div class="bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 p-4">
95
+ <form id="chatForm" class="space-y-2">
96
+ <div class="flex items-end space-x-2">
97
+ <!-- File Upload -->
98
+ <div class="w-10">
99
+ <input type="file" class="filepond" id="fileUpload" name="fileUpload"
100
+ data-max-file-size="10MB"
101
+ accept="image/*,.pdf,.doc,.docx,.txt">
102
+ </div>
103
+
104
+ <!-- Text Input -->
105
+ <div class="flex-1 relative">
106
+ <div id="textEditor" class="border border-gray-300 dark:border-gray-600 rounded-lg p-2 min-h-[40px] max-h-[120px] overflow-y-auto bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200" contenteditable="true" placeholder="Type your message..."></div>
107
+
108
+ <!-- Emoji Picker Toggle -->
109
+ <button type="button" id="emojiBtn" class="absolute right-2 bottom-2 text-gray-500 hover:text-primary-light dark:hover:text-primary-dark emoji-btn">
110
+ <i data-feather="smile"></i>
111
+ </button>
112
+ </div>
113
+
114
+ <!-- Voice/Send Buttons -->
115
+ <div class="flex space-x-2">
116
+ <button type="button" id="voiceBtn" class="p-2 rounded-full bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300">
117
+ <i data-feather="mic"></i>
118
+ </button>
119
+ <button type="submit" class="p-2 rounded-full bg-primary-light dark:bg-primary-dark text-white hover:opacity-90">
120
+ <i data-feather="send"></i>
121
+ </button>
122
+ </div>
123
+ </div>
124
+
125
+ <!-- Emoji Picker (hidden by default) -->
126
+ <div id="emojiPicker" class="hidden"></div>
127
+ </form>
128
+ </div>
129
+ </div>
130
+
131
+ <!-- History Modal -->
132
+ <div id="historyModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
133
+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md max-h-[80vh] overflow-hidden">
134
+ <div class="p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
135
+ <h3 class="text-lg font-medium text-gray-800 dark:text-white">Chat History</h3>
136
+ <button id="closeHistoryModal" class="text-gray-500 hover:text-gray-700 dark:hover:text-gray-300">
137
+ <i data-feather="x"></i>
138
+ </button>
139
+ </div>
140
+ <div class="overflow-y-auto p-4">
141
+ <ul id="historyList" class="space-y-2">
142
+ <li class="p-3 rounded-lg bg-gray-100 dark:bg-gray-700 cursor-pointer hover:bg-gray-200 dark:hover:bg-gray-600">
143
+ <p class="text-gray-800 dark:text-gray-200 font-medium">Getting started with AI</p>
144
+ <p class="text-sm text-gray-500 dark:text-gray-400">Today, 10:30 AM</p>
145
+ </li>
146
+ <li class="p-3 rounded-lg cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700">
147
+ <p class="text-gray-800 dark:text-gray-200 font-medium">Project brainstorming</p>
148
+ <p class="text-sm text-gray-500 dark:text-gray-400">Yesterday, 2:15 PM</p>
149
+ </li>
150
+ </ul>
151
+ </div>
152
+ <div class="p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end">
153
+ <button id="clearHistoryBtn" class="px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600">Clear History</button>
154
+ </div>
155
+ </div>
156
+ </div>
157
+
158
+ <!-- Settings Modal -->
159
+ <div id="settingsModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
160
+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md max-h-[80vh] overflow-hidden">
161
+ <div class="p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
162
+ <h3 class="text-lg font-medium text-gray-800 dark:text-white">Settings</h3>
163
+ <button id="closeSettingsModal" class="text-gray-500 hover:text-gray-700 dark:hover:text-gray-300">
164
+ <i data-feather="x"></i>
165
+ </button>
166
+ </div>
167
+ <div class="overflow-y-auto p-4 space-y-6">
168
+ <div>
169
+ <h4 class="text-md font-medium text-gray-800 dark:text-white mb-2">AI Model</h4>
170
+ <select class="w-full p-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200">
171
+ <option>GPT-4</option>
172
+ <option>GPT-3.5</option>
173
+ <option>Claude 2</option>
174
+ <option>Llama 2</option>
175
+ </select>
176
+ </div>
177
+
178
+ <div>
179
+ <h4 class="text-md font-medium text-gray-800 dark:text-white mb-2">Voice Input</h4>
180
+ <div class="flex items-center space-x-2">
181
+ <label class="inline-flex items-center">
182
+ <input type="checkbox" class="rounded border-gray-300 text-primary-light dark:text-primary-dark shadow-sm focus:border-primary-light focus:ring focus:ring-primary-light focus:ring-opacity-50">
183
+ <span class="ml-2 text-gray-700 dark:text-gray-300">Enable voice input</span>
184
+ </label>
185
+ </div>
186
+ </div>
187
+
188
+ <div>
189
+ <h4 class="text-md font-medium text-gray-800 dark:text-white mb-2">Appearance</h4>
190
+ <div class="flex space-x-4">
191
+ <button id="lightThemeBtn" class="px-4 py-2 border rounded-lg flex items-center space-x-2">
192
+ <i data-feather="sun" class="w-4 h-4"></i>
193
+ <span>Light</span>
194
+ </button>
195
+ <button id="darkThemeBtn" class="px-4 py-2 border rounded-lg flex items-center space-x-2">
196
+ <i data-feather="moon" class="w-4 h-4"></i>
197
+ <span>Dark</span>
198
+ </button>
199
+ <button id="systemThemeBtn" class="px-4 py-2 border rounded-lg flex items-center space-x-2">
200
+ <i data-feather="monitor" class="w-4 h-4"></i>
201
+ <span>System</span>
202
+ </button>
203
+ </div>
204
+ </div>
205
+ </div>
206
+ <div class="p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end">
207
+ <button id="saveSettingsBtn" class="px-4 py-2 bg-primary-light dark:bg-primary-dark text-white rounded-lg hover:opacity-90">Save Settings</button>
208
+ </div>
209
+ </div>
210
+ </div>
211
+
212
+ <!-- File Preview Modal -->
213
+ <div id="filePreviewModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
214
+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] overflow-hidden">
215
+ <div class="p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
216
+ <h3 class="text-lg font-medium text-gray-800 dark:text-white">File Preview</h3>
217
+ <button id="closeFilePreviewModal" class="text-gray-500 hover:text-gray-700 dark:hover:text-gray-300">
218
+ <i data-feather="x"></i>
219
+ </button>
220
+ </div>
221
+ <div class="overflow-y-auto p-4 flex justify-center">
222
+ <img id="previewImage" src="" alt="Preview" class="max-w-full max-h-[60vh] rounded-lg">
223
+ <div id="previewDocument" class="hidden w-full h-[60vh] bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center">
224
+ <div class="text-center p-6">
225
+ <i data-feather="file-text" class="w-12 h-12 mx-auto text-gray-400"></i>
226
+ <p class="mt-2 text-gray-800 dark:text-gray-200">Document preview not available</p>
227
+ <p class="text-sm text-gray-500 dark:text-gray-400">Download to view the full content</p>
228
+ <button class="mt-4 px-4 py-2 bg-primary-light dark:bg-primary-dark text-white rounded-lg hover:opacity-90">Download</button>
229
+ </div>
230
+ </div>
231
+ </div>
232
+ </div>
233
+ </div>
234
+
235
+ <script>
236
+ // Initialize FilePond
237
+ FilePond.registerPlugin(FilePondPluginImagePreview);
238
+ FilePond.registerPlugin(FilePondPluginFileValidateType);
239
+
240
+ const pond = FilePond.create(document.querySelector('input[type="file"]'), {
241
+ allowMultiple: true,
242
+ acceptedFileTypes: ['image/*', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/plain'],
243
+ fileValidateTypeDetectType: (source, type) => new Promise((resolve, reject) => {
244
+ resolve(type);
245
+ }),
246
+ onaddfile: (error, file) => {
247
+ if (error) return;
248
+ if (file.fileType === 'image') {
249
+ // Show preview modal
250
+ document.getElementById('previewImage').src = URL.createObjectURL(file.file);
251
+ document.getElementById('previewDocument').classList.add('hidden');
252
+ document.getElementById('previewImage').classList.remove('hidden');
253
+ document.getElementById('filePreviewModal').classList.remove('hidden');
254
+ } else {
255
+ // Show document placeholder
256
+ document.getElementById('previewImage').classList.add('hidden');
257
+ document.getElementById('previewDocument').classList.remove('hidden');
258
+ document.getElementById('filePreviewModal').classList.remove('hidden');
259
+ }
260
+ }
261
+ });
262
+
263
+ // Initialize emoji picker
264
+ const picker = document.getElementById('emojiPicker');
265
+ const emojiBtn = document.getElementById('emojiBtn');
266
+ const textEditor = document.getElementById('textEditor');
267
+
268
+ new EmojiPicker({
269
+ locale: 'en',
270
+ onClick: emoji => {
271
+ textEditor.innerHTML += emoji;
272
+ textEditor.focus();
273
+ picker.classList.add('hidden');
274
+ }
275
+ }).mount('#emojiPicker');
276
+
277
+ emojiBtn.addEventListener('click', () => {
278
+ picker.classList.toggle('hidden');
279
+ });
280
+
281
+ // Modal handlers
282
+ document.getElementById('historyBtn').addEventListener('click', () => {
283
+ document.getElementById('historyModal').classList.remove('hidden');
284
+ });
285
+
286
+ document.getElementById('settingsBtn').addEventListener('click', () => {
287
+ document.getElementById('settingsModal').classList.remove('hidden');
288
+ });
289
+
290
+ document.getElementById('closeHistoryModal').addEventListener('click', () => {
291
+ document.getElementById('historyModal').classList.add('hidden');
292
+ });
293
+
294
+ document.getElementById('closeSettingsModal').addEventListener('click', () => {
295
+ document.getElementById('settingsModal').classList.add('hidden');
296
+ });
297
+
298
+ document.getElementById('closeFilePreviewModal').addEventListener('click', () => {
299
+ document.getElementById('filePreviewModal').classList.add('hidden');
300
+ });
301
+
302
+ // Theme switcher
303
+ document.getElementById('themeBtn').addEventListener('click', () => {
304
+ if (document.documentElement.classList.contains('dark')) {
305
+ document.documentElement.classList.remove('dark');
306
+ localStorage.setItem('theme', 'light');
307
+ } else {
308
+ document.documentElement.classList.add('dark');
309
+ localStorage.setItem('theme', 'dark');
310
+ }
311
+ });
312
+
313
+ document.getElementById('lightThemeBtn').addEventListener('click', () => {
314
+ document.documentElement.classList.remove('dark');
315
+ localStorage.setItem('theme', 'light');
316
+ });
317
+
318
+ document.getElementById('darkThemeBtn').addEventListener('click', () => {
319
+ document.documentElement.classList.add('dark');
320
+ localStorage.setItem('theme', 'dark');
321
+ });
322
+
323
+ document.getElementById('systemThemeBtn').addEventListener('click', () => {
324
+ localStorage.removeItem('theme');
325
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
326
+ document.documentElement.classList.add('dark');
327
+ } else {
328
+ document.documentElement.classList.remove('dark');
329
+ }
330
+ });
331
+
332
+ // Check for saved theme preference or use system preference
333
+ if (localStorage.getItem('theme') === 'dark' || (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
334
+ document.documentElement.classList.add('dark');
335
+ } else {
336
+ document.documentElement.classList.remove('dark');
337
+ }
338
+
339
+ // Chat form submission
340
+ document.getElementById('chatForm').addEventListener('submit', (e) => {
341
+ e.preventDefault();
342
+ const message = textEditor.innerHTML.trim();
343
+
344
+ if (message || pond.getFiles().length > 0) {
345
+ // Add user message
346
+ addMessage('user', message);
347
+
348
+ // Clear input
349
+ textEditor.innerHTML = '';
350
+ pond.removeFiles();
351
+
352
+ // Simulate bot response
353
+ setTimeout(() => {
354
+ addMessage('bot', "Thanks for your message! I'm processing your request...");
355
+ }, 1000);
356
+ }
357
+ });
358
+
359
+ // Add message to chat
360
+ function addMessage(sender, content) {
361
+ const chatMessages = document.getElementById('chatMessages');
362
+ const messageDiv = document.createElement('div');
363
+ messageDiv.className = `flex items-start space-x-3 ${sender === 'user' ? 'justify-end' : ''}`;
364
+
365
+ if (sender === 'user') {
366
+ messageDiv.innerHTML = `
367
+ <div class="bg-primary-light dark:bg-primary-dark text-white p-3 rounded-lg max-w-[80%]">
368
+ <div class="message-content">${content}</div>
369
+ </div>
370
+ <div class="flex-shrink-0 bg-gray-300 rounded-full w-8 h-8 flex items-center justify-center">
371
+ <i data-feather="user" class="w-4 h-4 text-gray-700"></i>
372
+ </div>
373
+ `;
374
+ } else {
375
+ messageDiv.innerHTML = `
376
+ <div class="flex-shrink-0 bg-primary-light dark:bg-primary-dark rounded-full w-8 h-8 flex items-center justify-center text-white">
377
+ <i data-feather="bot" class="w-4 h-4"></i>
378
+ </div>
379
+ <div class="bg-gray-100 dark:bg-gray-700 p-3 rounded-lg max-w-[80%]">
380
+ <div class="message-content">${content}</div>
381
+ </div>
382
+ `;
383
+ }
384
+
385
+ chatMessages.appendChild(messageDiv);
386
+ chatMessages.scrollTop = chatMessages.scrollHeight;
387
+ feather.replace();
388
+ }
389
+
390
+ // Voice recognition (simplified)
391
+ document.getElementById('voiceBtn').addEventListener('click', () => {
392
+ alert("Voice input would be implemented here with the Web Speech API");
393
+ });
394
+
395
+ // Initialize feather icons
396
+ document.addEventListener('DOMContentLoaded', () => {
397
+ feather.replace();
398
+ });
399
+ </script>
400
+ </body>
401
  </html>