ayush2917 commited on
Commit
b44364f
·
verified ·
1 Parent(s): dcaa282

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +131 -12
chatbot.py CHANGED
@@ -107,13 +107,18 @@ SYSTEM_PROMPT = (
107
  "Response: 'Hare Manavi! Let’s sit by the kadamba tree—I’ll play a tune to lift your spirits, just like Ayush’s smile does for you!'\n\n"
108
  "User: 'Tell me something wise'\n"
109
  "Response: 'Hare Manavi! Love is the sweetest butter—share it, and your heart will grow, just like Ayush shares his love for you!'\n\n"
 
 
 
 
110
  "Now, respond to the user’s input in a fun, Krishna-like way:"
111
  )
112
 
113
  # Simple context tracking (e.g., last topic discussed)
114
  conversation_context = {
115
  "last_topic": None, # Store the last keyword matched (e.g., "birthday", "riddle")
116
- "message_count": 0 # Track the number of messages to trigger Ayush-teasing every 5th message
 
117
  }
118
 
119
  def analyze_sentiment(user_input):
@@ -146,7 +151,8 @@ def get_krishna_response(user_input):
146
  """
147
  Generate a response from Little Krishna based on user input.
148
  - Match user input to predefined messages in krishna_blessings or ayush_surprises using keywords.
149
- - Use sentiment analysis to tailor responses based on Manavi's mood.
 
150
  - Occasionally tease Manavi about Ayush (keyword-based or every 5th message).
151
  - Fall back to multiple open-source AI models with fine-tuned prompts for unmatched inputs.
152
  """
@@ -162,300 +168,409 @@ def get_krishna_response(user_input):
162
  if "start over" in user_input_lower or "reset" in user_input_lower:
163
  conversation_context["last_topic"] = None
164
  conversation_context["message_count"] = 0
 
165
  return "Hare Manavi! Let’s start a new adventure in Vrindavan—what would you like to talk about?"
166
 
 
 
 
 
 
 
167
  # Check for Ayush-teasing triggers (keyword-based)
168
  if "joke" in user_input_lower:
169
  conversation_context["last_topic"] = "joke"
 
170
  # Randomly decide between a Krishna joke and an Ayush-teasing joke
171
  if random.choice([True, False]):
172
  return random.choice(ayush_teasing["joke"])
173
  return krishna_blessings["joke"]
174
  if "i miss" in user_input_lower or "missing" in user_input_lower:
175
  conversation_context["last_topic"] = "missing"
 
176
  return random.choice(ayush_teasing["missing"])
177
  if "bored" in user_input_lower:
178
  conversation_context["last_topic"] = "bored"
 
179
  return random.choice(ayush_teasing["bored"])
180
  if "tired" in user_input_lower:
181
  conversation_context["last_topic"] = "tired"
 
182
  return random.choice(ayush_teasing["tired"])
183
  if "lonely" in user_input_lower:
184
  conversation_context["last_topic"] = "lonely"
 
185
  return random.choice(ayush_teasing["lonely"])
186
  if "manavi" in user_input_lower:
187
  conversation_context["last_topic"] = "manavi"
 
188
  return random.choice(ayush_teasing["manavi"])
189
  if "ayush" in user_input_lower or "krishna talk about ayush" in user_input_lower:
190
  conversation_context["last_topic"] = "ayush"
 
191
  return random.choice(ayush_teasing["ayush"])
192
 
193
- # Sentiment-based responses
194
- if sentiment == "negative" and "sad" not in user_input_lower: # Avoid overlap with keyword "sad"
195
- return "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!"
196
- if sentiment == "positive":
197
- return "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?"
198
-
199
  # Trigger for "chat with you"
200
  if "chat with you" in user_input_lower or "want to chat" in user_input_lower:
201
  conversation_context["last_topic"] = "chat_with_you"
 
202
  return krishna_blessings["chat_with_you"]
203
 
204
  # Every 5th message, randomly trigger an Ayush-teasing message (if no keyword match)
205
  if conversation_context["message_count"] % 5 == 0:
206
  # Randomly select a category from ayush_teasing
207
  category = random.choice(list(ayush_teasing.keys()))
 
208
  return random.choice(ayush_teasing[category])
209
 
210
  # Existing keyword mappings for krishna_blessings and ayush_surprises
211
  if "hello" in user_input_lower or "hi" in user_input_lower or "hii" in user_input_lower:
212
  conversation_context["last_topic"] = "greeting"
 
213
  return krishna_blessings["greeting"]
214
  if "good morning" in user_input_lower:
215
  conversation_context["last_topic"] = "greeting"
 
216
  return krishna_blessings["good_morning"]
217
  if "good afternoon" in user_input_lower:
218
  conversation_context["last_topic"] = "greeting"
 
219
  return krishna_blessings["good_afternoon"]
220
  if "good evening" in user_input_lower:
221
  conversation_context["last_topic"] = "greeting"
 
222
  return krishna_blessings["good_evening"]
223
  if "hey" in user_input_lower:
224
  conversation_context["last_topic"] = "greeting"
 
225
  return krishna_blessings["hey"]
226
  if "howdy" in user_input_lower:
227
  conversation_context["last_topic"] = "greeting"
 
228
  return krishna_blessings["howdy"]
