UnarineLeo commited on
Commit
2ea496c
·
verified ·
1 Parent(s): 165fe32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
4
  unmasker = pipeline('fill-mask', model='dsfsi/zabantu-sot-ven-170m')
5
 
6
  def fill_mask(sentences):
@@ -10,8 +11,10 @@ def fill_mask(sentences):
10
  results[sentence] = unmasked
11
  return results
12
 
 
13
  st.title("Fill Mask | Zabantu-sot-ven-170m")
14
 
 
15
  col1, col2 = st.columns(2)
16
 
17
  with col1:
@@ -26,27 +29,41 @@ with col1:
26
  "\n".join(sample_sentences)
27
  )
28
 
 
29
  input_sentences = text_input.split(",")
30
 
31
  if st.button("Submit"):
32
- # Store the result after clicking submit
33
  result = fill_mask(input_sentences)
34
 
35
  with col2:
 
36
  if 'result' in locals():
37
  st.write("Predicted words and their probabilities:")
 
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
- # Display the predicted word with its probability
44
- st.write(f"**{predicted_word}** : {score:.2f}%")
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  css = """
47
  <style>
48
- footer {display:none !important}
49
- .results-markdown{display:none !important}
50
  .gr-button-primary {
51
  z-index: 14;
52
  height: 43px;
@@ -108,7 +125,28 @@ footer {display:none !important}
108
  --tw-text-opacity: 1 !important;
109
  color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
110
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  </style>
112
  """
113
 
114
- st.markdown(css, unsafe_allow_html=True)
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Load the fill-mask model
5
  unmasker = pipeline('fill-mask', model='dsfsi/zabantu-sot-ven-170m')
6
 
7
  def fill_mask(sentences):
 
11
  results[sentence] = unmasked
12
  return results
13
 
14
+ # Title of the app
15
  st.title("Fill Mask | Zabantu-sot-ven-170m")
16
 
17
+ # Two columns layout
18
  col1, col2 = st.columns(2)
19
 
20
  with col1:
 
29
  "\n".join(sample_sentences)
30
  )
31
 
32
+ # Split input sentences into a list
33
  input_sentences = text_input.split(",")
34
 
35
  if st.button("Submit"):
36
+ # Get fill-mask predictions after clicking the submit button
37
  result = fill_mask(input_sentences)
38
 
39
  with col2:
40
+ # If there is a result, display the predictions
41
  if 'result' in locals():
42
  st.write("Predicted words and their probabilities:")
43
+
44
  if result:
45
  for sentence, predictions in result.items():
46
+ st.write(f"**Sentence:** {sentence}") # Show sentence
47
  for prediction in predictions:
48
  predicted_word = prediction['token_str']
49
  score = prediction['score'] * 100
 
 
50
 
51
+ # Display the predicted word with a bar chart representing the score
52
+ st.markdown(f"""
53
+ <div class="container">
54
+ <span>{predicted_word}</span>
55
+ <div class="bar">
56
+ <div class="bar-fill" style="width: {score}%;"></div>
57
+ </div>
58
+ <span>{score:.2f}%</span>
59
+ </div>
60
+ """, unsafe_allow_html=True)
61
+
62
+ # Custom CSS for bar chart styling
63
  css = """
64
  <style>
65
+ footer {display:none !important;}
66
+ .results-markdown{display:none !important;}
67
  .gr-button-primary {
68
  z-index: 14;
69
  height: 43px;
 
125
  --tw-text-opacity: 1 !important;
126
  color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
127
  }
128
+ .container {
129
+ display: flex;
130
+ justify-content: space-between;
131
+ align-items: center;
132
+ margin-bottom: 5px;
133
+ width: 100%;
134
+ }
135
+ .bar {
136
+ width: 70%;
137
+ background-color: #e6e6e6;
138
+ border-radius: 12px;
139
+ overflow: hidden;
140
+ margin-right: 10px;
141
+ height: 20px;
142
+ }
143
+ .bar-fill {
144
+ background-color: #17152e;
145
+ height: 100%;
146
+ border-radius: 12px;
147
+ }
148
  </style>
149
  """
150
 
151
+ # Insert the custom CSS into the Streamlit app
152
+ st.markdown(css, unsafe_allow_html=True)