vijay7788 commited on
Commit
c14a277
·
verified ·
1 Parent(s): a8f1fe1

provid eclick evnt correclty

Browse files
Files changed (1) hide show
  1. index.html +113 -56
index.html CHANGED
@@ -138,31 +138,89 @@
138
  </div>
139
 
140
  <script>
141
- // Theme Toggle
142
- const themeToggle = document.getElementById('themeToggle');
143
- themeToggle.addEventListener('click', () => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  document.documentElement.classList.toggle('dark');
145
- const icon = themeToggle.querySelector('i');
 
146
  if (document.documentElement.classList.contains('dark')) {
147
- feather.icons['moon'].toSvg().then(svg => icon.outerHTML = svg);
148
  } else {
149
- feather.icons['sun'].toSvg().then(svg => icon.outerHTML = svg);
150
  }
151
- });
 
 
 
 
 
 
 
 
 
 
152
 
153
- // Chat functionality
154
- const chatMessages = document.getElementById('chatMessages');
155
- const userInput = document.getElementById('userInput');
156
- const sendButton = document.getElementById('sendButton');
157
- const quickPrompts = document.querySelectorAll('.quick-prompt');
 
 
 
 
 
 
 
 
 
158
 
159
  function addUserMessage(message) {
 
160
  const messageDiv = document.createElement('div');
161
  messageDiv.className = 'chat-message user-message';
162
  messageDiv.innerHTML = `
163
  <div class="flex items-start space-x-3 justify-end">
164
  <div class="bg-gray-700 rounded-lg p-3 max-w-3xl">
165
- <p>${message}</p>
166
  </div>
167
  <div class="bg-primary-500 p-2 rounded-full">
168
  <i data-feather="user" class="w-5 h-5 text-white"></i>
@@ -170,16 +228,18 @@
170
  </div>
171
  `;
172
  chatMessages.appendChild(messageDiv);
 
173
  scrollToBottom();
174
  }
175
 
176
  function addBotMessage(message, isTyping = false) {
 
177
  const messageDiv = document.createElement('div');
178
  messageDiv.className = 'chat-message bot-message';
179
 
180
  let messageContent = isTyping
181
- ? '<span class="typing-indicator"></span>'
182
- : `<p>${message}</p>`;
183
 
184
  messageDiv.innerHTML = `
185
  <div class="flex items-start space-x-3">
@@ -192,67 +252,64 @@
192
  </div>
193
  `;
194
  chatMessages.appendChild(messageDiv);
 
195
  scrollToBottom();
196
 
197
- if (isTyping) {
198
- return messageDiv;
199
- }
200
- return null;
201
  }
202
 
203
  function scrollToBottom() {
 
204
  chatMessages.scrollTop = chatMessages.scrollHeight;
205
  }
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  // Simulate API call to Python backend
208
  async function getBotResponse(userMessage) {
209
- // In a real app, this would call your Python backend API
210
- // For demo purposes, we'll simulate responses
211
-
212
  const responses = {
213
  "hello": "Hello! How can I assist you with your AI/ML learning today?",
214
  "hi": "Hi there! What AI concept would you like to explore?",
215
- "explain backpropagation": "Backpropagation is the algorithm used to train neural networks. It works by:\n1. Forward pass: Compute predictions\n2. Calculate loss\n3. Backward pass: Compute gradients\n4. Update weights using gradient descent\n\nIt's called 'back' propagation because gradients flow backward through the network from output to input layers.",
216
- "show python ml example": "Here's a simple linear regression example using scikit-learn:\n
217
- // Send message when Enter is pressed
218
- userInput.addEventListener('keypress', (e) => {
219
- if (e.key === 'Enter') {
220
- sendMessage();
221
- }
222
- });
223
-
224
- // Send button click handler
225
- sendButton.addEventListener('click', sendMessage);
226
-
227
- // Quick prompt buttons
228
- quickPrompts.forEach(button => {
229
- button.addEventListener('click', () => {
230
- userInput.value = button.textContent;
231
- sendMessage();
232
- });
233
- });
234
 
235
- async function sendMessage() {
236
- const message = userInput.value.trim();
237
- if (!message) return;
 
238
 
239
- addUserMessage(message);
240
- userInput.value = '';
 
 
 
 
241
 
242
- const typingIndicator = addBotMessage('', true);
243
-
244
- // Simulate API delay
245
- setTimeout(async () => {
246
- const response = await getBotResponse(message);
247
- chatMessages.removeChild(typingIndicator);
248
- addBotMessage(response);
249
- }, 1000 + Math.random() * 2000);
250
  }
251
 
252
- // Initialize Feather Icons
253
  document.addEventListener('DOMContentLoaded', () => {
254
  feather.replace();
 
255
  });
256
- </script>
257
  </body>
258
  </html>
 
138
  </div>
139
 
140
  <script>
141
+ // Initialize event handlers
142
+ function initializeEventHandlers() {
143
+ // Theme Toggle
144
+ const themeToggle = document.getElementById('themeToggle');
145
+ themeToggle.addEventListener('click', handleThemeToggle);
146
+
147
+ // Chat functionality
148
+ const chatMessages = document.getElementById('chatMessages');
149
+ const userInput = document.getElementById('userInput');
150
+ const sendButton = document.getElementById('sendButton');
151
+ const quickPrompts = document.querySelectorAll('.quick-prompt');
152
+
153
+ // Send message when Enter is pressed
154
+ userInput.addEventListener('keypress', (e) => {
155
+ if (e.key === 'Enter' && !e.shiftKey) {
156
+ e.preventDefault();
157
+ handleSendMessage();
158
+ }
159
+ });
160
+
161
+ // Send button click handler
162
+ sendButton.addEventListener('click', handleSendMessage);
163
+
164
+ // Quick prompt buttons
165
+ quickPrompts.forEach(button => {
166
+ button.addEventListener('click', (e) => {
167
+ e.preventDefault();
168
+ userInput.value = button.textContent.trim();
169
+ handleSendMessage();
170
+ });
171
+ });
172
+
173
+ // Settings button click handler
174
+ const settingsButton = document.querySelector('button[aria-label="settings"]');
175
+ if (settingsButton) {
176
+ settingsButton.addEventListener('click', handleSettingsClick);
177
+ }
178
+ }
179
+
180
+ function handleThemeToggle() {
181
  document.documentElement.classList.toggle('dark');
182
+ const themeIcon = document.querySelector('#themeToggle i');
183
+
184
  if (document.documentElement.classList.contains('dark')) {
185
+ themeIcon.outerHTML = feather.icons.sun.toSvg();
186
  } else {
187
+ themeIcon.outerHTML = feather.icons.moon.toSvg();
188
  }
189
+ }
190
+
191
+ function handleSettingsClick() {
192
+ console.log('Settings clicked - implement settings modal');
193
+ }
194
+
195
+ function handleSendMessage() {
196
+ const userInput = document.getElementById('userInput');
197
+ const message = userInput.value.trim();
198
+
199
+ if (!message) return;
200
 
201
+ addUserMessage(message);
202
+ userInput.value = '';
203
+
204
+ const typingIndicator = addBotMessage('', true);
205
+
206
+ // Simulate API delay
207
+ setTimeout(async () => {
208
+ const response = await getBotResponse(message.toLowerCase());
209
+ if (typingIndicator && typingIndicator.parentNode) {
210
+ chatMessages.removeChild(typingIndicator);
211
+ }
212
+ addBotMessage(response);
213
+ }, 1000 + Math.random() * 2000);
214
+ }
215
 
216
  function addUserMessage(message) {
217
+ const chatMessages = document.getElementById('chatMessages');
218
  const messageDiv = document.createElement('div');
219
  messageDiv.className = 'chat-message user-message';
220
  messageDiv.innerHTML = `
221
  <div class="flex items-start space-x-3 justify-end">
222
  <div class="bg-gray-700 rounded-lg p-3 max-w-3xl">
223
+ <p>${escapeHtml(message)}</p>
224
  </div>
225
  <div class="bg-primary-500 p-2 rounded-full">
226
  <i data-feather="user" class="w-5 h-5 text-white"></i>
 
228
  </div>
229
  `;
230
  chatMessages.appendChild(messageDiv);
231
+ feather.replace();
232
  scrollToBottom();
233
  }
234
 
235
  function addBotMessage(message, isTyping = false) {
236
+ const chatMessages = document.getElementById('chatMessages');
237
  const messageDiv = document.createElement('div');
238
  messageDiv.className = 'chat-message bot-message';
239
 
240
  let messageContent = isTyping
241
+ ? '<span class="typing-indicator">Typing</span>'
242
+ : `<p>${formatMessage(message)}</p>`;
243
 
244
  messageDiv.innerHTML = `
245
  <div class="flex items-start space-x-3">
 
252
  </div>
253
  `;
254
  chatMessages.appendChild(messageDiv);
255
+ feather.replace();
256
  scrollToBottom();
257
 
258
+ return isTyping ? messageDiv : null;
 
 
 
259
  }
260
 
261
  function scrollToBottom() {
262
+ const chatMessages = document.getElementById('chatMessages');
263
  chatMessages.scrollTop = chatMessages.scrollHeight;
264
  }
265
 
266
+ function escapeHtml(text) {
267
+ const div = document.createElement('div');
268
+ div.textContent = text;
269
+ return div.innerHTML;
270
+ }
271
+
272
+ function formatMessage(message) {
273
+ return message
274
+ .replace(/\n/g, '<br>')
275
+ .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
276
+ .replace(/\*(.*?)\*/g, '<em>$1</em>')
277
+ .replace(/`(.*?)`/g, '<code class="bg-gray-600 px-1 rounded">$1</code>');
278
+ }
279
+
280
  // Simulate API call to Python backend
281
  async function getBotResponse(userMessage) {
 
 
 
282
  const responses = {
283
  "hello": "Hello! How can I assist you with your AI/ML learning today?",
284
  "hi": "Hi there! What AI concept would you like to explore?",
285
+ "explain backpropagation": "**Backpropagation** is the algorithm used to train neural networks. It works by:\n\n1. **Forward pass**: Compute predictions\n2. **Calculate loss**: Compare predictions with actual values\n3. **Backward pass**: Compute gradients\n4. **Update weights**: Using gradient descent\n\nIt's called 'back' propagation because gradients flow backward through the network from output to input layers.",
286
+ "show python ml example": "Here's a simple linear regression example using **scikit-learn**:\n\n```python\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.model_selection import train_test_split\nimport numpy as np\n\n# Sample data\nX = np.array([[1], [2], [3], [4], [5]])\ny = np.array([2, 4, 6, 8, 10])\n\n# Split data\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n\n# Create and train model\nmodel = LinearRegression()\nmodel.fit(X_train, y_train)\n\n# Make predictions\npredictions = model.predict(X_test)\n```",
287
+ "what's a gan": "**GANs (Generative Adversarial Networks)** consist of two neural networks:\n\n1. **Generator**: Creates fake data\n2. **Discriminator**: Distinguishes real from fake\n\nThey 'fight' each other in a zero-sum game, improving both networks. Used for generating realistic images, art, and data augmentation.",
288
+ "neural networks basics": "**Neural Networks** are computing systems inspired by biological neurons:\n\n• **Neurons**: Basic processing units\n• **Weights**: Connection strengths\n• **Biases**: Offset values\n• **Activation Functions**: Introduce non-linearity\n• **Layers**: Input, Hidden, Output\n• **Training**: Adjust weights using backpropagation",
289
+ "python pandas tips": "Here are some useful **pandas** tips:\n\n```python\n# Load data\ndf = pd.read_csv('data.csv')\n\n# Quick info\ndf.info()\ndf.describe()\n\n# Handle missing values\ndf.fillna(0, inplace=True)\n\n# Group by and aggregate\ndf.groupby('category').sum()\n\n# Efficient operations\ndf['new_col'] = df['col1'] + df['col2']\n```"
290
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
291
 
292
+ // Check for exact matches first
293
+ if (responses[userMessage]) {
294
+ return responses[userMessage];
295
+ }
296
 
297
+ // Check for partial matches
298
+ for (const [key, response] of Object.entries(responses)) {
299
+ if (userMessage.includes(key)) {
300
+ return response;
301
+ }
302
+ }
303
 
304
+ // Default response
305
+ return `I'd be happy to help with that! Could you be more specific about what aspect of AI/ML you're interested in? I can explain concepts like neural networks, provide Python code examples, or discuss algorithms like backpropagation.`;
 
 
 
 
 
 
306
  }
307
 
308
+ // Initialize when DOM is loaded
309
  document.addEventListener('DOMContentLoaded', () => {
310
  feather.replace();
311
+ initializeEventHandlers();
312
  });
313
+ </script>
314
  </body>
315
  </html>