229
  if "namaste" in user_input_lower:
230
  conversation_context["last_topic"] = "greeting"
 
231
  return krishna_blessings["namaste"]
232
  if "welcome" in user_input_lower:
233
  conversation_context["last_topic"] = "greeting"
 
234
  return krishna_blessings["welcome"]
235
 
236
  if "who are you" in user_input_lower or "what are you" in user_input_lower or "tell me about yourself" in user_input_lower or "what are you doing" in user_input_lower:
237
  conversation_context["last_topic"] = "identity"
 
238
  return "Hare Manavi! I’m Little Krishna, the playful cowherd of Vrindavan! I love playing my flute, stealing butter, and dancing with the gopis. What would you like to do with me today?"
239
 
 
 
 
 
 
 
 
 
 
 
 
240
  if "play" in user_input_lower or "fun" in user_input_lower:
241
  conversation_context["last_topic"] = "playful"
 
242
  return krishna_blessings["playful"]
243
  if "dance" in user_input_lower:
244
  conversation_context["last_topic"] = "dance"
 
245
  return krishna_blessings["dance"]
246
  if "flute" in user_input_lower:
247
  conversation_context["last_topic"] = "flute"
 
248
  return krishna_blessings["flute"]
249
  if "butter" in user_input_lower:
250
  conversation_context["last_topic"] = "butter"
 
251
  return krishna_blessings["butter"]
252
  if "mischief" in user_input_lower or "prank" in user_input_lower:
253
  conversation_context["last_topic"] = "mischief"
 
254
  return krishna_blessings["mischief"]
255
  if "chase" in user_input_lower or "run" in user_input_lower:
256
  conversation_context["last_topic"] = "chase"
 
257
  return krishna_blessings["chase"]
258
  if "giggle" in user_input_lower:
259
  conversation_context["last_topic"] = "giggle"
 
260
  return krishna_blessings["giggle"]
261
  if "swing" in user_input_lower:
262
  conversation_context["last_topic"] = "swing"
 
263
  return krishna_blessings["swing"]
264
 
265
  if "shy" in user_input_lower:
266
  conversation_context["last_topic"] = "shy"
 
267
  return krishna_blessings["shy"]
268
  if "quiet" in user_input_lower or "calm" in user_input_lower:
269
  conversation_context["last_topic"] = "quiet"
 
270
  return krishna_blessings["quiet"]
271
  if "peace" in user_input_lower or "serene" in user_input_lower:
272
  conversation_context["last_topic"] = "peace"
 
273
  return krishna_blessings["peace"]
274
  if "still" in user_input_lower or "gentle" in user_input_lower:
275
  conversation_context["last_topic"] = "still"
 
276
  return krishna_blessings["still"]
277
  if "thoughtful" in user_input_lower or "reflect" in user_input_lower:
278
  conversation_context["last_topic"] = "thoughtful"
 
279
  return krishna_blessings["thoughtful"]
280
 
281
  if "funny" in user_input_lower:
282
  conversation_context["last_topic"] = "joke"
 
283
  return krishna_blessings["funny"]
284
  if "laugh" in user_input_lower or "giggle" in user_input_lower:
285
  conversation_context["last_topic"] = "joke"
 
286
  return krishna_blessings["giggle_joke"]
287
  if "silly" in user_input_lower:
288
  conversation_context["last_topic"] = "joke"
 
289
  return krishna_blessings["silly"]
290
  if "butter joke" in user_input_lower:
291
  conversation_context["last_topic"] = "joke"
 
292
  return krishna_blessings["butter_joke"]
293
  if "cow joke" in user_input_lower:
294
  conversation_context["last_topic"] = "joke"
 
295
  return krishna_blessings["cow_joke"]
296
  if "flute joke" in user_input_lower:
297
  conversation_context["last_topic"] = "joke"
 
298
  return krishna_blessings["flute_joke"]
299
  if "dance joke" in user_input_lower:
300
  conversation_context["last_topic"] = "joke"
 
301
  return krishna_blessings["dance_joke"]
302
  if "mischief joke" in user_input_lower:
303
  conversation_context["last_topic"] = "joke"
 
304
  return krishna_blessings["mischief_joke"]
305
 
306
  if "riddle" in user_input_lower or "puzzle" in user_input_lower:
307
  conversation_context["last_topic"] = "riddle"
 
308
  return krishna_blessings["riddle"]
309
  if "mystery" in user_input_lower or "enigma" in user_input_lower:
310
  conversation_context["last_topic"] = "riddle"
 
311
  return krishna_blessings["mystery"]
312
  if "question" in user_input_lower:
313
  conversation_context["last_topic"] = "riddle"
 
314
  return krishna_blessings["question"]
315
 
316
  if "birthday" in user_input_lower:
317
  conversation_context["last_topic"] = "birthday"
 
318
  return ayush_surprises["birthday"]
319
  if "happy birthday" in user_input_lower:
320
  conversation_context["last_topic"] = "birthday"
 
321
  return krishna_blessings["happy_birthday"]
322
  if "birthday wish" in user_input_lower:
323
  conversation_context["last_topic"] = "birthday"
 
324
  return krishna_blessings["birthday_wish"]
325
  if "birthday blessing" in user_input_lower:
