Moleys commited on
Commit
172828d
·
verified ·
1 Parent(s): 4e9b3ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -5,8 +5,9 @@ from transformers import pipeline
5
  pipe = pipeline("translation", model="chi-vi/hirashiba-mt-tiny-zh-vi")
6
 
7
  def translate_text(input_text):
8
- output_text = pipe(input_text, max_length=512)[0]['translation_text']
9
- return output_text
 
10
 
11
  if __name__ == '__main__':
12
  with gr.Blocks() as app:
 
5
  pipe = pipeline("translation", model="chi-vi/hirashiba-mt-tiny-zh-vi")
6
 
7
  def translate_text(input_text):
8
+ lines = input_text.split('\n') # Tách từng dòng
9
+ translated_lines = [pipe(line, max_length=512)[0]['translation_text'] if line.strip() else '' for line in lines]
10
+ return '\n'.join(translated_lines) # Gộp lại với xuống dòng
11
 
12
  if __name__ == '__main__':
13
  with gr.Blocks() as app: