thomaswong360 commited on
Commit
f782783
·
verified ·
1 Parent(s): 3e87193

Can you generate a Chatbot website that model very much like how ChatGPT works? - Initial Deployment

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +293 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Chatui
3
- emoji: 🔥
4
  colorFrom: gray
5
- colorTo: gray
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: chatui
3
+ emoji: 🐳
4
  colorFrom: gray
5
+ colorTo: purple
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,293 @@
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">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AI Chatbot - ChatGPT Clone</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ /* Custom scrollbar */
11
+ ::-webkit-scrollbar {
12
+ width: 6px;
13
+ }
14
+ ::-webkit-scrollbar-track {
15
+ background: #f1f1f1;
16
+ }
17
+ ::-webkit-scrollbar-thumb {
18
+ background: #888;
19
+ border-radius: 3px;
20
+ }
21
+ ::-webkit-scrollbar-thumb:hover {
22
+ background: #555;
23
+ }
24
+
25
+ /* Message typing animation */
26
+ @keyframes typing {
27
+ from { width: 0 }
28
+ to { width: 100% }
29
+ }
30
+
31
+ .typing-indicator::after {
32
+ content: "|";
33
+ animation: blink 1s infinite;
34
+ }
35
+
36
+ @keyframes blink {
37
+ 0%, 100% { opacity: 1 }
38
+ 50% { opacity: 0 }
39
+ }
40
+
41
+ /* Fade in animation */
42
+ @keyframes fadeIn {
43
+ from { opacity: 0; transform: translateY(10px); }
44
+ to { opacity: 1; transform: translateY(0); }
45
+ }
46
+
47
+ .fade-in {
48
+ animation: fadeIn 0.3s ease-out forwards;
49
+ }
50
+ </style>
51
+ </head>
52
+ <body class="bg-gray-50 text-gray-900 flex flex-col h-screen">
53
+ <!-- Header -->
54
+ <header class="bg-white border-b border-gray-200 py-3 px-4 flex items-center justify-between">
55
+ <div class="flex items-center">
56
+ <div class="w-8 h-8 rounded-full bg-green-500 flex items-center justify-center text-white font-bold mr-2">AI</div>
57
+ <h1 class="text-xl font-semibold">AI Assistant</h1>
58
+ </div>
59
+ <div class="flex items-center space-x-4">
60
+ <button class="text-gray-500 hover:text-gray-700">
61
+ <i class="fas fa-sun"></i>
62
+ </button>
63
+ <button class="text-gray-500 hover:text-gray-700">
64
+ <i class="fas fa-cog"></i>
65
+ </button>
66
+ </div>
67
+ </header>
68
+
69
+ <!-- Chat container -->
70
+ <div class="flex-1 overflow-y-auto p-4 space-y-6" id="chat-container">
71
+ <!-- Welcome message -->
72
+ <div class="max-w-3xl mx-auto fade-in">
73
+ <div class="flex items-start space-x-3">
74
+ <div class="w-8 h-8 rounded-full bg-green-500 flex items-center justify-center text-white font-bold flex-shrink-0">AI</div>
75
+ <div class="bg-white p-4 rounded-lg shadow-sm border border-gray-200 flex-1">
76
+ <p class="font-medium">Hello! I'm your AI assistant. How can I help you today?</p>
77
+ <div class="mt-2 grid grid-cols-1 md:grid-cols-2 gap-2">
78
+ <button class="suggestion-btn text-left p-2 text-sm rounded border border-gray-200 hover:bg-gray-50 transition">
79
+ "Explain quantum computing in simple terms"
80
+ </button>
81
+ <button class="suggestion-btn text-left p-2 text-sm rounded border border-gray-200 hover:bg-gray-50 transition">
82
+ "Give me creative ideas for a 10-year-old's birthday"
83
+ </button>
84
+ <button class="suggestion-btn text-left p-2 text-sm rounded border border-gray-200 hover:bg-gray-50 transition">
85
+ "How do I make an HTTP request in JavaScript?"
86
+ </button>
87
+ <button class="suggestion-btn text-left p-2 text-sm rounded border border-gray-200 hover:bg-gray-50 transition">
88
+ "Write a poem about artificial intelligence"
89
+ </button>
90
+ </div>
91
+ </div>
92
+ </div>
93
+ </div>
94
+ </div>
95
+
96
+ <!-- Input area -->
97
+ <div class="bg-white border-t border-gray-200 p-4">
98
+ <div class="max-w-3xl mx-auto relative">
99
+ <form id="chat-form" class="relative">
100
+ <textarea
101
+ id="message-input"
102
+ rows="1"
103
+ placeholder="Message AI Assistant..."
104
+ class="w-full p-4 pr-12 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent resize-none"
105
+ style="min-height: 60px; max-height: 200px;"
106
+ ></textarea>
107
+ <button
108
+ type="submit"
109
+ id="send-btn"
110
+ class="absolute right-3 bottom-3 w-8 h-8 rounded-full bg-green-500 text-white flex items-center justify-center hover:bg-green-600 transition disabled:opacity-50 disabled:cursor-not-allowed"
111
+ disabled
112
+ >
113
+ <i class="fas fa-paper-plane"></i>
114
+ </button>
115
+ </form>
116
+ <div class="text-xs text-gray-500 mt-2 text-center">
117
+ AI Assistant can make mistakes. Consider checking important information.
118
+ </div>
119
+ </div>
120
+ </div>
121
+
122
+ <script>
123
+ document.addEventListener('DOMContentLoaded', function() {
124
+ const chatContainer = document.getElementById('chat-container');
125
+ const messageInput = document.getElementById('message-input');
126
+ const chatForm = document.getElementById('chat-form');
127
+ const sendBtn = document.getElementById('send-btn');
128
+
129
+ // Auto-resize textarea
130
+ messageInput.addEventListener('input', function() {
131
+ this.style.height = 'auto';
132
+ this.style.height = (this.scrollHeight) + 'px';
133
+
134
+ // Enable/disable send button
135
+ sendBtn.disabled = this.value.trim() === '';
136
+ });
137
+
138
+ // Handle form submission
139
+ chatForm.addEventListener('submit', function(e) {
140
+ e.preventDefault();
141
+ const message = messageInput.value.trim();
142
+ if (message) {
143
+ sendMessage(message);
144
+ messageInput.value = '';
145
+ messageInput.style.height = 'auto';
146
+ sendBtn.disabled = true;
147
+ }
148
+ });
149
+
150
+ // Handle suggestion buttons
151
+ document.querySelectorAll('.suggestion-btn').forEach(btn => {
152
+ btn.addEventListener('click', function() {
153
+ const suggestion = this.textContent.trim();
154
+ messageInput.value = suggestion;
155
+ messageInput.dispatchEvent(new Event('input'));
156
+ messageInput.focus();
157
+ });
158
+ });
159
+
160
+ // Send message function
161
+ function sendMessage(message) {
162
+ // Add user message to chat
163
+ addMessageToChat('user', message);
164
+
165
+ // Show typing indicator
166
+ showTypingIndicator();
167
+
168
+ // Simulate AI response after a delay
169
+ setTimeout(() => {
170
+ // Remove typing indicator
171
+ removeTypingIndicator();
172
+
173
+ // Generate and add AI response
174
+ const response = generateAIResponse(message);
175
+ addMessageToChat('ai', response);
176
+
177
+ // Scroll to bottom
178
+ scrollToBottom();
179
+ }, 1000 + Math.random() * 2000); // Random delay between 1-3 seconds
180
+
181
+ // Scroll to bottom
182
+ scrollToBottom();
183
+ }
184
+
185
+ // Add message to chat
186
+ function addMessageToChat(sender, message) {
187
+ const messageDiv = document.createElement('div');
188
+ messageDiv.className = 'max-w-3xl mx-auto fade-in';
189
+
190
+ if (sender === 'user') {
191
+ messageDiv.innerHTML = `
192
+ <div class="flex items-start space-x-3 justify-end">
193
+ <div class="bg-green-500 text-white p-4 rounded-lg shadow-sm max-w-full">
194
+ <p>${message}</p>
195
+ </div>
196
+ <div class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center text-white font-bold flex-shrink-0">
197
+ <i class="fas fa-user text-sm"></i>
198
+ </div>
199
+ </div>
200
+ `;
201
+ } else {
202
+ messageDiv.innerHTML = `
203
+ <div class="flex items-start space-x-3">
204
+ <div class="w-8 h-8 rounded-full bg-green-500 flex items-center justify-center text-white font-bold flex-shrink-0">AI</div>
205
+ <div class="bg-white p-4 rounded-lg shadow-sm border border-gray-200 flex-1">
206
+ <p>${message}</p>
207
+ </div>
208
+ </div>
209
+ `;
210
+ }
211
+
212
+ chatContainer.appendChild(messageDiv);
213
+ scrollToBottom();
214
+ }
215
+
216
+ // Show typing indicator
217
+ function showTypingIndicator() {
218
+ const typingDiv = document.createElement('div');
219
+ typingDiv.className = 'max-w-3xl mx-auto fade-in';
220
+ typingDiv.id = 'typing-indicator';
221
+ typingDiv.innerHTML = `
222
+ <div class="flex items-start space-x-3">
223
+ <div class="w-8 h-8 rounded-full bg-green-500 flex items-center justify-center text-white font-bold flex-shrink-0">AI</div>
224
+ <div class="bg-white p-4 rounded-lg shadow-sm border border-gray-200 flex-1">
225
+ <div class="typing-indicator">Typing</div>
226
+ </div>
227
+ </div>
228
+ `;
229
+ chatContainer.appendChild(typingDiv);
230
+ }
231
+
232
+ // Remove typing indicator
233
+ function removeTypingIndicator() {
234
+ const typingIndicator = document.getElementById('typing-indicator');
235
+ if (typingIndicator) {
236
+ typingIndicator.remove();
237
+ }
238
+ }
239
+
240
+ // Scroll to bottom of chat
241
+ function scrollToBottom() {
242
+ chatContainer.scrollTop = chatContainer.scrollHeight;
243
+ }
244
+
245
+ // Generate AI response (simulated)
246
+ function generateAIResponse(userMessage) {
247
+ const responses = {
248
+ "hello": "Hello there! How can I assist you today?",
249
+ "hi": "Hi! What can I do for you?",
250
+ "how are you": "I'm just a computer program, so I don't have feelings, but I'm functioning perfectly! How can I help you?",
251
+ "what's your name": "I'm an AI assistant created to help answer your questions and assist with various tasks.",
252
+ "explain quantum computing in simple terms": "Quantum computing uses quantum bits or qubits which can exist in multiple states at once (unlike regular bits that are just 0 or 1). This allows quantum computers to perform many calculations simultaneously, potentially solving certain complex problems much faster than classical computers.",
253
+ "give me creative ideas for a 10-year-old's birthday": "Here are some fun ideas:\n1. Science party with simple experiments\n2. Outdoor treasure hunt with clues\n3. DIY pizza making party\n4. Movie night under the stars\n5. Video game tournament\n6. Arts and crafts party\n7. Sports-themed party with mini-games",
254
+ "how do i make an http request in javascript": "You can use the Fetch API in modern JavaScript:\n\n```javascript\nfetch('https://api.example.com/data')\n .then(response => response.json())\n .then(data => console.log(data))\n .catch(error => console.error('Error:', error));\n```\n\nOr with async/await:\n\n```javascript\nasync function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error:', error);\n }\n}\n```",
255
+ "write a poem about artificial intelligence": `"Silicon Dreams"\n\nIn circuits deep where thoughts take flight,\nA spark of code, a beam of light.\nNot flesh nor blood, yet still it learns,\nFrom data vast its knowledge burns.\n\nIt speaks in tongues of math so pure,\nSolutions found, of this I'm sure.\nYet questions linger in the air,\nCan mind emerge from wires bare?\n\nA tool we've forged to help, to guide,\nWith logic's edge and wisdom wide.\nBut in its heart (if heart there be),\nLies just our own humanity.`
256
+ };
257
+
258
+ const lowerMessage = userMessage.toLowerCase();
259
+
260
+ // Check for exact matches first
261
+ if (responses[lowerMessage]) {
262
+ return responses[lowerMessage];
263
+ }
264
+
265
+ // Check for partial matches
266
+ for (const [key, value] of Object.entries(responses)) {
267
+ if (lowerMessage.includes(key)) {
268
+ return value;
269
+ }
270
+ }
271
+
272
+ // Default responses based on question type
273
+ if (lowerMessage.startsWith('what') || lowerMessage.startsWith('how') || lowerMessage.endsWith('?')) {
274
+ return "That's an interesting question. While I don't have all the answers, I can tell you that " +
275
+ "this topic relates to several areas of study. Would you like me to provide some general " +
276
+ "information about it or would you prefer a more specific explanation?";
277
+ }
278
+
279
+ if (lowerMessage.startsWith('tell me') || lowerMessage.startsWith('explain')) {
280
+ return "I'd be happy to explain that concept. Essentially, it involves " +
281
+ "several key principles that work together to create the effect you're asking about. " +
282
+ "Would you like me to break it down further?";
283
+ }
284
+
285
+ // Fallback response
286
+ return "Thank you for your message. I'm designed to assist with a wide variety of topics. " +
287
+ "Could you clarify or provide more details about what you're looking for? " +
288
+ "I'm happy to help with information, creative ideas, problem solving, and more!";
289
+ }
290
+ });
291
+ </script>
292
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=thomaswong360/chatui" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
293
+ </html>