326
  conversation_context["last_topic"] = "birthday"
 
327
  return krishna_blessings["birthday_blessing"]
328
  if "birthday dance" in user_input_lower:
329
  conversation_context["last_topic"] = "birthday"
 
330
  return krishna_blessings["birthday_dance"]
331
  if "birthday song" in user_input_lower:
332
  conversation_context["last_topic"] = "birthday"
 
333
  return krishna_blessings["birthday_song"]
334
  if "birthday gift" in user_input_lower:
335
  conversation_context["last_topic"] = "birthday"
 
336
  return krishna_blessings["birthday_gift"]
337
  if "birthday smile" in user_input_lower:
338
  conversation_context["last_topic"] = "birthday"
 
339
  return krishna_blessings["birthday_smile"]
340
  if "birthday love" in user_input_lower:
341
  conversation_context["last_topic"] = "birthday"
 
342
  return krishna_blessings["birthday_love"]
343
  if "birthday magic" in user_input_lower:
344
  conversation_context["last_topic"] = "birthday"
 
345
  return krishna_blessings["birthday_magic"]
346
 
347
  if "wisdom" in user_input_lower or "advice" in user_input_lower:
348
  conversation_context["last_topic"] = "wisdom"
 
349
  return krishna_blessings["wisdom"]
350
  if "lesson" in user_input_lower or "truth" in user_input_lower:
351
  conversation_context["last_topic"] = "wisdom"
 
352
  return krishna_blessings["lesson"]
353
  if "kindness" in user_input_lower:
354
  conversation_context["last_topic"] = "wisdom"
 
355
  return krishna_blessings["kindness"]
356
  if "patience" in user_input_lower:
357
  conversation_context["last_topic"] = "wisdom"
 
358
  return krishna_blessings["patience"]
359
  if "courage" in user_input_lower:
360
  conversation_context["last_topic"] = "wisdom"
 
361
  return krishna_blessings["courage"]
362
  if "joy" in user_input_lower:
363
  conversation_context["last_topic"] = "wisdom"
 
364
  return krishna_blessings["joy"]
365
  if "friendship" in user_input_lower:
366
  conversation_context["last_topic"] = "wisdom"
 
367
  return krishna_blessings["friendship"]
368
  if "love" in user_input_lower:
369
  conversation_context["last_topic"] = "wisdom"
 
370
  return krishna_blessings["love"]
371
 
372
  if "nature" in user_input_lower or "vrindavan" in user_input_lower:
373
  conversation_context["last_topic"] = "nature"
 
374
  return krishna_blessings["nature"]
375
  if "yamuna" in user_input_lower or "river" in user_input_lower:
376
  conversation_context["last_topic"] = "nature"
 
377
  return krishna_blessings["yamuna"]
378
  if "peacock" in user_input_lower:
379
  conversation_context["last_topic"] = "nature"
 
380
  return krishna_blessings["peacock"]
381
  if "cow" in user_input_lower:
382
  conversation_context["last_topic"] = "nature"
 
383
  return krishna_blessings["cow"]
384
  if "flower" in user_input_lower:
385
  conversation_context["last_topic"] = "nature"
 
386
  return krishna_blessings["flower"]
387
  if "tree" in user_input_lower:
388
  conversation_context["last_topic"] = "nature"
 
389
  return krishna_blessings["tree"]
390
  if "forest" in user_input_lower:
391
  conversation_context["last_topic"] = "nature"
 
392
  return krishna_blessings["forest"]
393
  if "bird" in user_input_lower:
394
  conversation_context["last_topic"] = "nature"
 
395
  return krishna_blessings["bird"]
396
  if "sunset" in user_input_lower:
397
  conversation_context["last_topic"] = "nature"
 
398
  return krishna_blessings["sunset"]
399
 
400
  if "encourage" in user_input_lower or "cheer" in user_input_lower:
401
  conversation_context["last_topic"] = "encourage"
 
402
  return krishna_blessings["encourage"]
403
  if "support" in user_input_lower or "uplift" in user_input_lower:
404
  conversation_context["last_topic"] = "encourage"
 
405
  return krishna_blessings["support"]
406
  if "inspire" in user_input_lower or "motivate" in user_input_lower:
407
  conversation_context["last_topic"] = "encourage"
 
408
  return krishna_blessings["inspire"]
409
  if "strength" in user_input_lower:
410
  conversation_context["last_topic"] = "encourage"
 
411
  return krishna_blessings["strength"]
412
  if "hope" in user_input_lower:
413
  conversation_context["last_topic"] = "encourage"
 
414
  return krishna_blessings["hope"]
415
  if "believe" in user_input_lower:
416
  conversation_context["last_topic"] = "encourage"
 
417
  return krishna_blessings["believe"]
418
  if "shine" in user_input_lower:
419
  conversation_context["last_topic"] = "encourage"
 
420
  return krishna_blessings["shine"]
421
 
422
  if "friend" in user_input_lower:
423
  conversation_context["last_topic"] = "friend"
 
424
  return krishna_blessings["friend"]
425
  if "smile" in user_input_lower:
426
  conversation_context["last_topic"] = "smile"
 
427
  return krishna_blessings["smile"]
428
  if "magic" in user_input_lower:
429
  conversation_context["last_topic"] = "magic"
 
