chrisjay commited on
Commit
e26a582
·
1 Parent(s): b2c835b

update based on revised joeynmt

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import yaml
3
- from joeynmt.prediction import load_params_for_prediction,translate
4
  from huggingface_hub import hf_hub_download
5
 
6
  language_map = {'English':'en','Swahili':'sw','Fon':'fon','Igbo':'ig',
@@ -68,7 +68,6 @@ if examples_available_models==[]:
68
  def get_translation(source_language,target_language,source_sentence=None,source_file=None):
69
  '''
70
  This takes a sentence and gets the translation.
71
- type_=2 tells joeynmt translate that it should expect a sentence.
72
  '''
73
 
74
  source_language_ = language_map[source_language]
@@ -76,13 +75,13 @@ def get_translation(source_language,target_language,source_sentence=None,source_
76
 
77
 
78
  source = source_sentence
79
- type_=2
80
  if source_file!=None:
81
- type_=1
82
  source = source_file.name
83
  try:
84
  params = model_mapping[f'{source_language_}-{target_language_}']
85
- pred = translate(params,source,type_)
86
  except Exception:
87
  return f'There was an issue loading the translation model for {source_language} -> {target_language}. Try another pair please'
88
 
 
1
  import gradio as gr
2
  import yaml
3
+ from joeynmt.prediction import load_params_for_prediction,translate_for_hf_space
4
  from huggingface_hub import hf_hub_download
5
 
6
  language_map = {'English':'en','Swahili':'sw','Fon':'fon','Igbo':'ig',
 
68
  def get_translation(source_language,target_language,source_sentence=None,source_file=None):
69
  '''
70
  This takes a sentence and gets the translation.
 
71
  '''
72
 
73
  source_language_ = language_map[source_language]
 
75
 
76
 
77
  source = source_sentence
78
+ translation_type='sentence'
79
  if source_file!=None:
80
+ translation_type='file'
81
  source = source_file.name
82
  try:
83
  params = model_mapping[f'{source_language_}-{target_language_}']
84
+ pred = translate_for_hf_space(params,source,translation_type)
85
  except Exception:
86
  return f'There was an issue loading the translation model for {source_language} -> {target_language}. Try another pair please'
87