Horchatas commited on
Commit
df5d6d2
·
verified ·
1 Parent(s): 0b1121c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -9,13 +9,21 @@ tokenizer = MarianTokenizer.from_pretrained(model_name)
9
  model = MarianMTModel.from_pretrained(model_name)
10
 
11
  def traducir(texto):
12
- text_summarized = summarizer(texto, max_length=1000000, min_length=30, do_sample=False)
 
 
13
  texto_solo = ">>esp<< " + text_summarized[0]["summary_text"]
14
- translated_entero = model.generate(**tokenizer(texto, return_tensors="pt", padding=True))
15
- texto_entero = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_entero]
 
 
 
 
 
 
16
  translated_resumido = model.generate(**tokenizer(texto_solo, return_tensors="pt", padding=True))
17
  texto_resumido = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_resumido]
18
- return texto_resumido[0], texto_entero[0],
19
 
20
  demo = gr.Interface(
21
  fn=traducir,
 
9
  model = MarianMTModel.from_pretrained(model_name)
10
 
11
  def traducir(texto):
12
+ texto_unido = ""
13
+ texto_completo = ""
14
+ text_summarized = summarizer(texto, max_length=1000, min_length=30, do_sample=False)
15
  texto_solo = ">>esp<< " + text_summarized[0]["summary_text"]
16
+ texto_separado = texto.split(" ")
17
+ for i in range(len(texto_separado)):
18
+ texto_unido = texto_unido + "".join(texto_separado[i]) + " "
19
+ if i//(len(texto_separado)-1) == 1 or i%100 == 0:
20
+ texto_unido_traducido = model.generate(**tokenizer(texto_unido, return_tensors="pt", padding=True))
21
+ texto_unido = [tokenizer.decode(t, skip_special_tokens=True) for t in texto_unido_traducido]
22
+ texto_completo = texto_completo + "".join(texto_unido[0]) + " "
23
+ texto_unido = ""
24
  translated_resumido = model.generate(**tokenizer(texto_solo, return_tensors="pt", padding=True))
25
  texto_resumido = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_resumido]
26
+ return texto_resumido[0], texto_completo
27
 
28
  demo = gr.Interface(
29
  fn=traducir,