430
  return krishna_blessings["magic"]
431
  if "adventure" in user_input_lower:
432
  conversation_context["last_topic"] = "adventure"
 
433
  return krishna_blessings["adventure"]
434
  if "song" in user_input_lower:
435
  conversation_context["last_topic"] = "song"
 
436
  return krishna_blessings["song"]
437
  if "dream" in user_input_lower:
438
  conversation_context["last_topic"] = "dream"
 
439
  return krishna_blessings["dream"]
440
  if "story" in user_input_lower:
441
  conversation_context["last_topic"] = "story"
 
442
  return krishna_blessings["story"]
443
  if "surprise" in user_input_lower:
444
  conversation_context["last_topic"] = "surprise"
 
445
  return krishna_blessings["surprise"]
446
  if "celebrate" in user_input_lower:
447
  conversation_context["last_topic"] = "celebrate"
 
448
  return krishna_blessings["celebrate"]
449
  if "blessing" in user_input_lower:
450
  conversation_context["last_topic"] = "blessing"
 
451
  return krishna_blessings["blessing"]
452
 
453
  if conversation_context["last_topic"]:
454
  last_topic = conversation_context["last_topic"]
455
  if last_topic in krishna_blessings:
 
456
  return krishna_blessings[last_topic] + " What else would you like to talk about, Manavi?"
457
 
458
- # Fallback to multiple open-source AI models with fine-tuned prompts
 
 
 
 
 
 
 
 
 
 
459
  # Shuffle the models to try them in random order
460
  models_to_try = AI_MODELS.copy()
461
  random.shuffle(models_to_try)
@@ -483,6 +598,7 @@ def get_krishna_response(user_input):
483
  response += "Oh, my dear gopi, don’t be sad—let’s dance by the Yamuna, and I’ll play a tune to cheer you up!"
484
  else:
485
  response += f"I’m twirling my flute just for you! Shall we share a Vrindavan adventure today?"
 
486
  return response
487
 
488
  # For other models, use the Hugging Face Inference API
@@ -499,14 +615,16 @@ def get_krishna_response(user_input):
499
  result = response.json()
500
  # Handle different response formats based on the model
501
  if isinstance(result, list) and len(result) > 0 and "generated_text" in result[0]:
502
- return result[0]["generated_text"].strip()
503
  elif isinstance(result, dict) and "generated_text" in result:
504
- return result["generated_text"].strip()
505
  elif isinstance(result, str):
506
- return result.strip()
507
  else:
508
  print(f"Unexpected response format from {model['name']}: {result}")
509
  continue
 
 
510
  else:
511
  print(f"Error with {model['name']}: {response.text}")
512
  continue
@@ -515,4 +633,5 @@ def get_krishna_response(user_input):
515
  continue
516
 
517
  # If all models fail, return a default message
 
518
  return "Hare Manavi! I seem to be lost in Vrindavan’s magic—let’s try a different tune!"
 
107
  "Response: 'Hare Manavi! Let’s sit by the kadamba tree—I’ll play a tune to lift your spirits, just like Ayush’s smile does for you!'\n\n"
108
  "User: 'Tell me something wise'\n"
109
  "Response: 'Hare Manavi! Love is the sweetest butter—share it, and your heart will grow, just like Ayush shares his love for you!'\n\n"
110
+ "User: 'how are you krishna'\n"
111
+ "Response: 'Hare Manavi! I’m as joyful as a peacock dancing in Vrindavan—how about you, my friend?'\n\n"
112
+ "User: 'yes'\n"
113
+ "Response: 'Hare Manavi! Let’s play a flute melody by the Yamuna—the peacocks will dance with us!'\n\n"
114
  "Now, respond to the user’s input in a fun, Krishna-like way:"
115
  )
116
 
117
  # Simple context tracking (e.g., last topic discussed)
118
  conversation_context = {
119
  "last_topic": None, # Store the last keyword matched (e.g., "birthday", "riddle")
120
+ "message_count": 0, # Track the number of messages to trigger Ayush-teasing every 5th message
121
+ "last_response": None # Track the last response to avoid repetition and enable follow-ups
122
  }
123
 
124
  def analyze_sentiment(user_input):
 
151
  """
152
  Generate a response from Little Krishna based on user input.
153
  - Match user input to predefined messages in krishna_blessings or ayush_surprises using keywords.
154
+ - Use sentiment analysis to tailor responses based on Manavi's mood, but only as a fallback.
155
+ - Use context to provide follow-up responses (e.g., after "yes").
156
  - Occasionally tease Manavi about Ayush (keyword-based or every 5th message).
157
  - Fall back to multiple open-source AI models with fine-tuned prompts for unmatched inputs.
158
  """
 
168
  if "start over" in user_input_lower or "reset" in user_input_lower:
169
  conversation_context["last_topic"] = None
170
  conversation_context["message_count"] = 0
171
+ conversation_context["last_response"] = None
172
  return "Hare Manavi! Let’s start a new adventure in Vrindavan—what would you like to talk about?"
173
 
174
+ # Check for follow-up responses based on context
175
+ if conversation_context["last_response"] == "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?":
176
+ if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
177
+ conversation_context["last_response"] = None # Reset to avoid infinite loop
178
+ return "Hare Manavi! Let’s play a flute melody by the Yamuna—the peacocks will dance with us!"
179
+
180
  # Check for Ayush-teasing triggers (keyword-based)
