vteam27 commited on
Commit
3134ca6
·
1 Parent(s): 8eb6a3c

added download

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -16,16 +16,16 @@ processor = AutoProcessor.from_pretrained("facebook/hf-seamless-m4t-medium")
16
  # print(translated_text_from_text)
17
 
18
 
19
- def run_t2tt(file_uploader , input_text: str, source_language: str, target_language: str) -> str:
20
  if file_uploader is not None:
21
- input_text = file_uploader.read().decode("utf-8")
22
  source_language_code = LANGUAGE_NAME_TO_CODE[source_language]
23
  target_language_code = LANGUAGE_NAME_TO_CODE[target_language]
24
  text_inputs = processor(text = input_text, src_lang=source_language_code , return_tensors="pt")
25
  output_tokens = model.generate(**text_inputs, tgt_lang=target_language_code)
26
  output = processor.decode(output_tokens[0].tolist(), skip_special_tokens=True)
27
- return str(output)
28
-
29
 
30
  with gr.Blocks() as demo_t2tt:
31
  with gr.Row():
@@ -47,6 +47,7 @@ with gr.Blocks() as demo_t2tt:
47
  btn = gr.Button("Translate")
48
  with gr.Column():
49
  output_text = gr.Textbox(label="Translated text")
 
50
 
51
  gr.Examples(
52
  examples=[
@@ -76,7 +77,7 @@ with gr.Blocks() as demo_t2tt:
76
  ],
77
  ],
78
  inputs=[file_uploader ,input_text, source_language, target_language],
79
- outputs=output_text,
80
  fn=run_t2tt,
81
  cache_examples=False,
82
  api_name=False,
@@ -86,7 +87,7 @@ with gr.Blocks() as demo_t2tt:
86
  triggers=[input_text.submit, btn.click],
87
  fn=run_t2tt,
88
  inputs=[file_uploader, input_text, source_language, target_language],
89
- outputs=output_text,
90
  api_name="t2tt",
91
  )
92
 
 
16
  # print(translated_text_from_text)
17
 
18
 
19
+ def run_t2tt(file_uploader , input_text: str, source_language: str, target_language: str) -> (str, bytes):
20
  if file_uploader is not None:
21
+ input_text = ffile_uploader['content'].decode("utf-8")
22
  source_language_code = LANGUAGE_NAME_TO_CODE[source_language]
23
  target_language_code = LANGUAGE_NAME_TO_CODE[target_language]
24
  text_inputs = processor(text = input_text, src_lang=source_language_code , return_tensors="pt")
25
  output_tokens = model.generate(**text_inputs, tgt_lang=target_language_code)
26
  output = processor.decode(output_tokens[0].tolist(), skip_special_tokens=True)
27
+ translated_text_bytes = translated_text.encode("utf-8")
28
+ return str(output), translated_text_bytes
29
 
30
  with gr.Blocks() as demo_t2tt:
31
  with gr.Row():
 
47
  btn = gr.Button("Translate")
48
  with gr.Column():
49
  output_text = gr.Textbox(label="Translated text")
50
+ output_file = gr.File(label="Translated text file")
51
 
52
  gr.Examples(
53
  examples=[
 
77
  ],
78
  ],
79
  inputs=[file_uploader ,input_text, source_language, target_language],
80
+ outputs=[output_text, output_file],
81
  fn=run_t2tt,
82
  cache_examples=False,
83
  api_name=False,
 
87
  triggers=[input_text.submit, btn.click],
88
  fn=run_t2tt,
89
  inputs=[file_uploader, input_text, source_language, target_language],
90
+ outputs=[output_text, output_file],
91
  api_name="t2tt",
92
  )
93