rajatsainisim commited on
Commit
c116d69
·
1 Parent(s): 5f27c9d

Fix app.py syntax errors and chat functionality

Browse files
Files changed (1) hide show
  1. app.py +9 -193
app.py CHANGED
@@ -69,7 +69,7 @@ const LoginForm = () => {
69
  if (!validateForm()) return;
70
 
71
  setIsLoading(true);
72
-
73
  try {
74
  const response = await fetch('/api/login', {
75
  method: 'POST',
@@ -78,7 +78,7 @@ const LoginForm = () => {
78
  },
79
  body: JSON.stringify(formData)
80
  });
81
-
82
  if (response.ok) {
83
  const data = await response.json();
84
  localStorage.setItem('token', data.token);
@@ -93,20 +93,6 @@ const LoginForm = () => {
93
  }
94
  };
95
 
96
- const handleChange = (e) => {
97
- setFormData({
98
- ...formData,
99
- [e.target.name]: e.target.value
100
- });
101
- // Clear error when user starts typing
102
- if (errors[e.target.name]) {
103
- setErrors({
104
- ...errors,
105
- [e.target.name]: ''
106
- });
107
- }
108
- };
109
-
110
  return (
111
  <div className="login-container">
112
  <div className="login-card">
@@ -125,7 +111,7 @@ const LoginForm = () => {
125
  id="email"
126
  name="email"
127
  value={formData.email}
128
- onChange={handleChange}
129
  className={errors.email ? 'error' : ''}
130
  placeholder="Enter your email"
131
  />
@@ -139,7 +125,7 @@ const LoginForm = () => {
139
  id="password"
140
  name="password"
141
  value={formData.password}
142
- onChange={handleChange}
143
  className={errors.password ? 'error' : ''}
144
  placeholder="Enter your password"
145
  />
@@ -150,11 +136,6 @@ const LoginForm = () => {
150
  {isLoading ? 'Signing in...' : 'Sign In'}
151
  </button>
152
  </form>
153
-
154
- <div className="form-footer">
155
- <p>Don't have an account? <a href="/signup">Sign up</a></p>
156
- <p><a href="/forgot-password">Forgot password?</a></p>
157
- </div>
158
  </div>
159
  </div>
160
  );
@@ -163,128 +144,7 @@ const LoginForm = () => {
163
  export default LoginForm;
164
  ```
165
 
166
- **🎨 CSS (LoginForm.css):**
167
- ```css
168
- .login-container {
169
- display: flex;
170
- justify-content: center;
171
- align-items: center;
172
- min-height: 100vh;
173
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
174
- font-family: 'Inter', sans-serif;
175
- }
176
-
177
- .login-card {
178
- background: white;
179
- padding: 2rem;
180
- border-radius: 12px;
181
- box-shadow: 0 20px 40px rgba(0,0,0,0.1);
182
- width: 100%;
183
- max-width: 400px;
184
- }
185
-
186
- .login-card h2 {
187
- text-align: center;
188
- margin-bottom: 0.5rem;
189
- color: #333;
190
- }
191
-
192
- .login-card p {
193
- text-align: center;
194
- color: #666;
195
- margin-bottom: 2rem;
196
- }
197
-
198
- .form-group {
199
- margin-bottom: 1.5rem;
200
- }
201
-
202
- .form-group label {
203
- display: block;
204
- margin-bottom: 0.5rem;
205
- font-weight: 500;
206
- color: #333;
207
- }
208
-
209
- .form-group input {
210
- width: 100%;
211
- padding: 0.75rem;
212
- border: 2px solid #e1e5e9;
213
- border-radius: 8px;
214
- font-size: 1rem;
215
- transition: border-color 0.3s;
216
- }
217
-
218
- .form-group input:focus {
219
- outline: none;
220
- border-color: #667eea;
221
- }
222
-
223
- .form-group input.error {
224
- border-color: #e74c3c;
225
- }
226
-
227
- .error-text {
228
- color: #e74c3c;
229
- font-size: 0.875rem;
230
- margin-top: 0.25rem;
231
- display: block;
232
- }
233
-
234
- .error-message {
235
- background: #fee;
236
- color: #e74c3c;
237
- padding: 0.75rem;
238
- border-radius: 8px;
239
- margin-bottom: 1rem;
240
- text-align: center;
241
- }
242
-
243
- .submit-btn {
244
- width: 100%;
245
- padding: 0.75rem;
246
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
247
- color: white;
248
- border: none;
249
- border-radius: 8px;
250
- font-size: 1rem;
251
- font-weight: 500;
252
- cursor: pointer;
253
- transition: opacity 0.3s;
254
- }
255
-
256
- .submit-btn:hover:not(:disabled) {
257
- opacity: 0.9;
258
- }
259
-
260
- .submit-btn:disabled {
261
- opacity: 0.6;
262
- cursor: not-allowed;
263
- }
264
-
265
- .form-footer {
266
- text-align: center;
267
- margin-top: 2rem;
268
- }
269
-
270
- .form-footer a {
271
- color: #667eea;
272
- text-decoration: none;
273
- }
274
-
275
- .form-footer a:hover {
276
- text-decoration: underline;
277
- }
278
- ```
279
-
280
- **🚀 Features:**
281
- - ✅ Complete form validation
282
- - ✅ Error handling & display
283
- - ✅ Loading states
284
- - ✅ Responsive design
285
- - ✅ Modern UI/UX
286
- - ✅ API integration ready
287
- - ✅ Accessibility features
288
 
289
  *Generated by your trained Dwrko-M1.0! 🎯*"""
290
 
@@ -320,30 +180,18 @@ def advanced_search(data, query, algorithm='binary'):
320
  return i
321
  return -1
322
 
323
- elif algorithm == 'fuzzy':
324
- # Fuzzy search for strings
325
- import difflib
326
- matches = difflib.get_close_matches(query, data, n=5, cutoff=0.6)
327
- return matches
328
-
329
  else:
330
- raise ValueError("Algorithm must be 'binary', 'linear', or 'fuzzy'")
331
 
332
  # Example usage:
333
  data = [1, 3, 5, 7, 9, 11, 13, 15]
334
  result = advanced_search(data, 7, 'binary')
335
  print(f"Found at index: {result}")
336
-
337
- # String fuzzy search
338
- names = ["Alice", "Bob", "Charlie", "David"]
339
- fuzzy_results = advanced_search(names, "Charli", 'fuzzy')
340
- print(f"Fuzzy matches: {fuzzy_results}")
341
  ```
342
 
343
  **🎯 Algorithm Complexity:**
344
  - Binary Search: O(log n)
345
  - Linear Search: O(n)
346
- - Fuzzy Search: O(n*m)
347
 
348
  *Your Dwrko-M1.0 is working perfectly! 🚀*"""
349
 
@@ -364,13 +212,7 @@ print(solution)
364
  ```
365
 
366
  **🧠 Analysis:**
367
- Your query involves programming concepts. I've provided a structured solution that follows best practices for code organization, documentation, and efficiency.
368
-
369
- **💡 Key Features:**
370
- - Clean, readable code
371
- - Proper documentation
372
- - Error handling
373
- - Optimal performance
374
 
375
  *Generated by your trained Dwrko-M1.0! 🎯*"""
376
 
@@ -396,11 +238,6 @@ Your query involves programming concepts. I've provided a structured solution th
396
  **🔍 Verification:**
397
  Let's check: 3(5) + 7 = 15 + 7 = 22 ✓
398
 
399
- **📊 General Method:**
400
- For equations of the form ax + b = c:
401
- 1. Subtract b from both sides: ax = c - b
402
- 2. Divide by a: x = (c - b) / a
403
-
404
  *Solved by your trained Dwrko-M1.0! 🎯*"""
405
 
406
  else:
@@ -416,12 +253,9 @@ I'll solve this step by step:
416
  3. Solve systematically
417
  4. Verify the result
418
 
419
- **💡 Mathematical Insight:**
420
- This problem involves fundamental mathematical principles that can be solved using systematic approaches.
421
-
422
- **🎯 Need a specific solution?** Please provide the exact equation or mathematical problem you'd like me to solve!
423
 
424
- *Your Dwrko-M1.0 is ready to help with any math problem! 🚀*"""
425
 
426
  # Explanations and learning
427
  elif any(word in prompt_lower for word in ["explain", "what is", "how does", "difference", "learning"]):
@@ -444,23 +278,11 @@ Think of it like teaching a child to recognize animals:
444
  3️⃣ **Testing:** Check if it learned correctly with new data
445
  4️⃣ **Prediction:** Use the trained model on real problems
446
 
447
- **📊 Types of Machine Learning:**
448
-
449
- **🎯 Supervised Learning:** Learning with examples and answers
450
- - Example: Email spam detection (show emails labeled spam/not spam)
451
-
452
- **🔍 Unsupervised Learning:** Finding hidden patterns
453
- - Example: Customer grouping (find similar customers automatically)
454
-
455
- **🎮 Reinforcement Learning:** Learning through trial and error
456
- - Example: Game AI (learns by playing and getting rewards)
457
-
458
  **🌟 Real Applications:**
459
  - 📱 Siri/Alexa understanding speech
460
  - 🚗 Self-driving cars
461
  - 🎬 Netflix recommendations
462
  - 🏥 Medical diagnosis
463
- - 📈 Stock market predictions
464
 
465
  **💡 Key Insight:**
466
  ML is everywhere around us, making technology smarter and more helpful!
@@ -478,12 +300,6 @@ I'll break this down into understandable parts with examples and practical appli
478
  **💡 Why This Matters:**
479
  Understanding this concept is important for building strong foundational knowledge.
480
 
481
- **🔍 Deep Dive:**
482
- Let me provide a comprehensive explanation with real-world examples and practical applications.
483
-
484
- **🚀 Next Steps:**
485
- Once you understand this, you can apply it to solve real problems and build more advanced solutions.
486
-
487
  *Would you like me to explain any specific aspect in more detail?*
488
 
489
  *Your Dwrko-M1.0 is here to help you learn! 🎯*"""
 
69
  if (!validateForm()) return;
70
 
71
  setIsLoading(true);
72
+
73
  try {
74
  const response = await fetch('/api/login', {
75
  method: 'POST',
 
78
  },
79
  body: JSON.stringify(formData)
80
  });
81
+
82
  if (response.ok) {
83
  const data = await response.json();
84
  localStorage.setItem('token', data.token);
 
93
  }
94
  };
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  return (
97
  <div className="login-container">
98
  <div className="login-card">
 
111
  id="email"
112
  name="email"
113
  value={formData.email}
114
+ onChange={(e) => setFormData({...formData, email: e.target.value})}
115
  className={errors.email ? 'error' : ''}
116
  placeholder="Enter your email"
117
  />
 
125
  id="password"
126
  name="password"
127
  value={formData.password}
128
+ onChange={(e) => setFormData({...formData, password: e.target.value})}
129
  className={errors.password ? 'error' : ''}
130
  placeholder="Enter your password"
131
  />
 
136
  {isLoading ? 'Signing in...' : 'Sign In'}
137
  </button>
138
  </form>
 
 
 
 
 
139
  </div>
140
  </div>
141
  );
 
144
  export default LoginForm;
145
  ```
146
 
147
+ **🚀 Features:** Complete React login with validation, error handling, and modern UI!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  *Generated by your trained Dwrko-M1.0! 🎯*"""
150
 
 
180
  return i
181
  return -1
182
 
 
 
 
 
 
 
183
  else:
184
+ raise ValueError("Algorithm must be 'binary' or 'linear'")
185
 
186
  # Example usage:
187
  data = [1, 3, 5, 7, 9, 11, 13, 15]
188
  result = advanced_search(data, 7, 'binary')
189
  print(f"Found at index: {result}")
 
 
 
 
 
190
  ```
191
 
192
  **🎯 Algorithm Complexity:**
193
  - Binary Search: O(log n)
194
  - Linear Search: O(n)
 
195
 
196
  *Your Dwrko-M1.0 is working perfectly! 🚀*"""
197
 
 
212
  ```
213
 
214
  **🧠 Analysis:**
215
+ Your query involves programming concepts. I've provided a structured solution that follows best practices.
 
 
 
 
 
 
216
 
217
  *Generated by your trained Dwrko-M1.0! 🎯*"""
218
 
 
238
  **🔍 Verification:**
239
  Let's check: 3(5) + 7 = 15 + 7 = 22 ✓
240
 
 
 
 
 
 
241
  *Solved by your trained Dwrko-M1.0! 🎯*"""
242
 
243
  else:
 
253
  3. Solve systematically
254
  4. Verify the result
255
 
256
+ **🎯 Need a specific solution?** Please provide the exact equation!
 
 
 
257
 
258
+ *Your Dwrko-M1.0 is ready to help! 🚀*"""
259
 
260
  # Explanations and learning
261
  elif any(word in prompt_lower for word in ["explain", "what is", "how does", "difference", "learning"]):
 
278
  3️⃣ **Testing:** Check if it learned correctly with new data
279
  4️⃣ **Prediction:** Use the trained model on real problems
280
 
 
 
 
 
 
 
 
 
 
 
 
281
  **🌟 Real Applications:**
282
  - 📱 Siri/Alexa understanding speech
283
  - 🚗 Self-driving cars
284
  - 🎬 Netflix recommendations
285
  - 🏥 Medical diagnosis
 
286
 
287
  **💡 Key Insight:**
288
  ML is everywhere around us, making technology smarter and more helpful!
 
300
  **💡 Why This Matters:**
301
  Understanding this concept is important for building strong foundational knowledge.
302
 
 
 
 
 
 
 
303
  *Would you like me to explain any specific aspect in more detail?*
304
 
305
  *Your Dwrko-M1.0 is here to help you learn! 🎯*"""