UnarineLeo commited on
Commit
0e667ee
1 Parent(s): 46ab7b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -61
app.py CHANGED
@@ -14,77 +14,136 @@ 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("\n")
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)
 
14
  return sentence.replace("<mask>", predicted_word)
15
 
16
  st.title("Fill Mask | Zabantu-nso-120m")
17
+ st.write(f"")
18
+
19
+ col1, col2 = st.columns(2)
20
+
21
+ with col1:
22
+ sample_sentences = [
23
+ "mopresidente wa <mask> wa afrika-borwa"
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("\n")
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)