Spaces:
Runtime error
Runtime error
Download utils/lang_utils.py from MBilal-72/GenerativeEngineOptimization: direct link, hf CLI and curl.
- Browser
- Download file 464 Bytes
-
https://huggingface.co/spaces/MBilal-72/GenerativeEngineOptimization/resolve/refs%2Fpr%2F8/utils/lang_utils.py
- Command line
-
hf download hf://spaces/MBilal-72/GenerativeEngineOptimization@refs/pr/8/utils/lang_utils.py
-
curl -L -o lang_utils.py https://huggingface.co/spaces/MBilal-72/GenerativeEngineOptimization/resolve/refs%2Fpr%2F8/utils/lang_utils.py
464 Bytes
| from langdetect import detect | |
| from transformers import pipeline | |
| # Detect language of the input text | |
| def detect_language(text: str) -> str: | |
| try: | |
| return detect(text) | |
| except: | |
| return "unknown" | |
| # Translate text to English (or another target language) | |
| def translate_text(text: str, target_lang: str = "en") -> str: | |
| translator = pipeline("translation", model="Helsinki-NLP/opus-mt-mul-en") | |
| return translator(text)[0]["translation_text"] | |