VeyVey commited on
Commit
63e4dbf
1 Parent(s): 0e096ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -4,9 +4,13 @@ from transformers import pipeline
4
  pipe = pipeline("translation", model="t5-base", tokenizer_kwargs={"model_max_length": 1024})
5
 
6
  def translate(text, target_language):
 
 
7
  return pipe(text, target_language=target_language)[0]["translation_text"]
8
 
9
  def translate_callback(english, language_select):
 
 
10
  target_language = "de" if language_select == "German" else "fr" if language_select == "French" else "lo"
11
  translated_text = translate(english, target_language)
12
  return translated_text
@@ -40,12 +44,10 @@ def main():
40
  inputs=[english_textbox, language_select],
41
  outputs=translated_textbox,
42
  title="Text Translation",
43
- description="Translate English text to German, French, or Lao.",
44
- examples=[[None, "German"]],
45
- examples_per_page=5
46
  )
47
 
48
  iface.launch()
49
 
50
  if __name__ == "__main__":
51
- main()
 
4
  pipe = pipeline("translation", model="t5-base", tokenizer_kwargs={"model_max_length": 1024})
5
 
6
  def translate(text, target_language):
7
+ if text is None or text == "":
8
+ return ""
9
  return pipe(text, target_language=target_language)[0]["translation_text"]
10
 
11
  def translate_callback(english, language_select):
12
+ if english is None or english == "":
13
+ return ""
14
  target_language = "de" if language_select == "German" else "fr" if language_select == "French" else "lo"
15
  translated_text = translate(english, target_language)
16
  return translated_text
 
44
  inputs=[english_textbox, language_select],
45
  outputs=translated_textbox,
46
  title="Text Translation",
47
+ description="Translate English text to German, French, or Lao."
 
 
48
  )
49
 
50
  iface.launch()
51
 
52
  if __name__ == "__main__":
53
+ main()