Nebulixlabs commited on
Commit
19b748f
·
verified ·
1 Parent(s): c7d7cd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -307,24 +307,29 @@ class HybridSearchIndex:
307
 
308
  if spell_model is not None and spell_tokenizer is not None:
309
  try:
310
- # "correct grammar: " is required by this specific lightweight model
311
- input_text = "correct grammar: " + query
 
312
  input_ids = spell_tokenizer(input_text, return_tensors="pt").input_ids
313
 
314
- # CPU-Optimized Fast Inference
315
  with torch.inference_mode():
316
- outputs = spell_model.generate(input_ids, max_length=20, num_beams=2, early_stopping=True)
317
 
318
  ai_corrected = spell_tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
319
 
320
- # Validation: Punctuation hata kar match karte hain (ki meaning change na ho)
 
 
 
321
  q_clean = normalize_text(query)
322
  ai_clean = normalize_text(ai_corrected)
323
 
324
- # Agar user ne galat type kiya hai tabhi change hoga, warna "ai for coding" same hi rahega
325
  if q_clean != ai_clean and len(ai_clean) > 0:
326
- corrected_query_str = ai_corrected
327
- search_query = ai_corrected
 
328
  except Exception as e:
329
  pass # Fail safe mechanism
330
 
@@ -512,11 +517,17 @@ async def pure_search(q: str = Query(...), content: bool = Query(False), debug:
512
  "request_id": req_id,
513
  "query": q,
514
  "corrected_query": corrected_query,
 
 
515
  "images": global_images,
516
  "results_count": len(top_5),
517
  "results": top_5
518
  }
519
 
 
 
 
 
520
  if len(QUERY_CACHE) > MAX_CACHE_SIZE: QUERY_CACHE.clear()
521
  QUERY_CACHE[cache_key] = final_response
522
 
 
307
 
308
  if spell_model is not None and spell_tokenizer is not None:
309
  try:
310
+ # 🔥 Fix: Query ko lowercase karke bhejenge taaki AI 'Laptp' ko Brand Name na samjhe!
311
+ q_lower = query.lower()
312
+ input_text = "correct grammar: " + q_lower
313
  input_ids = spell_tokenizer(input_text, return_tensors="pt").input_ids
314
 
315
+ # Use slightly better parameters (num_beams=3) for smarter typo fixing
316
  with torch.inference_mode():
317
+ outputs = spell_model.generate(input_ids, max_length=25, num_beams=3, early_stopping=True)
318
 
319
  ai_corrected = spell_tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
320
 
321
+ # Agar AI galti se wapas 'correct grammar:' print kar de, toh usko hata do
322
+ if ai_corrected.lower().startswith("correct grammar:"):
323
+ ai_corrected = ai_corrected.replace("correct grammar:", "", 1).strip()
324
+
325
  q_clean = normalize_text(query)
326
  ai_clean = normalize_text(ai_corrected)
327
 
328
+ # Agar dono words alag hain tabhi corrected_query update hogi
329
  if q_clean != ai_clean and len(ai_clean) > 0:
330
+ # Har word ka pehla letter wapas Capital banayenge (Best Laptop Under 10000)
331
+ corrected_query_str = ai_corrected.title()
332
+ search_query = corrected_query_str
333
  except Exception as e:
334
  pass # Fail safe mechanism
335
 
 
517
  "request_id": req_id,
518
  "query": q,
519
  "corrected_query": corrected_query,
520
+ "intent": intent_info.get("intent", "GENERAL"), # ✨ Yaha INTENT show hoga!
521
+ "intent_signals": intent_info.get("signals", []), # ✨ Yaha show honge triggers (Jaise 'COMPARISON', 'NEWS')
522
  "images": global_images,
523
  "results_count": len(top_5),
524
  "results": top_5
525
  }
526
 
527
+ # Debugging on ki hai toh debug_features array bhi dega
528
+ if debug:
529
+ final_response["debug_mode"] = True
530
+
531
  if len(QUERY_CACHE) > MAX_CACHE_SIZE: QUERY_CACHE.clear()
532
  QUERY_CACHE[cache_key] = final_response
533