UnarineLeo commited on
Commit
f0d994d
1 Parent(s): 1146910

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -61
app.py CHANGED
@@ -14,76 +14,136 @@ def replace_mask(sentence, predicted_word):
14
  return sentence.replace("<mask>", predicted_word)
15
 
16
  st.title("Fill Mask | Zabantu-ven-120m")
17
- st.write("This app predicts the missing word in a sentence using a Zabantu-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)
 
 
14
  return sentence.replace("<mask>", predicted_word)
15
 
16
  st.title("Fill Mask | Zabantu-ven-120m")
17
+ st.write(f"")
18
+
19
+ col1, col2 = st.columns(2)
20
+
21
+ with col1:
22
+ sample_sentences = [
23
+ "Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u <mask> nga Listeriosis"
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(",")
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)