UnarineLeo
commited on
Commit
•
f0d994d
1
Parent(s):
1146910
Update app.py
Browse files
app.py
CHANGED
@@ -14,76 +14,136 @@ def replace_mask(sentence, predicted_word):
|
|
14 |
return sentence.replace("<mask>", predicted_word)
|
15 |
|
16 |
st.title("Fill Mask | Zabantu-ven-120m")
|
17 |
-
st.write("
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
44 |
-
footer {display:none !important}
|
45 |
-
|
46 |
-
.
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
padding: 0.75em;
|
68 |
-
border-radius: 10px;
|
69 |
-
font-size: 16px;
|
70 |
-
width: 100%;
|
71 |
}
|
72 |
-
|
73 |
-
|
74 |
-
border-color: #17152e;
|
75 |
-
outline: none;
|
76 |
-
box-shadow: 0px 0px 5px rgba(23, 21, 46, 0.5);
|
77 |
}
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
81 |
}
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
</style>
|
88 |
"""
|
89 |
-
|
|
|
|
14 |
return sentence.replace("<mask>", predicted_word)
|
15 |
|
16 |
st.title("Fill Mask | Zabantu-ven-120m")
|
17 |
+
st.write(f"")
|
18 |
+
|
19 |
+
col1, col2 = st.columns(2)
|
20 |
+
|
21 |
+
with col1:
|
22 |
+
sample_sentences = [
|
23 |
+
"Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u <mask> nga Listeriosis"
|
24 |
+
]
|
25 |
+
|
26 |
+
text_input = st.text_area(
|
27 |
+
"Enter sentences with <mask> token (one per line):",
|
28 |
+
"\n".join(sample_sentences)
|
29 |
+
)
|
30 |
+
|
31 |
+
input_sentences = text_input.split(",")
|
32 |
+
|
33 |
+
if st.button("Submit"):
|
34 |
+
result = fill_mask(input_sentences)
|
35 |
+
|
36 |
+
with col2:
|
37 |
+
if 'result' in locals():
|
38 |
+
if result:
|
39 |
+
for sentence, predictions in result.items():
|
40 |
+
for prediction in predictions:
|
41 |
+
predicted_word = prediction['token_str']
|
42 |
+
score = prediction['score'] * 100
|
43 |
+
|
44 |
+
st.markdown(f"""
|
45 |
+
<div class="bar">
|
46 |
+
<div class="bar-fill" style="width: {score}%;"></div>
|
47 |
+
</div>
|
48 |
+
<div class="container">
|
49 |
+
<div style="align-items: left;">{predicted_word}</div>
|
50 |
+
<div style="align-items: right;">{score:.2f}%</div>
|
51 |
+
</div>
|
52 |
+
""", unsafe_allow_html=True)
|
53 |
+
|
54 |
+
if 'result' in locals():
|
55 |
+
if result:
|
56 |
+
for sentence, predictions in result.items():
|
57 |
+
predicted_word = predictions[0]['token_str']
|
58 |
full_sentence = replace_mask(sentence, predicted_word)
|
59 |
+
st.write(f"**Sentence:** {full_sentence }")
|
|
|
|
|
|
|
60 |
|
61 |
css = """
|
62 |
<style>
|
63 |
+
footer {display:none !important;}
|
64 |
+
|
65 |
+
.gr-button-primary {
|
66 |
+
z-index: 14;
|
67 |
+
height: 43px;
|
68 |
+
width: 130px;
|
69 |
+
left: 0px;
|
70 |
+
top: 0px;
|
71 |
+
padding: 0px;
|
72 |
+
cursor: pointer !important;
|
73 |
+
background: none rgb(17, 20, 45) !important;
|
74 |
+
border: none !important;
|
75 |
+
text-align: center !important;
|
76 |
+
font-family: Poppins !important;
|
77 |
+
font-size: 14px !important;
|
78 |
+
font-weight: 500 !important;
|
79 |
+
color: rgb(255, 255, 255) !important;
|
80 |
+
line-height: 1 !important;
|
81 |
+
border-radius: 12px !important;
|
82 |
+
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
83 |
+
box-shadow: none !important;
|
84 |
}
|
85 |
+
.gr-button-primary:hover{
|
86 |
+
z-index: 14;
|
87 |
+
height: 43px;
|
88 |
+
width: 130px;
|
89 |
+
left: 0px;
|
90 |
+
top: 0px;
|
91 |
+
padding: 0px;
|
92 |
+
cursor: pointer !important;
|
93 |
+
background: none rgb(66, 133, 244) !important;
|
94 |
+
border: none !important;
|
95 |
+
text-align: center !important;
|
96 |
+
font-family: Poppins !important;
|
97 |
+
font-size: 14px !important;
|
98 |
+
font-weight: 500 !important;
|
99 |
+
color: rgb(255, 255, 255) !important;
|
100 |
+
line-height: 1 !important;
|
101 |
+
border-radius: 12px !important;
|
102 |
+
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
103 |
+
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
|
104 |
}
|
105 |
+
.hover\:bg-orange-50:hover {
|
106 |
+
--tw-bg-opacity: 1 !important;
|
107 |
+
background-color: rgb(229,225,255) !important;
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
+
.to-orange-200 {
|
110 |
+
--tw-gradient-to: rgb(37 56 133 / 37%) !important;
|
|
|
|
|
|
|
111 |
}
|
112 |
+
.from-orange-400 {
|
113 |
+
--tw-gradient-from: rgb(17, 20, 45) !important;
|
114 |
+
--tw-gradient-to: rgb(255 150 51 / 0);
|
115 |
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
|
116 |
}
|
117 |
+
.group-hover\:from-orange-500{
|
118 |
+
--tw-gradient-from:rgb(17, 20, 45) !important;
|
119 |
+
--tw-gradient-to: rgb(37 56 133 / 37%);
|
120 |
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
|
121 |
+
}
|
122 |
+
.group:hover .group-hover\:text-orange-500{
|
123 |
+
--tw-text-opacity: 1 !important;
|
124 |
+
color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
|
125 |
+
}
|
126 |
+
.container {
|
127 |
+
display: flex;
|
128 |
+
justify-content: space-between;
|
129 |
+
align-items: center;
|
130 |
+
margin-bottom: 5px;
|
131 |
+
width: 100%;
|
132 |
+
}
|
133 |
+
.bar {
|
134 |
+
width: 70%;
|
135 |
+
background-color: #e6e6e6;
|
136 |
+
border-radius: 12px;
|
137 |
+
overflow: hidden;
|
138 |
+
margin-right: 10px;
|
139 |
+
height: 5px;
|
140 |
+
}
|
141 |
+
.bar-fill {
|
142 |
+
background-color: #17152e;
|
143 |
+
height: 100%;
|
144 |
+
border-radius: 12px;
|
145 |
}
|
146 |
</style>
|
147 |
"""
|
148 |
+
|
149 |
+
st.markdown(css, unsafe_allow_html=True)
|