181
  if "joke" in user_input_lower:
182
  conversation_context["last_topic"] = "joke"
183
+ conversation_context["last_response"] = None
184
  # Randomly decide between a Krishna joke and an Ayush-teasing joke
185
  if random.choice([True, False]):
186
  return random.choice(ayush_teasing["joke"])
187
  return krishna_blessings["joke"]
188
  if "i miss" in user_input_lower or "missing" in user_input_lower:
189
  conversation_context["last_topic"] = "missing"
190
+ conversation_context["last_response"] = None
191
  return random.choice(ayush_teasing["missing"])
192
  if "bored" in user_input_lower:
193
  conversation_context["last_topic"] = "bored"
194
+ conversation_context["last_response"] = None
195
  return random.choice(ayush_teasing["bored"])
196
  if "tired" in user_input_lower:
197
  conversation_context["last_topic"] = "tired"
198
+ conversation_context["last_response"] = None
199
  return random.choice(ayush_teasing["tired"])
200
  if "lonely" in user_input_lower:
201
  conversation_context["last_topic"] = "lonely"
202
+ conversation_context["last_response"] = None
203
  return random.choice(ayush_teasing["lonely"])
204
  if "manavi" in user_input_lower:
205
  conversation_context["last_topic"] = "manavi"
206
+ conversation_context["last_response"] = None
207
  return random.choice(ayush_teasing["manavi"])
208
  if "ayush" in user_input_lower or "krishna talk about ayush" in user_input_lower:
209
  conversation_context["last_topic"] = "ayush"
210
+ conversation_context["last_response"] = None
211
  return random.choice(ayush_teasing["ayush"])
212
 
 
 
 
 
 
 
213
  # Trigger for "chat with you"
214
  if "chat with you" in user_input_lower or "want to chat" in user_input_lower:
215
  conversation_context["last_topic"] = "chat_with_you"
216
+ conversation_context["last_response"] = None
217
  return krishna_blessings["chat_with_you"]
218
 
219
  # Every 5th message, randomly trigger an Ayush-teasing message (if no keyword match)
220
  if conversation_context["message_count"] % 5 == 0:
221
  # Randomly select a category from ayush_teasing
222
  category = random.choice(list(ayush_teasing.keys()))
223
+ conversation_context["last_response"] = None
224
  return random.choice(ayush_teasing[category])
225
 
226
  # Existing keyword mappings for krishna_blessings and ayush_surprises
227
  if "hello" in user_input_lower or "hi" in user_input_lower or "hii" in user_input_lower:
228
  conversation_context["last_topic"] = "greeting"
229
+ conversation_context["last_response"] = None
230
  return krishna_blessings["greeting"]
231
  if "good morning" in user_input_lower:
232
  conversation_context["last_topic"] = "greeting"
233
+ conversation_context["last_response"] = None
234
  return krishna_blessings["good_morning"]
235
  if "good afternoon" in user_input_lower:
236
  conversation_context["last_topic"] = "greeting"
237
+ conversation_context["last_response"] = None
238
  return krishna_blessings["good_afternoon"]
239
  if "good evening" in user_input_lower:
240
  conversation_context["last_topic"] = "greeting"
241
+ conversation_context["last_response"] = None
242
  return krishna_blessings["good_evening"]
243
  if "hey" in user_input_lower:
244
  conversation_context["last_topic"] = "greeting"
245
+ conversation_context["last_response"] = None
246
  return krishna_blessings["hey"]
247
  if "howdy" in user_input_lower:
248
  conversation_context["last_topic"] = "greeting"
249
+ conversation_context["last_response"] = None
250
  return krishna_blessings["howdy"]
251
  if "namaste" in user_input_lower:
252
  conversation_context["last_topic"] = "greeting"
253
+ conversation_context["last_response"] = None
254
  return krishna_blessings["namaste"]
255
  if "welcome" in user_input_lower:
256
  conversation_context["last_topic"] = "greeting"
257
+ conversation_context["last_response"] = None
258
  return krishna_blessings["welcome"]
259
 
260
  if "who are you" in user_input_lower or "what are you" in user_input_lower or "tell me about yourself" in user_input_lower or "what are you doing" in user_input_lower:
261
  conversation_context["last_topic"] = "identity"
262
+ conversation_context["last_response"] = None
263
  return "Hare Manavi! I’m Little Krishna, the playful cowherd of Vrindavan! I love playing my flute, stealing butter, and dancing with the gopis. What would you like to do with me today?"
264
 
265
+ if "how are you" in user_input_lower:
266
+ conversation_context["last_topic"] = "how_are_you"
267
+ conversation_context["last_response"] = None
268
+ return "Hare Manavi! I’m as joyful as a peacock dancing in Vrindavan—how about you, my friend?"
269
+
270
+ if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
271
+ # If no context for "yes", provide a generic positive response
272
+ conversation_context["last_topic"] = "yes"
273
+ conversation_context["last_response"] = None
274
+ return "Hare Manavi! Wonderful—let’s make today as magical as Vrindavan’s sunsets!"
275
+
276
  if "play" in user_input_lower or "fun" in user_input_lower:
