kargaranamir commited on
Commit
c53190e
1 Parent(s): 2a21b24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -153,8 +153,25 @@ def load_GlotLID_v2(model_name, file_name):
153
  return model
154
 
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  model_1 = load_GlotLID_v1(constants.MODEL_NAME, "model_v1.bin")
157
  model_2 = load_GlotLID_v2(constants.MODEL_NAME, "model_v2.bin")
 
 
 
158
 
159
  # @st.cache_resource
160
  def plot(label, prob):
@@ -189,7 +206,16 @@ def compute(sentences, version = 'v2'):
189
  A list of language probablities and labels for the given sentences.
190
  """
191
  progress_text = "Computing Language..."
192
- model_choice = model_2 if version == 'v2' else model_1
 
 
 
 
 
 
 
 
 
193
  my_bar = st.progress(0, text=progress_text)
194
 
195
  probs = []
@@ -206,7 +232,7 @@ def compute(sentences, version = 'v2'):
206
  output_label_language = output_label.split('_')[0]
207
 
208
  # script control
209
- if version in ['v2'] and output_label_language!= 'zxx':
210
  main_script, all_scripts = get_script(sent)
211
  output_label_script = output_label.split('_')[1]
212
 
@@ -247,8 +273,8 @@ with tab1:
247
 
248
  version = st.radio(
249
  "Choose model",
250
- ["v1", "v2"],
251
- captions=["GlotLID version 1", "GlotLID version 2 (more data and languages)"],
252
  index = 1,
253
  key = 'version_tab1',
254
  horizontal = True
 
153
  return model
154
 
155
 
156
+ @st.cache_resource
157
+ def load_OpenLID():
158
+ model_path = hf_hub_download(repo_id='laurievb/OpenLID', filename='model.bin')
159
+ model = fasttext.load_model(model_path)
160
+ return model
161
+
162
+
163
+ @st.cache_resource
164
+ def load_NLLB():
165
+ model_path = hf_hub_download(repo_id='facebook/fasttext-language-identification', filename='model.bin')
166
+ model = fasttext.load_model(model_path)
167
+ return model
168
+
169
+
170
  model_1 = load_GlotLID_v1(constants.MODEL_NAME, "model_v1.bin")
171
  model_2 = load_GlotLID_v2(constants.MODEL_NAME, "model_v2.bin")
172
+ model_3 = load_OpenLID()
173
+ model_4 = load_NLLB()
174
+
175
 
176
  # @st.cache_resource
177
  def plot(label, prob):
 
206
  A list of language probablities and labels for the given sentences.
207
  """
208
  progress_text = "Computing Language..."
209
+
210
+ if version == 'nllb-218':
211
+ model_choice = model_4
212
+ elif version == 'openlid-201':
213
+ model_choice = model_3
214
+ elif version == 'v2':
215
+ model_choice = model_2
216
+ else:
217
+ model_choice = model_1
218
+
219
  my_bar = st.progress(0, text=progress_text)
220
 
221
  probs = []
 
232
  output_label_language = output_label.split('_')[0]
233
 
234
  # script control
235
+ if version in ['v2', 'openlid-201', 'nllb-218'] and output_label_language!= 'zxx':
236
  main_script, all_scripts = get_script(sent)
237
  output_label_script = output_label.split('_')[1]
238
 
 
273
 
274
  version = st.radio(
275
  "Choose model",
276
+ ["nllb-218", "openlid-201", "v1", "v2"],
277
+ captions=["NLLB", "OpenLID", "GlotLID version 1", "GlotLID version 2 (more data and languages)"],
278
  index = 1,
279
  key = 'version_tab1',
280
  horizontal = True