meinvirgos commited on
Commit
4b0094d
·
verified ·
1 Parent(s): cc67ce1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -7,6 +7,10 @@ from transformers import AutoTokenizer, pipeline
7
  # Modelo de Meta capaz de traducir a más de 200 idiomas
8
  model = 'facebook/nllb-200-distilled-600M'
9
  tokenizer = model
 
 
 
 
10
 
11
  flores_codes = {}
12
  flores_codes["Asturianu"] = "ast_Latn"
@@ -21,11 +25,16 @@ def translation(source, target, text):
21
  #start_time = time.time()
22
  source = flores_codes[source]
23
  target = flores_codes[target]
24
-
25
- translator = pipeline('translation', model=model, tokenizer=tokenizer,
26
-
27
- src_lang=source, tgt_lang=target)
28
- output = translator(text, max_length=400)
 
 
 
 
 
29
 
30
  #end_time = time.time()
31
 
 
7
  # Modelo de Meta capaz de traducir a más de 200 idiomas
8
  model = 'facebook/nllb-200-distilled-600M'
9
  tokenizer = model
10
+ # Pero como traduce mal al asturiano, añadimos este otro que traduce del español
11
+ # Es del proyecto AINA: https://huggingface.co/projecte-aina
12
+ model_ast = "projecte-aina/aina-translator-es-ast"
13
+ tokenizer_ast = model_ast
14
 
15
  flores_codes = {}
16
  flores_codes["Asturianu"] = "ast_Latn"
 
25
  #start_time = time.time()
26
  source = flores_codes[source]
27
  target = flores_codes[target]
28
+ if target == flores_codes["Asturianu"]:
29
+ texto_castellano = source
30
+ if source != flores_codes["Castellano"]:
31
+ translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=source, tgt_lang=flores_codes["Castellano"])
32
+ texto_castellano = translator(text, max_length=400)
33
+ translator_ast = pipeline('translation', model=model_ast, tokenizer=tokenizer_ast)
34
+ output = translator_ast(text, max_length=400)
35
+ else
36
+ translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=source, tgt_lang=target)
37
+ output = translator(text, max_length=400)
38
 
39
  #end_time = time.time()
40