Spaces:
Build error
Build error
Commit
·
447b9ea
1
Parent(s):
37fe427
pre-loading models
Browse files
app.py
CHANGED
|
@@ -51,10 +51,17 @@ def load_model(source_language,target_language):
|
|
| 51 |
return params
|
| 52 |
|
| 53 |
#Load models of all available language pairs
|
|
|
|
| 54 |
model_mapping = {}
|
| 55 |
for availabe_lang in available_language_pairs:
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def get_translation(source_language,target_language,source_sentence=None,source_file=None):
|
|
@@ -96,11 +103,7 @@ iface = gr.Interface(fn=get_translation,
|
|
| 96 |
outputs=gr.outputs.Textbox(type="auto", label='Translation'),
|
| 97 |
title=title,
|
| 98 |
description=description,
|
| 99 |
-
examples=
|
| 100 |
-
['English','Swahili'],
|
| 101 |
-
['English','Afrikaans'],['English','Arabic'],['Efik','English'],['English','Hausa'],
|
| 102 |
-
['English','Igbo'],['English','Fon'],['English','Twi'],['Shona','English'],['Swahili','English'],
|
| 103 |
-
['Yoruba','English']],
|
| 104 |
enable_queue=True,
|
| 105 |
theme='huggingface')
|
| 106 |
iface.launch()
|
|
|
|
| 51 |
return params
|
| 52 |
|
| 53 |
#Load models of all available language pairs
|
| 54 |
+
examples_available_models=[]
|
| 55 |
model_mapping = {}
|
| 56 |
for availabe_lang in available_language_pairs:
|
| 57 |
+
try:
|
| 58 |
+
model_mapping.update({availabe_lang:load_model(availabe_lang.split('-')[0],availabe_lang.split('-')[1])})
|
| 59 |
+
examples_available_models.append([f"{list(language_map.keys())[list(language_map.values()).index(availabe_lang.split('-')[0])]}",f"{list(language_map.keys())[list(language_map.values()).index(availabe_lang.split('-')[1])]}"]) #idea to extract key from value got from https://stackoverflow.com/questions/8023306/get-key-by-value-in-dictionary
|
| 60 |
+
except Exception:
|
| 61 |
+
continue
|
| 62 |
|
| 63 |
+
if examples_available_models==[]:
|
| 64 |
+
raise Exception(f'Available models for Space cannot be empty!')
|
| 65 |
|
| 66 |
|
| 67 |
def get_translation(source_language,target_language,source_sentence=None,source_file=None):
|
|
|
|
| 103 |
outputs=gr.outputs.Textbox(type="auto", label='Translation'),
|
| 104 |
title=title,
|
| 105 |
description=description,
|
| 106 |
+
examples=examples_available_models,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
enable_queue=True,
|
| 108 |
theme='huggingface')
|
| 109 |
iface.launch()
|