Goog cr lf
Browse files
app.py
CHANGED
|
@@ -18,11 +18,11 @@ langs.extend(list(all_langs.keys())) # Language options as list, add favourite l
|
|
| 18 |
# all_langs = languagecodes.iso_languages_byname
|
| 19 |
|
| 20 |
def timer(func):
|
| 21 |
-
import time
|
| 22 |
def wrapper(*args, **kwargs):
|
| 23 |
-
start_time = time
|
| 24 |
translated_text, message_text = func(*args, **kwargs)
|
| 25 |
-
end_time = time
|
| 26 |
execution_time = end_time - start_time
|
| 27 |
# print(f"Function {func.__name__!r} executed in {execution_time:.4f} seconds.")
|
| 28 |
message_text = f'Executed in {execution_time:.2f} seconds! {message_text}'
|
|
@@ -57,10 +57,13 @@ class Translators:
|
|
| 57 |
self.input_text = input_text
|
| 58 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 59 |
|
| 60 |
-
def google(self):
|
|
|
|
|
|
|
|
|
|
| 61 |
url = os.environ['GCLIENT'] + f'sl={self.sl}&tl={self.tl}&q={self.input_text}'
|
| 62 |
response = httpx.get(url)
|
| 63 |
-
return response.json()[0][0][0]
|
| 64 |
|
| 65 |
def mitre(self):
|
| 66 |
from transformers import AutoModel, AutoTokenizer
|
|
|
|
| 18 |
# all_langs = languagecodes.iso_languages_byname
|
| 19 |
|
| 20 |
def timer(func):
|
| 21 |
+
from time import time
|
| 22 |
def wrapper(*args, **kwargs):
|
| 23 |
+
start_time = time()
|
| 24 |
translated_text, message_text = func(*args, **kwargs)
|
| 25 |
+
end_time = time()
|
| 26 |
execution_time = end_time - start_time
|
| 27 |
# print(f"Function {func.__name__!r} executed in {execution_time:.4f} seconds.")
|
| 28 |
message_text = f'Executed in {execution_time:.2f} seconds! {message_text}'
|
|
|
|
| 57 |
self.input_text = input_text
|
| 58 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 59 |
|
| 60 |
+
def google(self):
|
| 61 |
+
# for rep in ('\r\n', '\r', '\n', ' '):
|
| 62 |
+
# self.input_text = self.input_text.replace(rep, ' ')
|
| 63 |
+
self.input_text = " ".join(self.input_text.split())
|
| 64 |
url = os.environ['GCLIENT'] + f'sl={self.sl}&tl={self.tl}&q={self.input_text}'
|
| 65 |
response = httpx.get(url)
|
| 66 |
+
return response.json()[0][0][0].strip()
|
| 67 |
|
| 68 |
def mitre(self):
|
| 69 |
from transformers import AutoModel, AutoTokenizer
|