Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
unmasker = pipeline('fill-mask', model='dsfsi/zabantu-
|
5 |
|
6 |
-
def fill_mask(
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
return
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
st.
|
17 |
-
st.write("This app predicts the missing word in a sentence using a Zabantu-sot-ven-170m model.")
|
18 |
|
19 |
-
|
|
|
20 |
"Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u <mask> nga Listeriosis"]
|
21 |
|
22 |
-
text_input = st.text_area("Enter sentences with <mask> token (one per line):",
|
23 |
"\n".join(sample_sentences))
|
24 |
|
25 |
-
input_sentences = text_input.split(",")
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
if result:
|
31 |
-
for sentence, predictions in result.items():
|
32 |
-
st.write(f"**Original sentence**: {sentence}")
|
33 |
-
for prediction in predictions:
|
34 |
-
predicted_word = prediction['token_str']
|
35 |
-
score = prediction['score'] * 100
|
36 |
-
full_sentence = replace_mask(sentence, predicted_word)
|
37 |
-
|
38 |
-
st.write(f"Predicted word: {predicted_word} - Score: {score:.2f}%")
|
39 |
-
st.write(f"Full sentence: {full_sentence}")
|
40 |
-
st.write("=" * 80)
|
41 |
|
42 |
css = """
|
43 |
<style>
|
@@ -62,7 +56,7 @@ footer {display:none !important}
|
|
62 |
background-color: #3c4a6b;
|
63 |
}
|
64 |
|
65 |
-
.stTextInput
|
66 |
border: 1px solid #e6e6e6;
|
67 |
padding: 0.75em;
|
68 |
border-radius: 10px;
|
@@ -70,7 +64,7 @@ footer {display:none !important}
|
|
70 |
width: 100%;
|
71 |
}
|
72 |
|
73 |
-
.stTextInput:focus
|
74 |
border-color: #17152e;
|
75 |
outline: none;
|
76 |
box-shadow: 0px 0px 5px rgba(23, 21, 46, 0.5);
|
@@ -84,6 +78,32 @@ div[data-testid="stMarkdownContainer"] p {
|
|
84 |
padding: 2em;
|
85 |
font-family: 'Poppins', sans-serif;
|
86 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
</style>
|
88 |
"""
|
|
|
|
|
89 |
st.markdown(css, unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
unmasker = pipeline('fill-mask', model='dsfsi/zabantu-ven-120m'')
|
5 |
|
6 |
+
def fill_mask(text):
|
7 |
+
unmasked = unmasker(text)
|
8 |
+
output = {}
|
9 |
+
for unmask in unmasked:
|
10 |
+
output[unmask["token_str"]] = unmask["score"]
|
11 |
+
return output
|
12 |
|
13 |
+
st.title("Fill Mask | Zabantu-Bantu-250m")
|
14 |
+
st.write("This app predicts the missing word in a sentence using a BERT model.")
|
15 |
|
16 |
+
col1, col2 = st.columns(2)
|
|
|
17 |
|
18 |
+
with col1:
|
19 |
+
sample_sentences = ["Rabulasi wa <mask> u khou bvelela nga u lima,",
|
20 |
"Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u <mask> nga Listeriosis"]
|
21 |
|
22 |
+
text_input = st.text_area("Enter sentences with <mask> token (one per line):",
|
23 |
"\n".join(sample_sentences))
|
24 |
|
25 |
+
input_sentences = text_input.split(",")
|
26 |
|
27 |
+
with col2:
|
28 |
+
if st.button("Submit"):
|
29 |
+
result = fill_mask(text_input)
|
30 |
+
|
31 |
+
st.write("Predicted words and their probabilities:")
|
32 |
+
for token, score in result.items():
|
33 |
+
st.write(f"**{token}**: {score * 100:.2f}%")
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
css = """
|
37 |
<style>
|
|
|
56 |
background-color: #3c4a6b;
|
57 |
}
|
58 |
|
59 |
+
.stTextInput {
|
60 |
border: 1px solid #e6e6e6;
|
61 |
padding: 0.75em;
|
62 |
border-radius: 10px;
|
|
|
64 |
width: 100%;
|
65 |
}
|
66 |
|
67 |
+
.stTextInput:focus {
|
68 |
border-color: #17152e;
|
69 |
outline: none;
|
70 |
box-shadow: 0px 0px 5px rgba(23, 21, 46, 0.5);
|
|
|
78 |
padding: 2em;
|
79 |
font-family: 'Poppins', sans-serif;
|
80 |
}
|
81 |
+
|
82 |
+
.examples {
|
83 |
+
margin-top: 2em;
|
84 |
+
margin-bottom: 2em;
|
85 |
+
}
|
86 |
+
|
87 |
+
.examples button {
|
88 |
+
background-color: #f0f0f0;
|
89 |
+
border: 1px solid #e6e6e6;
|
90 |
+
padding: 0.5em 1em;
|
91 |
+
margin: 5px;
|
92 |
+
border-radius: 8px;
|
93 |
+
cursor: pointer;
|
94 |
+
}
|
95 |
+
|
96 |
+
.examples button:hover {
|
97 |
+
background-color: #e0e0e0;
|
98 |
+
}
|
99 |
+
|
100 |
+
.stMarkdown h3 {
|
101 |
+
margin-bottom: 0.75em;
|
102 |
+
font-size: 24px;
|
103 |
+
font-weight: 500;
|
104 |
+
}
|
105 |
</style>
|
106 |
"""
|
107 |
+
|
108 |
+
# Inject the custom CSS into the Streamlit app
|
109 |
st.markdown(css, unsafe_allow_html=True)
|