edaiofficial commited on
Commit
8804405
·
1 Parent(s): 2153e72

additional commits

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -50,6 +50,9 @@ def load_model(source_language_,target_language_):
50
  params = load_params_for_prediction(parsed_yaml_file,best_ckpt)
51
  return params
52
 
 
 
 
53
  def get_translation(source_language,target_language,source_sentence=None,source_file=None):
54
  '''
55
  This takes a sentence and gets the translation.
@@ -61,7 +64,8 @@ def get_translation(source_language,target_language,source_sentence=None,source_
61
  type_=1
62
  source = source_file.name
63
  try:
64
- params = load_model(source_language,target_language)
 
65
  pred = translate(params,source,type_)
66
  except Exception:
67
  return 'There was an issue loading the translation model for this language pair.'
@@ -91,19 +95,4 @@ iface = gr.Interface(fn=get_translation,
91
  theme='huggingface')
92
  iface.launch()
93
 
94
- iface2 = gr.Interface(fn=get_translation,
95
- inputs=[gr.inputs.Dropdown(choices = available_languages,default='English'),
96
- gr.inputs.Dropdown(choices = available_languages,default='Swahili'),
97
- gr.inputs.Textbox(label="Input"),
98
- gr.inputs.File(file_count="single", type="file", label='File with sentences', optional=True)],
99
- outputs=gr.outputs.Textbox(type="auto", label='Translation'),
100
- title=title,
101
- description=description,
102
- examples=[
103
- ['English','Swahili'],
104
- ['English','Afrikaans'],['English','Arabic'],['Efik','English'],['English','Hausa'],
105
- ['English','Igbo'],['English','Fon'],['English','Twi'],['Shona','English'],['Swahili','English'],
106
- ['Yoruba','English']],
107
- enable_queue=True,
108
- theme='huggingface')
109
- iface2.launch()
 
50
  params = load_params_for_prediction(parsed_yaml_file,best_ckpt)
51
  return params
52
 
53
+ #Using global params for English and Swahili to save time taken to load them
54
+ params = load_model('English','Swahili'):
55
+
56
  def get_translation(source_language,target_language,source_sentence=None,source_file=None):
57
  '''
58
  This takes a sentence and gets the translation.
 
64
  type_=1
65
  source = source_file.name
66
  try:
67
+ #params = load_model(source_language,target_language) #Using global params for English and Swahili to save time taken to load them
68
+
69
  pred = translate(params,source,type_)
70
  except Exception:
71
  return 'There was an issue loading the translation model for this language pair.'
 
95
  theme='huggingface')
96
  iface.launch()
97
 
98
+