carlosep93 commited on
Commit
51a8540
·
1 Parent(s): ff287e4

fix newlines

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -23,14 +23,19 @@ example_sentence = ["Ahir se'n va anar, va agafar les seves coses i es va posar
23
 
24
  @spaces.GPU
25
  def translate(input_text, source, target):
26
- prompt = f'[{source}] {input_text} \n[{target}]'
 
 
 
27
 
28
- input_ids = tokenizer(prompt, return_tensors='pt').input_ids.to(device)
29
- output_ids = model.generate(input_ids, max_length=500, num_beams=5)
30
- input_length = input_ids.shape[1]
 
 
 
 
31
 
32
- generated_text = tokenizer.decode(output_ids[0, input_length:], skip_special_tokens=True).strip()
33
- return generated_text, ""
34
 
35
  with gr.Blocks() as demo:
36
  gr.HTML("""<html>
 
23
 
24
  @spaces.GPU
25
  def translate(input_text, source, target):
26
+ sentences = input_text.split('\n')
27
+ generated_text = []
28
+ for sentence in sentences:
29
+ prompt = f'[{source}] {sentence} \n[{target}]'
30
 
31
+ input_ids = tokenizer(prompt, return_tensors='pt').input_ids.to(device)
32
+ output_ids = model.generate(input_ids, max_length=500, num_beams=5)
33
+ input_length = input_ids.shape[1]
34
+
35
+ generated_text.append(tokenizer.decode(output_ids[0, input_length:], skip_special_tokens=True).strip())
36
+
37
+ return '\n'.join(generated_text), ""
38
 
 
 
39
 
40
  with gr.Blocks() as demo:
41
  gr.HTML("""<html>