Spaces:
Sleeping
Sleeping
File size: 4,757 Bytes
19c197e be35644 19c197e ce348fb 43baccc a254087 38a598e 43baccc 19c197e 4d7bc24 5111500 4d7bc24 be35644 bc64858 19c197e 2daa8ec 19c197e bd326a6 76e0010 b1416f5 76e0010 38a598e 76e0010 8be109d 76e0010 4a1ee55 770c64d b1416f5 35a46f6 b1416f5 12fc320 b1416f5 bc64858 2daa8ec 2ea496c 19c197e 2ea496c 992e84a 165fe32 19c197e 165fe32 19c197e 165fe32 19c197e 165fe32 19c197e 165fe32 19c197e 165fe32 bd326a6 165fe32 ed0e30c 35a46f6 d31ee13 0effeae d31ee13 0c419b8 d31ee13 0effeae d31ee13 19c197e bd326a6 2daa8ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import streamlit as st
from transformers import pipeline
unmasker = pipeline('fill-mask', model='dsfsi/zabantu-sot-ven-170m')
st.set_page_config(layout="wide")
def fill_mask(sentences):
results = {}
for sentence in sentences:
if "<mask>" in sentence:
unmasked = unmasker(sentence)
results[sentence] = unmasked
else:
st.warning(f"Warning: No <mask> token found in sentence: {sentence}")
return results
def replace_mask(sentence, predicted_word):
return sentence.replace("<mask>", f"**{predicted_word}**")
st.title("Fill Mask | Zabantu-sot-ven-170m")
st.write(f"")
col1, col2 = st.columns(2)
with col1:
with st.container(border=True):
sample_sentence = "Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u <mask> nga Listeriosis."
text_input = st.text_area(
"Enter sentences with <mask> token:",
)
input_sentences = text_input.split("\n")
if st.button("Submit"):
result = fill_mask(input_sentences)
st.markdown("Example")
st.code(sample_sentence, wrap_lines=True)
with col2:
with st.container(border=True):
st.markdown("Output")
if 'result' in locals():
if result:
for sentence, predictions in result.items():
for prediction in predictions:
predicted_word = prediction['token_str']
score = prediction['score'] * 100
st.markdown(f"""
<div class="bar">
<div class="bar-fill" style="width: {score}%;"></div>
</div>
<div class="container">
<div style="align-items: left;">{predicted_word}</div>
<div style="align-items: center;">{score:.2f}%</div>
</div>
""", unsafe_allow_html=True)
if 'result' in locals():
if result:
for sentence, predictions in result.items():
predicted_word = predictions[0]['token_str']
full_sentence = replace_mask(sentence, predicted_word)
st.write(f"**Sentence:** {full_sentence }")
css = """
<style>
footer {display:none !important;}
.gr-button-primary {
z-index: 14;
height: 43px;
width: 130px;
left: 0px;
top: 0px;
padding: 0px;
cursor: pointer !important;
background: none rgb(17, 20, 45) !important;
border: none !important;
text-align: center !important;
font-family: Poppins !important;
font-size: 14px !important;
font-weight: 500 !important;
color: rgb(255, 255, 255) !important;
line-height: 1 !important;
border-radius: 12px !important;
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
box-shadow: none !important;
}
.gr-button-primary:hover{
z-index: 14;
height: 43px;
width: 130px;
left: 0px;
top: 0px;
padding: 0px;
cursor: pointer !important;
background: none rgb(66, 133, 244) !important;
border: none !important;
text-align: center !important;
font-family: Poppins !important;
font-size: 14px !important;
font-weight: 500 !important;
color: rgb(255, 255, 255) !important;
line-height: 1 !important;
border-radius: 12px !important;
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
}
.hover\:bg-orange-50:hover {
--tw-bg-opacity: 1 !important;
background-color: rgb(229,225,255) !important;
}
.to-orange-200 {
--tw-gradient-to: rgb(37 56 133 / 37%) !important;
}
.from-orange-400 {
--tw-gradient-from: rgb(17, 20, 45) !important;
--tw-gradient-to: rgb(255 150 51 / 0);
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.group-hover\:from-orange-500{
--tw-gradient-from:rgb(17, 20, 45) !important;
--tw-gradient-to: rgb(37 56 133 / 37%);
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.group:hover .group-hover\:text-orange-500{
--tw-text-opacity: 1 !important;
color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 5px;
width: 100%;
}
.bar {
# width: 70%;
background-color: #e6e6e6;
border-radius: 12px;
overflow: hidden;
margin-right: 10px;
height: 5px;
}
.bar-fill {
background-color: #17152e;
height: 100%;
border-radius: 12px;
}
</style>
"""
st.markdown(css, unsafe_allow_html=True) |