cointegrated commited on
Commit
5c565ab
1 Parent(s): d0a2f64

raise errors when the source or target language is not chosen

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -38,7 +38,11 @@ def load_tokenizer(src_lang, tgt_lang):
38
  # cache function
39
  @lru_cache(maxsize=100)
40
  def translate(text: str, src_lang: str, tgt_lang: str):
41
- return _translate(text, src_lang,tgt_lang )
 
 
 
 
42
 
43
  # Only assign GPU if cache not used
44
  @spaces.GPU
 
38
  # cache function
39
  @lru_cache(maxsize=100)
40
  def translate(text: str, src_lang: str, tgt_lang: str):
41
+ if not src_lang:
42
+ raise gr.Error("The source language is empty! Please choose it in the dropdown list.")
43
+ if not tgt_lang:
44
+ raise gr.Error("The target language is empty! Please choose it in the dropdown list.")
45
+ return _translate(text, src_lang, tgt_lang)
46
 
47
  # Only assign GPU if cache not used
48
  @spaces.GPU