UnarineLeo
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -15,16 +15,17 @@ def fill_mask(sentences):
|
|
15 |
warnings.append(f"Warning: Choose language for {sentence}")
|
16 |
continue
|
17 |
|
18 |
-
if language != 'choose language' and sentence ==
|
19 |
warnings.append(f"Warning: Enter sentence for {language}")
|
20 |
continue
|
21 |
|
22 |
if "<mask>" in sentence:
|
23 |
masked_sentence = sentence.replace('<mask>', unmasker.tokenizer.mask_token)
|
24 |
unmasked = unmasker(masked_sentence)
|
25 |
-
results[
|
26 |
else:
|
27 |
warnings.append(f"Warning: No <mask> token found in sentence: {sentence}")
|
|
|
28 |
return results, warnings
|
29 |
|
30 |
def replace_mask(sentence, predicted_word):
|
@@ -122,7 +123,7 @@ with col2:
|
|
122 |
st.markdown("Output :bar_chart:")
|
123 |
if 'result' in locals() and result:
|
124 |
if len(result) == 1:
|
125 |
-
for language,
|
126 |
for prediction in predictions:
|
127 |
predicted_word = prediction['token_str']
|
128 |
score = prediction['score'] * 100
|
@@ -158,7 +159,7 @@ with col2:
|
|
158 |
if 'result' in locals():
|
159 |
if result:
|
160 |
line = 0
|
161 |
-
for
|
162 |
line += 1
|
163 |
predicted_word = predictions[0]['token_str']
|
164 |
full_sentence = replace_mask(sentence, predicted_word)
|
|
|
15 |
warnings.append(f"Warning: Choose language for {sentence}")
|
16 |
continue
|
17 |
|
18 |
+
if language != 'choose language' and sentence == "":
|
19 |
warnings.append(f"Warning: Enter sentence for {language}")
|
20 |
continue
|
21 |
|
22 |
if "<mask>" in sentence:
|
23 |
masked_sentence = sentence.replace('<mask>', unmasker.tokenizer.mask_token)
|
24 |
unmasked = unmasker(masked_sentence)
|
25 |
+
results[key] = (unmasked,language,sentence)
|
26 |
else:
|
27 |
warnings.append(f"Warning: No <mask> token found in sentence: {sentence}")
|
28 |
+
|
29 |
return results, warnings
|
30 |
|
31 |
def replace_mask(sentence, predicted_word):
|
|
|
123 |
st.markdown("Output :bar_chart:")
|
124 |
if 'result' in locals() and result:
|
125 |
if len(result) == 1:
|
126 |
+
for key,(predictions, language, sentence) in result.items():
|
127 |
for prediction in predictions:
|
128 |
predicted_word = prediction['token_str']
|
129 |
score = prediction['score'] * 100
|
|
|
159 |
if 'result' in locals():
|
160 |
if result:
|
161 |
line = 0
|
162 |
+
for key,(predictions, language, sentence) in result.items():
|
163 |
line += 1
|
164 |
predicted_word = predictions[0]['token_str']
|
165 |
full_sentence = replace_mask(sentence, predicted_word)
|