UnarineLeo commited on
Commit
f5f8f9a
·
verified ·
1 Parent(s): 8a0c18d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ unmasker = pipeline('fill-mask', model='dsfsi/zabantu-bantu-250m')
5
+
6
+ sample_sentences = {
7
+ 'Zulu': "Le ndoda ithi izo____ ukudla.",
8
+ 'Tshivenda': "Mufana uyo____ vhukuma.",
9
+ 'Sepedi': "Mosadi o ____ pheka.",
10
+ 'Tswana': "Monna o ____ tsamaya.",
11
+ 'Tsonga': "N'wana wa xisati u ____ ku tsaka."
12
+ }
13
+
14
+ def fill_mask_for_languages(sentences):
15
+ results = {}
16
+ for language, sentence in sentences.items():
17
+ masked_sentence = sentence.replace('____', unmasker.tokenizer.mask_token)
18
+
19
+ unmasked = unmasker(masked_sentence)
20
+
21
+ results[language] = unmasked
22
+ return results
23
+
24
+ st.title("Fill Mask for Multiple Languages | Zabantu-Bantu-250m")
25
+ st.write("This app predicts the missing word for sentences in Zulu, Tshivenda, Sepedi, Tswana, and Tsonga using a Zabantu BERT model.")
26
+
27
+ st.write("### Sample sentences:")
28
+ for language, sentence in sample_sentences.items():
29
+ st.write(f"**{language}**: {sentence}")
30
+
31
+ if st.button("Submit"):
32
+ result = fill_mask_for_languages(sample_sentences)
33
+
34
+ if result:
35
+ st.write("### Predictions:")
36
+ for language, predictions in result.items():
37
+ original_sentence = sample_sentences[language]
38
+ predicted_sentence = predictions[0]['sequence']
39
+ st.write(f"Original sentence ({language}): {original_sentence}")
40
+ st.write(f"Top prediction for the masked token: {predicted_sentence}\n")
41
+ st.write("=" * 80)
42
+
43
+ css = """
44
+ <style>
45
+ footer {display:none !important}
46
+
47
+ .stButton > button {
48
+ background-color: #17152e;
49
+ color: white;
50
+ border: none;
51
+ padding: 0.75em 2em;
52
+ text-align: center;
53
+ text-decoration: none;
54
+ display: inline-block;
55
+ font-size: 16px;
56
+ margin: 4px 2px;
57
+ cursor: pointer;
58
+ border-radius: 12px;
59
+ transition: background-color 0.3s ease;
60
+ }
61
+
62
+ .stButton > button:hover {
63
+ background-color: #3c4a6b;
64
+ }
65
+
66
+ .stTextInput, .stTextArea {
67
+ border: 1px solid #e6e6e6;
68
+ padding: 0.75em;
69
+ border-radius: 10px;
70
+ font-size: 16px;
71
+ width: 100%;
72
+ }
73
+
74
+ .stTextInput:focus, .stTextArea:focus {
75
+ border-color: #17152e;
76
+ outline: none;
77
+ box-shadow: 0px 0px 5px rgba(23, 21, 46, 0.5);
78
+ }
79
+
80
+ div[data-testid="stMarkdownContainer"] p {
81
+ font-size: 16px;
82
+ }
83
+
84
+ .stApp {
85
+ padding: 2em;
86
+ font-family: 'Poppins', sans-serif;
87
+ }
88
+ </style>
89
+ """
90
+ st.markdown(css, unsafe_allow_html=True)