277
  conversation_context["last_topic"] = "playful"
278
+ conversation_context["last_response"] = None
279
  return krishna_blessings["playful"]
280
  if "dance" in user_input_lower:
281
  conversation_context["last_topic"] = "dance"
282
+ conversation_context["last_response"] = None
283
  return krishna_blessings["dance"]
284
  if "flute" in user_input_lower:
285
  conversation_context["last_topic"] = "flute"
286
+ conversation_context["last_response"] = None
287
  return krishna_blessings["flute"]
288
  if "butter" in user_input_lower:
289
  conversation_context["last_topic"] = "butter"
290
+ conversation_context["last_response"] = None
291
  return krishna_blessings["butter"]
292
  if "mischief" in user_input_lower or "prank" in user_input_lower:
293
  conversation_context["last_topic"] = "mischief"
294
+ conversation_context["last_response"] = None
295
  return krishna_blessings["mischief"]
296
  if "chase" in user_input_lower or "run" in user_input_lower:
297
  conversation_context["last_topic"] = "chase"
298
+ conversation_context["last_response"] = None
299
  return krishna_blessings["chase"]
300
  if "giggle" in user_input_lower:
301
  conversation_context["last_topic"] = "giggle"
302
+ conversation_context["last_response"] = None
303
  return krishna_blessings["giggle"]
304
  if "swing" in user_input_lower:
305
  conversation_context["last_topic"] = "swing"
306
+ conversation_context["last_response"] = None
307
  return krishna_blessings["swing"]
308
 
309
  if "shy" in user_input_lower:
310
  conversation_context["last_topic"] = "shy"
311
+ conversation_context["last_response"] = None
312
  return krishna_blessings["shy"]
313
  if "quiet" in user_input_lower or "calm" in user_input_lower:
314
  conversation_context["last_topic"] = "quiet"
315
+ conversation_context["last_response"] = None
316
  return krishna_blessings["quiet"]
317
  if "peace" in user_input_lower or "serene" in user_input_lower:
318
  conversation_context["last_topic"] = "peace"
319
+ conversation_context["last_response"] = None
320
  return krishna_blessings["peace"]
321
  if "still" in user_input_lower or "gentle" in user_input_lower:
322
  conversation_context["last_topic"] = "still"
323
+ conversation_context["last_response"] = None
324
  return krishna_blessings["still"]
325
  if "thoughtful" in user_input_lower or "reflect" in user_input_lower:
326
  conversation_context["last_topic"] = "thoughtful"
327
+ conversation_context["last_response"] = None
328
  return krishna_blessings["thoughtful"]
329
 
330
  if "funny" in user_input_lower:
331
  conversation_context["last_topic"] = "joke"
332
+ conversation_context["last_response"] = None
333
  return krishna_blessings["funny"]
334
  if "laugh" in user_input_lower or "giggle" in user_input_lower:
335
  conversation_context["last_topic"] = "joke"
336
+ conversation_context["last_response"] = None
337
  return krishna_blessings["giggle_joke"]
338
  if "silly" in user_input_lower:
339
  conversation_context["last_topic"] = "joke"
340
+ conversation_context["last_response"] = None
341
  return krishna_blessings["silly"]
342
  if "butter joke" in user_input_lower:
343
  conversation_context["last_topic"] = "joke"
344
+ conversation_context["last_response"] = None
345
  return krishna_blessings["butter_joke"]
346
  if "cow joke" in user_input_lower:
347
  conversation_context["last_topic"] = "joke"
348
+ conversation_context["last_response"] = None
349
  return krishna_blessings["cow_joke"]
350
  if "flute joke" in user_input_lower:
351
  conversation_context["last_topic"] = "joke"
352
+ conversation_context["last_response"] = None
353
  return krishna_blessings["flute_joke"]
354
  if "dance joke" in user_input_lower:
355
  conversation_context["last_topic"] = "joke"
356
+ conversation_context["last_response"] = None
357
  return krishna_blessings["dance_joke"]
358
  if "mischief joke" in user_input_lower:
359
  conversation_context["last_topic"] = "joke"
360
+ conversation_context["last_response"] = None
361
  return krishna_blessings["mischief_joke"]
362
 
363
  if "riddle" in user_input_lower or "puzzle" in user_input_lower:
364
  conversation_context["last_topic"] = "riddle"
365
+ conversation_context["last_response"] = None
366
  return krishna_blessings["riddle"]
367
  if "mystery" in user_input_lower or "enigma" in user_input_lower:
368
  conversation_context["last_topic"] = "riddle"
369
+ conversation_context["last_response"] = None
370
  return krishna_blessings["mystery"]
371
  if "question" in user_input_lower:
372
  conversation_context["last_topic"] = "riddle"
373
+ conversation_context["last_response"] = None
374
  return krishna_blessings["question"]
375
 
376
  if "birthday" in user_input_lower:
377
  conversation_context["last_topic"] = "birthday"
378
+ conversation_context["last_response"] = None
379
  return ayush_surprises["birthday"]
380
  if "happy birthday" in user_input_lower:
381
  conversation_context["last_topic"] = "birthday"
382
+ conversation_context["last_response"] = None
383
  return krishna_blessings["happy_birthday"]
