Spaces:
Running
Running
Commit
•
832fdde
1
Parent(s):
b21d736
add v3.
Browse files
app.py
CHANGED
@@ -141,20 +141,15 @@ def convert_df(df):
|
|
141 |
|
142 |
|
143 |
@st.cache_resource
|
144 |
-
def
|
145 |
-
model_path = hf_hub_download(repo_id=model_name, filename=file_name)
|
146 |
-
model = fasttext.load_model(model_path)
|
147 |
-
return model
|
148 |
-
|
149 |
-
@st.cache_resource
|
150 |
-
def load_GlotLID_v2(model_name, file_name):
|
151 |
model_path = hf_hub_download(repo_id=model_name, filename=file_name)
|
152 |
model = fasttext.load_model(model_path)
|
153 |
return model
|
154 |
|
155 |
|
156 |
-
model_1 =
|
157 |
-
model_2 =
|
|
|
158 |
|
159 |
# @st.cache_resource
|
160 |
def plot(label, prob):
|
@@ -179,7 +174,7 @@ def plot(label, prob):
|
|
179 |
ax.set_xlabel("Confidence", color=BLACK_COLOR)
|
180 |
st.pyplot(fig)
|
181 |
|
182 |
-
def compute(sentences, version = '
|
183 |
"""Computes the language probablities and labels for the given sentences.
|
184 |
|
185 |
Args:
|
@@ -189,7 +184,7 @@ 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 +201,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,9 +242,9 @@ with tab1:
|
|
247 |
|
248 |
version = st.radio(
|
249 |
"Choose model",
|
250 |
-
["v1", "v2"],
|
251 |
-
captions=["GlotLID version 1", "GlotLID version 2 (
|
252 |
-
index =
|
253 |
key = 'version_tab1',
|
254 |
horizontal = True
|
255 |
)
|
@@ -286,9 +281,9 @@ with tab2:
|
|
286 |
|
287 |
version = st.radio(
|
288 |
"Choose model",
|
289 |
-
["v1", "v2"],
|
290 |
-
captions=["GlotLID version 1", "GlotLID version 2 (
|
291 |
-
index =
|
292 |
key = 'version_tab2',
|
293 |
horizontal = True
|
294 |
)
|
|
|
141 |
|
142 |
|
143 |
@st.cache_resource
|
144 |
+
def load_GlotLID(model_name, file_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
model_path = hf_hub_download(repo_id=model_name, filename=file_name)
|
146 |
model = fasttext.load_model(model_path)
|
147 |
return model
|
148 |
|
149 |
|
150 |
+
model_1 = load_GlotLID(constants.MODEL_NAME, "model_v1.bin")
|
151 |
+
model_2 = load_GlotLID(constants.MODEL_NAME, "model_v2.bin")
|
152 |
+
model_3 = load_GlotLID(constants.MODEL_NAME, "model_v3.bin")
|
153 |
|
154 |
# @st.cache_resource
|
155 |
def plot(label, prob):
|
|
|
174 |
ax.set_xlabel("Confidence", color=BLACK_COLOR)
|
175 |
st.pyplot(fig)
|
176 |
|
177 |
+
def compute(sentences, version = 'v3'):
|
178 |
"""Computes the language probablities and labels for the given sentences.
|
179 |
|
180 |
Args:
|
|
|
184 |
A list of language probablities and labels for the given sentences.
|
185 |
"""
|
186 |
progress_text = "Computing Language..."
|
187 |
+
model_choice = model_3 if version == 'v3' else (model_2 if version == 'v2' else model_1)
|
188 |
my_bar = st.progress(0, text=progress_text)
|
189 |
|
190 |
probs = []
|
|
|
201 |
output_label_language = output_label.split('_')[0]
|
202 |
|
203 |
# script control
|
204 |
+
if version in ['v2', 'v3'] and output_label_language!= 'zxx':
|
205 |
main_script, all_scripts = get_script(sent)
|
206 |
output_label_script = output_label.split('_')[1]
|
207 |
|
|
|
242 |
|
243 |
version = st.radio(
|
244 |
"Choose model",
|
245 |
+
["v1", "v2", "v3"],
|
246 |
+
captions=["GlotLID version 1", "GlotLID version 2", "GlotLID version 3 (More languages, better quality data)"],
|
247 |
+
index = 2,
|
248 |
key = 'version_tab1',
|
249 |
horizontal = True
|
250 |
)
|
|
|
281 |
|
282 |
version = st.radio(
|
283 |
"Choose model",
|
284 |
+
["v1", "v2", "v3"],
|
285 |
+
captions=["GlotLID version 1", "GlotLID version 2", "GlotLID version 3 (More languages, better quality data)" ],
|
286 |
+
index = 2,
|
287 |
key = 'version_tab2',
|
288 |
horizontal = True
|
289 |
)
|