Spaces:
Runtime error
Runtime error
Download utils.py from as-cle-bert/bloom-multilingual-chat: direct link, hf CLI and curl.
- Browser
- Download file 532 Bytes
-
https://huggingface.co/spaces/as-cle-bert/bloom-multilingual-chat/resolve/main/utils.py
- Command line
-
hf download hf://spaces/as-cle-bert/bloom-multilingual-chat/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/as-cle-bert/bloom-multilingual-chat/resolve/main/utils.py
532 Bytes
| from langdetect import detect | |
| from deep_translator import GoogleTranslator | |
| class Translation: | |
| def __init__(self, text, destination): | |
| self.text = text | |
| self.destination = destination | |
| try: | |
| self.original = detect(self.text) | |
| except Exception as e: | |
| self.original = "auto" | |
| def translatef(self): | |
| translator = GoogleTranslator(source=self.original, target=self.destination) | |
| translation = translator.translate(self.text) | |
| return translation |