UnarineLeo commited on
Commit
f73af86
1 Parent(s): c208b95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -82
app.py CHANGED
@@ -1,10 +1,8 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Load the model
5
  unmasker = pipeline('fill-mask', model='dsfsi/zabantu-nso-ven-170m')
6
 
7
- # Function to fill mask for given sentences
8
  def fill_mask(sentences):
9
  results = {}
10
  for sentence in sentences:
@@ -12,102 +10,119 @@ def fill_mask(sentences):
12
  results[sentence] = unmasked
13
  return results
14
 
15
- # Function to replace <mask> token with the predicted word
16
  def replace_mask(sentence, predicted_word):
17
  return sentence.replace("<mask>", predicted_word)
18
 
19
- # Streamlit app title and description
20
- st.title("Fill Mask | Zabantu-nso-ven-170m")
21
- st.write("This app predicts the missing word in a sentence using a Zabantu-nso-ven-170m model.")
22
 
23
- # Sample sentences
24
- sample_sentences = [
25
- "Rabulasi wa <mask> u khou bvelela nga u lima,",
26
- "Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u <mask> nga Listeriosis"
27
- ]
28
 
29
- # Input for sentences with <mask> token
30
- text_input = st.text_area(
31
- "Enter sentences with <mask> token (one per line):",
32
- "\n".join(sample_sentences)
33
- )
34
 
35
- # Split sentences by line
36
- input_sentences = text_input.splitlines()
 
 
37
 
38
- # Button to submit
39
- if st.button("Submit"):
40
- result = fill_mask(input_sentences)
41
 
42
- # Displaying the results with bars for scores
43
- if result:
44
- for sentence, predictions in result.items():
45
- st.write(f"**Original sentence**: {sentence}")
46
 
47
- # Loop through the predictions and display bar + score
48
- for prediction in predictions:
49
- predicted_word = prediction['token_str']
50
- score = prediction['score'] * 100
51
- full_sentence = replace_mask(sentence, predicted_word)
 
 
52
 
53
- # Display the word, bar for score, and full sentence
54
- st.write(f"Predicted word: {predicted_word}")
55
-
56
- # Bar for the score
57
- st.markdown(f"""
58
- <div class="container">
59
- <span class="bar-text">Score: {score:.2f}%</span>
60
  <div class="bar">
61
  <div class="bar-fill" style="width: {score}%;"></div>
62
  </div>
63
- </div>
64
- """, unsafe_allow_html=True)
 
 
 
65
 
66
- st.write(f"Full sentence: {full_sentence}")
67
- st.write("=" * 80)
 
 
 
 
68
 
69
- # Custom CSS for bar styling and other elements
70
  css = """
71
  <style>
72
- footer {display:none !important}
73
- .stButton > button {
74
- background-color: #17152e;
75
- color: white;
76
- border: none;
77
- padding: 0.75em 2em;
78
- text-align: center;
79
- text-decoration: none;
80
- display: inline-block;
81
- font-size: 16px;
82
- margin: 4px 2px;
83
- cursor: pointer;
84
- border-radius: 12px;
85
- transition: background-color 0.3s ease;
 
 
 
 
 
 
 
86
  }
87
- .stButton > button:hover {
88
- background-color: #3c4a6b;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
- .stTextInput, .stTextArea {
91
- border: 1px solid #e6e6e6;
92
- padding: 0.75em;
93
- border-radius: 10px;
94
- font-size: 16px;
95
- width: 100%;
96
  }
97
- .stTextInput:focus, .stTextArea:focus {
98
- border-color: #17152e;
99
- outline: none;
100
- box-shadow: 0px 0px 5px rgba(23, 21, 46, 0.5);
101
  }
102
- div[data-testid="stMarkdownContainer"] p {
103
- font-size: 16px;
 
 
104
  }
105
- .stApp {
106
- padding: 2em;
107
- font-family: 'Poppins', sans-serif;
 
 
 
 
 
108
  }
109
-
110
- /* Bar styles */
111
  .container {
112
  display: flex;
113
  justify-content: space-between;
@@ -116,23 +131,19 @@ div[data-testid="stMarkdownContainer"] p {
116
  width: 100%;
117
  }
118
  .bar {
119
- width: 80%;
120
  background-color: #e6e6e6;
121
  border-radius: 12px;
122
  overflow: hidden;
123
  margin-right: 10px;
124
- height: 20px;
125
  }
126
  .bar-fill {
127
  background-color: #17152e;
128
  height: 100%;
129
  border-radius: 12px;
130
  }
131
- .bar-text {
132
- font-size: 16px;
133
- }
134
  </style>
135
  """
136
 
137
- # Apply the custom CSS
138
- st.markdown(css, unsafe_allow_html=True)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
4
  unmasker = pipeline('fill-mask', model='dsfsi/zabantu-nso-ven-170m')
5
 
 
6
  def fill_mask(sentences):
7
  results = {}
8
  for sentence in sentences:
 
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-170m)
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;
 
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)