Spaces:
Sleeping
Sleeping
Download utils.py from as-cle-bert/chat-with-em: direct link, hf CLI and curl.
- Browser
- Download file 518 Bytes
-
https://huggingface.co/spaces/as-cle-bert/chat-with-em/resolve/main/utils.py
- Command line
-
hf download hf://spaces/as-cle-bert/chat-with-em/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/as-cle-bert/chat-with-em/resolve/main/utils.py
518 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 |