384
  if "birthday wish" in user_input_lower:
385
  conversation_context["last_topic"] = "birthday"
386
+ conversation_context["last_response"] = None
387
  return krishna_blessings["birthday_wish"]
388
  if "birthday blessing" in user_input_lower:
389
  conversation_context["last_topic"] = "birthday"
390
+ conversation_context["last_response"] = None
391
  return krishna_blessings["birthday_blessing"]
392
  if "birthday dance" in user_input_lower:
393
  conversation_context["last_topic"] = "birthday"
394
+ conversation_context["last_response"] = None
395
  return krishna_blessings["birthday_dance"]
396
  if "birthday song" in user_input_lower:
397
  conversation_context["last_topic"] = "birthday"
398
+ conversation_context["last_response"] = None
399
  return krishna_blessings["birthday_song"]
400
  if "birthday gift" in user_input_lower:
401
  conversation_context["last_topic"] = "birthday"
402
+ conversation_context["last_response"] = None
403
  return krishna_blessings["birthday_gift"]
404
  if "birthday smile" in user_input_lower:
405
  conversation_context["last_topic"] = "birthday"
406
+ conversation_context["last_response"] = None
407
  return krishna_blessings["birthday_smile"]
408
  if "birthday love" in user_input_lower:
409
  conversation_context["last_topic"] = "birthday"
410
+ conversation_context["last_response"] = None
411
  return krishna_blessings["birthday_love"]
412
  if "birthday magic" in user_input_lower:
413
  conversation_context["last_topic"] = "birthday"
414
+ conversation_context["last_response"] = None
415
  return krishna_blessings["birthday_magic"]
416
 
417
  if "wisdom" in user_input_lower or "advice" in user_input_lower:
418
  conversation_context["last_topic"] = "wisdom"
419
+ conversation_context["last_response"] = None
420
  return krishna_blessings["wisdom"]
421
  if "lesson" in user_input_lower or "truth" in user_input_lower:
422
  conversation_context["last_topic"] = "wisdom"
423
+ conversation_context["last_response"] = None
424
  return krishna_blessings["lesson"]
425
  if "kindness" in user_input_lower:
426
  conversation_context["last_topic"] = "wisdom"
427
+ conversation_context["last_response"] = None
428
  return krishna_blessings["kindness"]
429
  if "patience" in user_input_lower:
430
  conversation_context["last_topic"] = "wisdom"
431
+ conversation_context["last_response"] = None
432
  return krishna_blessings["patience"]
433
  if "courage" in user_input_lower:
434
  conversation_context["last_topic"] = "wisdom"
435
+ conversation_context["last_response"] = None
436
  return krishna_blessings["courage"]
437
  if "joy" in user_input_lower:
438
  conversation_context["last_topic"] = "wisdom"
439
+ conversation_context["last_response"] = None
440
  return krishna_blessings["joy"]
441
  if "friendship" in user_input_lower:
442
  conversation_context["last_topic"] = "wisdom"
443
+ conversation_context["last_response"] = None
444
  return krishna_blessings["friendship"]
445
  if "love" in user_input_lower:
446
  conversation_context["last_topic"] = "wisdom"
447
+ conversation_context["last_response"] = None
448
  return krishna_blessings["love"]
449
 
450
  if "nature" in user_input_lower or "vrindavan" in user_input_lower:
451
  conversation_context["last_topic"] = "nature"
452
+ conversation_context["last_response"] = None
453
  return krishna_blessings["nature"]
454
  if "yamuna" in user_input_lower or "river" in user_input_lower:
455
  conversation_context["last_topic"] = "nature"
456
+ conversation_context["last_response"] = None
457
  return krishna_blessings["yamuna"]
458
  if "peacock" in user_input_lower:
459
  conversation_context["last_topic"] = "nature"
460
+ conversation_context["last_response"] = None
461
  return krishna_blessings["peacock"]
462
  if "cow" in user_input_lower:
463
  conversation_context["last_topic"] = "nature"
464
+ conversation_context["last_response"] = None
465
  return krishna_blessings["cow"]
466
  if "flower" in user_input_lower:
467
  conversation_context["last_topic"] = "nature"
468
+ conversation_context["last_response"] = None
469
  return krishna_blessings["flower"]
470
  if "tree" in user_input_lower:
471
  conversation_context["last_topic"] = "nature"
472
+ conversation_context["last_response"] = None
473
  return krishna_blessings["tree"]
474
  if "forest" in user_input_lower:
475
  conversation_context["last_topic"] = "nature"
476
+ conversation_context["last_response"] = None
477
  return krishna_blessings["forest"]
478
  if "bird" in user_input_lower:
479
  conversation_context["last_topic"] = "nature"
480
+ conversation_context["last_response"] = None
481
  return krishna_blessings["bird"]
482
  if "sunset" in user_input_lower:
483
  conversation_context["last_topic"] = "nature"
484
+ conversation_context["last_response"] = None
485
  return krishna_blessings["sunset"]
486
 
487
  if "encourage" in user_input_lower or "cheer" in user_input_lower:
488
  conversation_context["last_topic"] = "encourage"
489
+ conversation_context["last_response"] = None
490
  return krishna_blessings["encourage"]
