UnarineLeo commited on
Commit
b205935
1 Parent(s): f56b704

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-nso-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-120m'")
17
+ st.write("This app predicts the missing word in a sentence using a Zabantu-nso-120m' model.")
18
+
19
+ sample_sentences = ["mopresidente wa <mask> wa afrika-borwa",
20
+ "bašomedi ba polase ya dinamune ya zebediela citrus ba hlomile magato a <mask> malebana le go se sepetšwe botse ga dilo ka polaseng eo."
21
+ ]
22
+
23
+ text_input = st.text_area("Enter sentences with <mask> token (one per line):",
24
+ "\n".join(sample_sentences))
25
+
26
+ input_sentences = text_input.split(",")
27
+
28
+ if st.button("Submit"):
29
+ result = fill_mask(input_sentences)
30
+
31
+ if result:
32
+ for sentence, predictions in result.items():
33
+ st.write(f"**Original sentence**: {sentence}")
34
+ for prediction in predictions:
35
+ predicted_word = prediction['token_str']
36
+ score = prediction['score'] * 100
37
+ full_sentence = replace_mask(sentence, predicted_word)
38
+
39
+ st.write(f"Predicted word: {predicted_word} - Score: {score:.2f}%")
40
+ st.write(f"Full sentence: {full_sentence}")
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)