Spaces:
Running
Running
Update src/Translate.py
Browse files- src/Translate.py +3 -3
src/Translate.py
CHANGED
|
@@ -20,7 +20,7 @@ class Translators:
|
|
| 20 |
self.sl, self.tl = sl, tl
|
| 21 |
self.input_text = input_text
|
| 22 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
-
|
| 24 |
def HelsinkiNLP_mulroa(self):
|
| 25 |
try:
|
| 26 |
pipe = pipeline("translation", model=self.model_name, device=self.device)
|
|
@@ -32,10 +32,10 @@ class Translators:
|
|
| 32 |
return f"Error translating with model: {self.model_name}! Try other available language combination.", error
|
| 33 |
def text2textgenerationpipe(self):
|
| 34 |
translation = pipeline('text2text-generation', model = self.model_name)
|
| 35 |
-
return translation(text)[0]['generated_text'], message
|
| 36 |
def translationpipe(self):
|
| 37 |
translation = pipeline('translation', model = self.model_name)
|
| 38 |
-
return translation(text)[0]['translation_text'], message
|
| 39 |
|
| 40 |
def paraphraseTranslateMethod(requestValue: str, model: str):
|
| 41 |
nltk.download('punkt')
|
|
|
|
| 20 |
self.sl, self.tl = sl, tl
|
| 21 |
self.input_text = input_text
|
| 22 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
+
self.message = f'Translated from {iso1_to_name[self.sl]} to {iso1_to_name[self.tl]} with {self.model_name}.'
|
| 24 |
def HelsinkiNLP_mulroa(self):
|
| 25 |
try:
|
| 26 |
pipe = pipeline("translation", model=self.model_name, device=self.device)
|
|
|
|
| 32 |
return f"Error translating with model: {self.model_name}! Try other available language combination.", error
|
| 33 |
def text2textgenerationpipe(self):
|
| 34 |
translation = pipeline('text2text-generation', model = self.model_name)
|
| 35 |
+
return translation(text)[0]['generated_text'], self.message
|
| 36 |
def translationpipe(self):
|
| 37 |
translation = pipeline('translation', model = self.model_name)
|
| 38 |
+
return translation(text)[0]['translation_text'], self.message
|
| 39 |
|
| 40 |
def paraphraseTranslateMethod(requestValue: str, model: str):
|
| 41 |
nltk.download('punkt')
|