| import re | |
| def detect_language(text: str) -> str: | |
| # Very basic language detection for the hackathon | |
| # Checks for Urdu script characters | |
| urdu_pattern = re.compile(r'[\u0600-\u06FF]') | |
| if urdu_pattern.search(text): | |
| return "Urdu" | |
| # Check for common Roman Urdu patterns (very simplified) | |
| roman_urdu_keywords = ["aap", "hai", "kya", "nhi", "ji", "ho", "raha", "kar"] | |
| words = text.lower().split() | |
| matches = [w for w in words if w in roman_urdu_keywords] | |
| if len(matches) > 1: | |
| return "Roman Urdu" | |
| return "English" | |
| def normalize_text(text: str) -> str: | |
| # Normalize encoding and whitespace | |
| return " ".join(text.split()).strip() | |