Spaces:
Sleeping
Sleeping
| """Standalone language detection used by app.py routing logic.""" | |
| from langdetect import detect, DetectorFactory, LangDetectException | |
| DetectorFactory.seed = 42 | |
| SUPPORTED = {"en", "fr"} | |
| def detect_language(text: str, hint: str = "auto") -> str: | |
| if hint in SUPPORTED: | |
| return hint | |
| if not text or not text.strip(): | |
| return "en" | |
| try: | |
| lang = detect(text[:500]) | |
| return lang if lang in SUPPORTED else "en" | |
| except LangDetectException: | |
| return "en" | |