DreamStream-1 commited on
Commit
cde2aee
·
verified ·
1 Parent(s): d8fa7b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -431,6 +431,33 @@ def process_voice_input(text: str) -> str:
431
  # Remove extra whitespace
432
  processed_text = re.sub(r'\s+', ' ', processed_text)
433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  # Fix special characters and encoding issues
435
  processed_text = clean_special_characters(processed_text)
436
 
@@ -1749,6 +1776,23 @@ async def process_incoming_message(from_number: str, msg: dict):
1749
 
1750
  logger.info(f"[Process] Processing {message_type} message from {from_number}: {message_body}")
1751
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1752
  # Get user context
1753
  user_context = context_manager.get_context(from_number)
1754
  current_state = user_context.get('current_state', 'main_menu')
@@ -4716,4 +4760,4 @@ if __name__ == "__main__":
4716
 
4717
  # Launch FastAPI app
4718
  import uvicorn
4719
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
431
  # Remove extra whitespace
432
  processed_text = re.sub(r'\s+', ' ', processed_text)
433
 
434
+ # Remove all leading/trailing quotes and dots
435
+ processed_text = re.sub(r'^["\']*[. ]*', '', processed_text)
436
+ processed_text = re.sub(r'["\']*[. ]*$', '', processed_text)
437
+
438
+ # Remove repeated phrases (if two sentences are very similar, keep only one)
439
+ # Split by sentence-ending punctuation
440
+ from rapidfuzz import fuzz
441
+ sentences = re.split(r'[.!?]+', processed_text)
442
+ unique_sentences = []
443
+ for s in sentences:
444
+ s = s.strip()
445
+ if not s:
446
+ continue
447
+ # Only add if not very similar to any already added
448
+ if not any(fuzz.ratio(s, us) > 85 for us in unique_sentences):
449
+ unique_sentences.append(s)
450
+ processed_text = '. '.join(unique_sentences)
451
+
452
+ # Remove any remaining duplicate words/phrases
453
+ words = processed_text.split()
454
+ if len(words) > 5:
455
+ mid = len(words) // 2
456
+ first_half = ' '.join(words[:mid])
457
+ second_half = ' '.join(words[mid:])
458
+ if fuzz.ratio(first_half, second_half) > 85:
459
+ processed_text = first_half
460
+
461
  # Fix special characters and encoding issues
462
  processed_text = clean_special_characters(processed_text)
463
 
 
1776
 
1777
  logger.info(f"[Process] Processing {message_type} message from {from_number}: {message_body}")
1778
 
1779
+ # --- NEW: Recognize 'all products' queries ---
1780
+ all_products_phrases = [
1781
+ 'all products', 'show all products', 'i want all the product information',
1782
+ 'i need all the product information', 'i want information about all products',
1783
+ 'i need information about all products',
1784
+ 'مجھے تمام پروڈکٹ کے بارے میں معلومات چاہیے',
1785
+ 'مجھے تمام پروڈکٹس کے بارے میں معلومات چاہئے',
1786
+ 'تمام پروڈکٹس', 'تمام پروڈکٹ', 'سارے پروڈکٹس', 'سارے پروڈکٹ'
1787
+ ]
1788
+ def normalize(text):
1789
+ return re.sub(r'[^\w\s\u0600-\u06FF]', '', text).lower().strip()
1790
+ normalized_msg = normalize(message_body)
1791
+ if any(phrase in normalized_msg for phrase in all_products_phrases):
1792
+ logger.info(f"[Process] Detected 'all products' query: '{message_body}'")
1793
+ await display_all_products(from_number)
1794
+ return
1795
+
1796
  # Get user context
1797
  user_context = context_manager.get_context(from_number)
1798
  current_state = user_context.get('current_state', 'main_menu')
 
4760
 
4761
  # Launch FastAPI app
4762
  import uvicorn
4763
+ uvicorn.run(app, host="0.0.0.0", port=7860)