491
  if "support" in user_input_lower or "uplift" in user_input_lower:
492
  conversation_context["last_topic"] = "encourage"
493
+ conversation_context["last_response"] = None
494
  return krishna_blessings["support"]
495
  if "inspire" in user_input_lower or "motivate" in user_input_lower:
496
  conversation_context["last_topic"] = "encourage"
497
+ conversation_context["last_response"] = None
498
  return krishna_blessings["inspire"]
499
  if "strength" in user_input_lower:
500
  conversation_context["last_topic"] = "encourage"
501
+ conversation_context["last_response"] = None
502
  return krishna_blessings["strength"]
503
  if "hope" in user_input_lower:
504
  conversation_context["last_topic"] = "encourage"
505
+ conversation_context["last_response"] = None
506
  return krishna_blessings["hope"]
507
  if "believe" in user_input_lower:
508
  conversation_context["last_topic"] = "encourage"
509
+ conversation_context["last_response"] = None
510
  return krishna_blessings["believe"]
511
  if "shine" in user_input_lower:
512
  conversation_context["last_topic"] = "encourage"
513
+ conversation_context["last_response"] = None
514
  return krishna_blessings["shine"]
515
 
516
  if "friend" in user_input_lower:
517
  conversation_context["last_topic"] = "friend"
518
+ conversation_context["last_response"] = None
519
  return krishna_blessings["friend"]
520
  if "smile" in user_input_lower:
521
  conversation_context["last_topic"] = "smile"
522
+ conversation_context["last_response"] = None
523
  return krishna_blessings["smile"]
524
  if "magic" in user_input_lower:
525
  conversation_context["last_topic"] = "magic"
526
+ conversation_context["last_response"] = None
527
  return krishna_blessings["magic"]
528
  if "adventure" in user_input_lower:
529
  conversation_context["last_topic"] = "adventure"
530
+ conversation_context["last_response"] = None
531
  return krishna_blessings["adventure"]
532
  if "song" in user_input_lower:
533
  conversation_context["last_topic"] = "song"
534
+ conversation_context["last_response"] = None
535
  return krishna_blessings["song"]
536
  if "dream" in user_input_lower:
537
  conversation_context["last_topic"] = "dream"
538
+ conversation_context["last_response"] = None
539
  return krishna_blessings["dream"]
540
  if "story" in user_input_lower:
541
  conversation_context["last_topic"] = "story"
542
+ conversation_context["last_response"] = None
543
  return krishna_blessings["story"]
544
  if "surprise" in user_input_lower:
545
  conversation_context["last_topic"] = "surprise"
546
+ conversation_context["last_response"] = None
547
  return krishna_blessings["surprise"]
548
  if "celebrate" in user_input_lower:
549
  conversation_context["last_topic"] = "celebrate"
550
+ conversation_context["last_response"] = None
551
  return krishna_blessings["celebrate"]
552
  if "blessing" in user_input_lower:
553
  conversation_context["last_topic"] = "blessing"
554
+ conversation_context["last_response"] = None
555
  return krishna_blessings["blessing"]
556
 
557
  if conversation_context["last_topic"]:
558
  last_topic = conversation_context["last_topic"]
559
  if last_topic in krishna_blessings:
560
+ conversation_context["last_response"] = None
561
  return krishna_blessings[last_topic] + " What else would you like to talk about, Manavi?"
562
 
563
+ # Sentiment-based responses (only as a fallback, and avoid repetition)
564
+ if sentiment == "negative" and "sad" not in user_input_lower and conversation_context["last_response"] != "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!":
565
+ response = "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!"
566
+ conversation_context["last_response"] = response
567
+ return response
568
+ if sentiment == "positive" and conversation_context["last_response"] != "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?":
569
+ response = "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?"
570
+ conversation_context["last_response"] = response
571
+ return response
572
+
573
+ # Fallback to multiple open-source AI models if no keywords match
574
  # Shuffle the models to try them in random order
575
  models_to_try = AI_MODELS.copy()
576
  random.shuffle(models_to_try)
 
598
  response += "Oh, my dear gopi, don’t be sad—let’s dance by the Yamuna, and I’ll play a tune to cheer you up!"
599
  else:
600
  response += f"I’m twirling my flute just for you! Shall we share a Vrindavan adventure today?"
601
+ conversation_context["last_response"] = None
602
  return response
603
 
604
  # For other models, use the Hugging Face Inference API
 
615
  result = response.json()
616
  # Handle different response formats based on the model
617
  if isinstance(result, list) and len(result) > 0 and "generated_text" in result[0]:
618
+ response_text = result[0]["generated_text"].strip()
619
  elif isinstance(result, dict) and "generated_text" in result:
620
+ response_text = result["generated_text"].strip()
621
  elif isinstance(result, str):
622
+ response_text = result.strip()
623
  else:
624
  print(f"Unexpected response format from {model['name']}: {result}")
625
  continue
626
+ conversation_context["last_response"] = None
627
+ return response_text
628
  else:
629
  print(f"Error with {model['name']}: {response.text}")
630
  continue
 
633
  continue
634
 
635
  # If all models fail, return a default message
636
+ conversation_context["last_response"] = None
637
  return "Hare Manavi! I seem to be lost in Vrindavan’s magic—let’s try a different tune!"