doof-ferb commited on
Commit
b1e81db
·
verified ·
1 Parent(s): 927a30e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -4
app.py CHANGED
@@ -36,21 +36,19 @@ def dịch(text: str, file_obj: str, batch_size: int, progress=gr.Progress()) ->
36
  if file_obj is not None:
37
  with open(file_obj, "r", encoding="utf-8", errors="ignore") as f:
38
  text = f.read()
39
- if text.strip() == "":
40
- return ""
41
 
42
  inputs = []
43
  for line in text.split("\n"):
44
  if (l := line.strip()) != "":
45
  inputs.append(TOKENIZER.convert_ids_to_tokens(TOKENIZER.encode(l, truncation=True)))
46
 
47
- if not inputs:
48
  return ""
49
 
50
  results = []
51
  for i in progress.tqdm(range(0, len(inputs), batch_size)):
52
  outputs = TRANSLATOR.translate_batch(
53
- inputs,
54
  max_decoding_length=TOKENIZER.model_max_length,
55
  max_batch_size=batch_size,
56
  beam_size=4,
 
36
  if file_obj is not None:
37
  with open(file_obj, "r", encoding="utf-8", errors="ignore") as f:
38
  text = f.read()
 
 
39
 
40
  inputs = []
41
  for line in text.split("\n"):
42
  if (l := line.strip()) != "":
43
  inputs.append(TOKENIZER.convert_ids_to_tokens(TOKENIZER.encode(l, truncation=True)))
44
 
45
+ if len(inputs) == 0:
46
  return ""
47
 
48
  results = []
49
  for i in progress.tqdm(range(0, len(inputs), batch_size)):
50
  outputs = TRANSLATOR.translate_batch(
51
+ inputs[i : i + batch_size],
52
  max_decoding_length=TOKENIZER.model_max_length,
53
  max_batch_size=batch_size,
54
  beam_size=4,