ez326 commited on
Commit
4570e2e
·
verified ·
1 Parent(s): 8d1a2b7

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import streamlit as st
2
 
3
- # Custom CSS for styling
4
  css = """
5
  <style>
6
  .criteria-name {
@@ -13,11 +13,12 @@ css = """
13
  color: #555;
14
  margin-bottom: 12px;
15
  }
 
16
  .subcriteria {
17
  margin-bottom: 20px;
18
  padding: 10px;
19
- border-bottom: 1px solid #eee;
20
  }
 
21
  .category-header {
22
  margin-top: 30px;
23
  margin-bottom: 10px;
@@ -30,6 +31,11 @@ css = """
30
  text-align: center;
31
  margin-bottom: 30px;
32
  }
 
 
 
 
 
33
  </style>
34
  """
35
  st.markdown(css, unsafe_allow_html=True)
@@ -81,8 +87,8 @@ criteria = {
81
  }
82
 
83
  def calculate_score(ratings):
84
- # Exclude ratings of 0 (0 means not rated)
85
- valid = [r for r in ratings if r and r > 0]
86
  if not valid:
87
  return "Please rate at least one criterion."
88
  avg = sum(valid) / len(valid)
@@ -104,10 +110,15 @@ for group, subcriteria in criteria.items():
104
  <div class='criteria-description'>{crit['description']}</div>
105
  </div>
106
  """, unsafe_allow_html=True)
107
- # Use a slider for rating (0 means not rated)
108
- key = f"{group}_{idx}"
109
- rating = st.slider(f"Rate {crit['name']} (0-7)", 0, 7, 0, key=key)
110
- ratings.append(rating)
 
 
 
 
 
111
 
112
  if st.button("Calculate Score"):
113
  result = calculate_score(ratings)
 
1
  import streamlit as st
2
 
3
+ # Custom CSS for styling and to hide slider min/max labels
4
  css = """
5
  <style>
6
  .criteria-name {
 
13
  color: #555;
14
  margin-bottom: 12px;
15
  }
16
+ /* Remove line separators between criteria */
17
  .subcriteria {
18
  margin-bottom: 20px;
19
  padding: 10px;
 
20
  }
21
+ /* Group header styling with separator */
22
  .category-header {
23
  margin-top: 30px;
24
  margin-bottom: 10px;
 
31
  text-align: center;
32
  margin-bottom: 30px;
33
  }
34
+ /* Hide slider min and max labels */
35
+ div[data-baseweb="slider"] > div > div:first-child,
36
+ div[data-baseweb="slider"] > div > div:last-child {
37
+ display: none;
38
+ }
39
  </style>
40
  """
41
  st.markdown(css, unsafe_allow_html=True)
 
87
  }
88
 
89
  def calculate_score(ratings):
90
+ # Filter out None values (i.e. criteria marked as N/A)
91
+ valid = [r for r in ratings if r is not None]
92
  if not valid:
93
  return "Please rate at least one criterion."
94
  avg = sum(valid) / len(valid)
 
110
  <div class='criteria-description'>{crit['description']}</div>
111
  </div>
112
  """, unsafe_allow_html=True)
113
+ # Create two columns: one for the slider and one for the N/A checkbox
114
+ cols = st.columns([4, 1])
115
+ na_key = f"na_{group}_{idx}"
116
+ slider_key = f"slider_{group}_{idx}"
117
+ na = cols[1].checkbox("N/A", key=na_key)
118
+ # Slider from 1 to 7 with default value 4; disabled (grayed-out) if N/A is ticked.
119
+ rating = cols[0].slider("", 1, 7, 4, key=slider_key, disabled=na)
120
+ # Use None to denote a nullified rating
121
+ ratings.append(None if na else rating)
122
 
123
  if st.button("Calculate Score"):
124
  result = calculate_score(ratings)