m-Kairo commited on
Commit
3b8a58e
·
verified ·
1 Parent(s): c66c9a0

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +351 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Chatbot
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: chatbot
3
+ emoji: 🐳
4
+ colorFrom: purple
5
+ colorTo: yellow
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,351 @@
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>Rohan - 3D AI Assistant</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
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.min.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script>
12
+ <style>
13
+ #model-container {
14
+ width: 300px;
15
+ height: 300px;
16
+ margin: 0 auto;
17
+ position: relative;
18
+ }
19
+
20
+ #model-viewer {
21
+ width: 100%;
22
+ height: 100%;
23
+ background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
24
+ border-radius: 50%;
25
+ overflow: hidden;
26
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
27
+ }
28
+
29
+ .chat-container {
30
+ height: 400px;
31
+ overflow-y: auto;
32
+ scrollbar-width: thin;
33
+ }
34
+
35
+ .chat-container::-webkit-scrollbar {
36
+ width: 6px;
37
+ }
38
+
39
+ .chat-container::-webkit-scrollbar-thumb {
40
+ background-color: rgba(156, 163, 175, 0.5);
41
+ border-radius: 3px;
42
+ }
43
+
44
+ .user-message {
45
+ animation: fadeIn 0.3s ease;
46
+ }
47
+
48
+ .ai-message {
49
+ animation: fadeIn 0.5s ease;
50
+ }
51
+
52
+ @keyframes fadeIn {
53
+ from { opacity: 0; transform: translateY(10px); }
54
+ to { opacity: 1; transform: translateY(0); }
55
+ }
56
+
57
+ .input-container {
58
+ box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.05);
59
+ }
60
+
61
+ .status-indicator {
62
+ transition: all 0.3s ease;
63
+ }
64
+
65
+ .typing .status-indicator {
66
+ animation: pulse 1.5s infinite;
67
+ }
68
+
69
+ @keyframes pulse {
70
+ 0%, 100% { opacity: 0.5; }
71
+ 50% { opacity: 1; }
72
+ }
73
+ </style>
74
+ </head>
75
+ <body class="bg-gray-50 min-h-screen flex flex-col">
76
+ <div class="container mx-auto px-4 py-8 flex-1 flex flex-col max-w-3xl">
77
+ <!-- Header -->
78
+ <header class="text-center mb-8">
79
+ <h1 class="text-4xl font-bold text-indigo-600 mb-2">Rohan</h1>
80
+ <p class="text-gray-600">Your 3D AI assistant</p>
81
+ </header>
82
+
83
+ <!-- 3D Model -->
84
+ <div class="mb-8 flex flex-col items-center">
85
+ <div id="model-container">
86
+ <div id="model-viewer"></div>
87
+ </div>
88
+ <div class="mt-4 text-center">
89
+ <div class="status-indicator inline-block w-3 h-3 rounded-full bg-green-500 mr-2"></div>
90
+ <span class="text-gray-600 status-text">Ready to help you</span>
91
+ </div>
92
+ </div>
93
+
94
+ <!-- Chat Container -->
95
+ <div class="chat-container bg-white rounded-lg shadow-md p-4 mb-4 flex-1">
96
+ <div class="ai-message flex mb-4">
97
+ <div class="flex-shrink-0 mr-3">
98
+ <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
99
+ <i class="fas fa-robot text-indigo-500"></i>
100
+ </div>
101
+ </div>
102
+ <div class="bg-indigo-50 rounded-lg p-3 max-w-[85%]">
103
+ <p class="text-gray-800">Namaste! I'm Rohan, your 3D AI assistant. How can I help you today?</p>
104
+ </div>
105
+ </div>
106
+ <div id="chat-messages"></div>
107
+ </div>
108
+
109
+ <!-- Input Area -->
110
+ <div class="input-container bg-white rounded-lg shadow-md p-4">
111
+ <form id="chat-form" class="flex">
112
+ <input
113
+ type="text"
114
+ id="user-input"
115
+ placeholder="Ask me anything..."
116
+ class="flex-1 border border-gray-300 rounded-l-lg py-2 px-4 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
117
+ autocomplete="off"
118
+ >
119
+ <button
120
+ type="submit"
121
+ class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-r-lg transition duration-200"
122
+ >
123
+ Send
124
+ </button>
125
+ </form>
126
+ <div class="mt-2 flex justify-between text-xs text-gray-500">
127
+ <span>Try: "weather in Delhi" or "what's 20% of 150?"</span>
128
+ <span id="typing-indicator" class="hidden">
129
+ <i class="fas fa-circle-notch fa-spin mr-1"></i> Rohan is typing...
130
+ </span>
131
+ </div>
132
+ </div>
133
+ </div>
134
+
135
+ <script>
136
+ document.addEventListener('DOMContentLoaded', function() {
137
+ // Three.js setup
138
+ const container = document.getElementById('model-viewer');
139
+ const scene = new THREE.Scene();
140
+ const camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000);
141
+ const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
142
+ renderer.setSize(container.clientWidth, container.clientHeight);
143
+ container.appendChild(renderer.domElement);
144
+
145
+ // Lighting
146
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
147
+ scene.add(ambientLight);
148
+
149
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
150
+ directionalLight.position.set(1, 1, 1);
151
+ scene.add(directionalLight);
152
+
153
+ // Controls
154
+ const controls = new THREE.OrbitControls(camera, renderer.domElement);
155
+ controls.enableZoom = false;
156
+ controls.enablePan = false;
157
+ controls.maxPolarAngle = Math.PI * 0.6;
158
+ controls.minPolarAngle = Math.PI * 0.4;
159
+ controls.maxAzimuthAngle = Math.PI * 0.2;
160
+ controls.minAzimuthAngle = -Math.PI * 0.2;
161
+
162
+ // Camera position
163
+ camera.position.z = 2;
164
+
165
+ // Load 3D model (using a free Indian boy model from Sketchfab)
166
+ const loader = new THREE.GLTFLoader();
167
+ const modelUrl = 'https://cdn.jsdelivr.net/gh/mrdoob/three.js@r128/examples/models/gltf/Parrot.glb';
168
+
169
+ // For demo purposes, we'll use a placeholder model
170
+ // In production, you would use a proper Indian boy model URL
171
+ loader.load(
172
+ modelUrl,
173
+ function(gltf) {
174
+ const model = gltf.scene;
175
+ model.scale.set(0.02, 0.02, 0.02);
176
+ model.position.y = -0.5;
177
+ scene.add(model);
178
+
179
+ // Animation loop
180
+ function animate() {
181
+ requestAnimationFrame(animate);
182
+ model.rotation.y += 0.005;
183
+ controls.update();
184
+ renderer.render(scene, camera);
185
+ }
186
+ animate();
187
+ },
188
+ undefined,
189
+ function(error) {
190
+ console.error('Error loading 3D model:', error);
191
+ // Fallback to a simple sphere if model fails to load
192
+ const geometry = new THREE.SphereGeometry(1, 32, 32);
193
+ const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
194
+ const sphere = new THREE.Mesh(geometry, material);
195
+ scene.add(sphere);
196
+
197
+ function animate() {
198
+ requestAnimationFrame(animate);
199
+ sphere.rotation.y += 0.01;
200
+ renderer.render(scene, camera);
201
+ }
202
+ animate();
203
+ }
204
+ );
205
+
206
+ // Chat functionality
207
+ const chatForm = document.getElementById('chat-form');
208
+ const userInput = document.getElementById('user-input');
209
+ const chatMessages = document.getElementById('chat-messages');
210
+ const typingIndicator = document.getElementById('typing-indicator');
211
+ const statusText = document.querySelector('.status-text');
212
+ const statusIndicator = document.querySelector('.status-indicator');
213
+
214
+ // Change status
215
+ function setStatus(status, text) {
216
+ statusIndicator.className = `status-indicator inline-block w-3 h-3 rounded-full mr-2 ${status}`;
217
+ statusText.textContent = text;
218
+
219
+ if (status === 'typing') {
220
+ statusIndicator.classList.add('typing');
221
+ } else {
222
+ statusIndicator.classList.remove('typing');
223
+ }
224
+ }
225
+
226
+ // Add message to chat
227
+ function addMessage(content, isUser) {
228
+ const messageDiv = document.createElement('div');
229
+ messageDiv.className = `${isUser ? 'user-message' : 'ai-message'} flex mb-4 ${isUser ? 'justify-end' : ''}`;
230
+
231
+ messageDiv.innerHTML = `
232
+ ${isUser ? '' : `
233
+ <div class="flex-shrink-0 mr-3">
234
+ <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
235
+ <i class="fas fa-robot text-indigo-500"></i>
236
+ </div>
237
+ </div>
238
+ `}
239
+ <div class="${isUser ? 'bg-indigo-100' : 'bg-indigo-50'} rounded-lg p-3 max-w-[85%]">
240
+ <p class="text-gray-800">${content}</p>
241
+ </div>
242
+ ${isUser ? `
243
+ <div class="flex-shrink-0 ml-3">
244
+ <div class="w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center">
245
+ <i class="fas fa-user text-gray-500"></i>
246
+ </div>
247
+ </div>
248
+ ` : ''}
249
+ `;
250
+
251
+ chatMessages.appendChild(messageDiv);
252
+ chatMessages.scrollTop = chatMessages.scrollHeight;
253
+ }
254
+
255
+ // Simulate AI response
256
+ function getAIResponse(message) {
257
+ return new Promise((resolve) => {
258
+ setTimeout(() => {
259
+ const lowerMsg = message.toLowerCase();
260
+
261
+ if (lowerMsg.includes('weather') || lowerMsg.includes('temperature')) {
262
+ const location = message.replace(/weather|temperature|in|at/gi, '').trim();
263
+ resolve(`The weather in ${location || "your location"} is pleasant today! Around 30°C with moderate humidity.`);
264
+ }
265
+ else if (lowerMsg.includes('hi') || lowerMsg.includes('hello') || lowerMsg.includes('namaste')) {
266
+ resolve("Namaste! How can I assist you today?");
267
+ }
268
+ else if (lowerMsg.includes('how are you')) {
269
+ resolve("I'm doing great, dhanyavaad for asking! What can I do for you?");
270
+ }
271
+ else if (lowerMsg.includes('thank') || lowerMsg.includes('dhanyavaad')) {
272
+ resolve("You're most welcome! Let me know if you need anything else.");
273
+ }
274
+ else if (lowerMsg.includes('+') || lowerMsg.includes('-') || lowerMsg.includes('*') || lowerMsg.includes('/') || lowerMsg.includes('math') || lowerMsg.includes('%')) {
275
+ try {
276
+ const result = eval(message.replace(/[^-()\d/*+.]/g, ''));
277
+ resolve(`The answer is ${result}.`);
278
+ } catch {
279
+ resolve("I couldn't calculate that. Could you please rephrase your math question?");
280
+ }
281
+ }
282
+ else if (lowerMsg.includes('time')) {
283
+ const now = new Date();
284
+ resolve(`The current time is ${now.toLocaleTimeString()}.`);
285
+ }
286
+ else if (lowerMsg.includes('india') || lowerMsg.includes('bharat')) {
287
+ resolve("India is a beautiful country with diverse culture, languages, and traditions. It's known for its rich history, delicious food, and warm hospitality!");
288
+ }
289
+ else {
290
+ resolve(`I understand you're asking about "${message}". Here's what I found: This is a simulated response. In a real app, I'd provide a detailed answer to your question.`);
291
+ }
292
+ }, 1500);
293
+ });
294
+ }
295
+
296
+ // Handle form submission
297
+ chatForm.addEventListener('submit', async function(e) {
298
+ e.preventDefault();
299
+ const message = userInput.value.trim();
300
+
301
+ if (!message) return;
302
+
303
+ // Add user message
304
+ addMessage(message, true);
305
+ userInput.value = '';
306
+
307
+ // Show typing indicator
308
+ setStatus('bg-yellow-500 typing', 'Thinking...');
309
+ typingIndicator.classList.remove('hidden');
310
+
311
+ // Get AI response
312
+ try {
313
+ const response = await getAIResponse(message);
314
+
315
+ // Hide typing indicator
316
+ typingIndicator.classList.add('hidden');
317
+
318
+ // Set appropriate status
319
+ if (response.includes('Namaste') || response.includes('welcome') || response.includes('pleasant')) {
320
+ setStatus('bg-green-500', 'Happy to help!');
321
+ } else if (response.includes('understand') || response.includes('rephrase') || response.includes('think')) {
322
+ setStatus('bg-blue-500', 'Processing...');
323
+ } else if (response.includes('couldn\'t') || response.includes('sorry')) {
324
+ setStatus('bg-red-500', 'Having trouble');
325
+ } else {
326
+ setStatus('bg-green-500', 'Ready to help');
327
+ }
328
+
329
+ // Add AI response
330
+ addMessage(response, false);
331
+ } catch (error) {
332
+ typingIndicator.classList.add('hidden');
333
+ setStatus('bg-red-500', 'Error occurred');
334
+ addMessage("Something went wrong. Please try again.", false);
335
+ console.error(error);
336
+ }
337
+ });
338
+
339
+ // Focus input on load
340
+ userInput.focus();
341
+
342
+ // Resize handler
343
+ window.addEventListener('resize', function() {
344
+ camera.aspect = 1;
345
+ camera.updateProjectionMatrix();
346
+ renderer.setSize(container.clientWidth, container.clientHeight);
347
+ });
348
+ });
349
+ </script>
350
+ <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=m-Kairo/chatbot" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
351
+ </html>