UnarineLeo
commited on
Commit
•
8cef51d
1
Parent(s):
279d9ee
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(sentences):
|
7 |
+
results = {}
|
8 |
+
for sentence in sentences:
|
9 |
+
unmasked = unmasker(sentence)
|
10 |
+
results[sentence] = unmasked
|
11 |
+
return results
|
12 |
+
|
13 |
+
def replace_mask(sentence, predicted_word):
|
14 |
+
return sentence.replace("<mask>", predicted_word)
|
15 |
+
|
16 |
+
st.title("Fill Mask | Zabantu-nso-ven-120m")
|
17 |
+
st.write("This app predicts the missing word in a sentence using a Zabantu-nso-ven-120m model.")
|
18 |
+
|
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 |
+
if st.button("Submit"):
|
28 |
+
result = fill_mask(input_sentences)
|
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>
|
44 |
+
footer {display:none !important}
|
45 |
+
|
46 |
+
.stButton > button {
|
47 |
+
background-color: #17152e;
|
48 |
+
color: white;
|
49 |
+
border: none;
|
50 |
+
padding: 0.75em 2em;
|
51 |
+
text-align: center;
|
52 |
+
text-decoration: none;
|
53 |
+
display: inline-block;
|
54 |
+
font-size: 16px;
|
55 |
+
margin: 4px 2px;
|
56 |
+
cursor: pointer;
|
57 |
+
border-radius: 12px;
|
58 |
+
transition: background-color 0.3s ease;
|
59 |
+
}
|
60 |
+
|
61 |
+
.stButton > button:hover {
|
62 |
+
background-color: #3c4a6b;
|
63 |
+
}
|
64 |
+
|
65 |
+
.stTextInput, .stTextArea {
|
66 |
+
border: 1px solid #e6e6e6;
|
67 |
+
padding: 0.75em;
|
68 |
+
border-radius: 10px;
|
69 |
+
font-size: 16px;
|
70 |
+
width: 100%;
|
71 |
+
}
|
72 |
+
|
73 |
+
.stTextInput:focus, .stTextArea:focus {
|
74 |
+
border-color: #17152e;
|
75 |
+
outline: none;
|
76 |
+
box-shadow: 0px 0px 5px rgba(23, 21, 46, 0.5);
|
77 |
+
}
|
78 |
+
|
79 |
+
div[data-testid="stMarkdownContainer"] p {
|
80 |
+
font-size: 16px;
|
81 |
+
}
|
82 |
+
|
83 |
+
.stApp {
|
84 |
+
padding: 2em;
|
85 |
+
font-family: 'Poppins', sans-serif;
|
86 |
+
}
|
87 |
+
</style>
|
88 |
+
"""
|
89 |
+
st.markdown(css, unsafe_allow_html=True)
|