ez326 commited on
Commit
e156efe
·
verified ·
1 Parent(s): b9d560b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import streamlit as st
2
 
3
- # Compact custom CSS for mobile-friendly design and disabled slider styling
4
  css = """
5
  <style>
6
  .criteria-name {
7
  font-size: 14px;
8
  font-weight: bold;
9
- margin-bottom: 2px;
10
  }
11
  .criteria-description {
12
  font-size: 12px;
@@ -36,9 +35,11 @@ css = """
36
  background: #888 !important;
37
  border-color: #888 !important;
38
  }
39
- /* Hide slider tick marks, tick bar, and thumb value */
40
  div[data-baseweb="slider"] .Tick,
41
  div[data-baseweb="slider"] .TickBar,
 
 
42
  div[data-testid="stSliderThumbValue"] {
43
  display: none !important;
44
  }
@@ -93,7 +94,7 @@ criteria = {
93
  }
94
 
95
  def calculate_score(ratings):
96
- # Filter out None values (criteria marked as N/A)
97
  valid = [r for r in ratings if r is not None]
98
  if not valid:
99
  return "Please rate at least one criterion."
@@ -110,20 +111,17 @@ ratings = []
110
  for group, subcriteria in criteria.items():
111
  st.markdown(f"<div class='category-header'>{group}</div>", unsafe_allow_html=True)
112
  for idx, crit in enumerate(subcriteria):
113
- st.markdown(f"""
114
- <div class='subcriteria'>
115
- <div class='criteria-name'>{crit['name']}</div>
116
- <div class='criteria-description'>{crit['description']}</div>
117
- </div>
118
- """, unsafe_allow_html=True)
119
- # Use two columns with a much narrower column for the checkbox
120
- cols = st.columns([3.8, 0.5])
121
- na_key = f"na_{group}_{idx}"
122
- slider_key = f"slider_{group}_{idx}"
123
- na = cols[1].checkbox("N/A", key=na_key)
124
- # Float slider from 1.0 to 7.0 with default value 4.0 and a step of 0.1
125
- rating = cols[0].slider("", 1.0, 7.0, 4.0, step=0.01, key=slider_key, disabled=na)
126
- ratings.append(None if na else rating)
127
 
128
  if st.button("Calculate Score"):
129
  result = calculate_score(ratings)
 
1
  import streamlit as st
2
 
3
+ # Custom CSS for a compact design, hiding slider indicators, and other styling.
4
  css = """
5
  <style>
6
  .criteria-name {
7
  font-size: 14px;
8
  font-weight: bold;
 
9
  }
10
  .criteria-description {
11
  font-size: 12px;
 
35
  background: #888 !important;
36
  border-color: #888 !important;
37
  }
38
+ /* Hide slider tick marks, tick bar, and the min/max texts */
39
  div[data-baseweb="slider"] .Tick,
40
  div[data-baseweb="slider"] .TickBar,
41
+ div[data-testid="stSliderTickBarMin"],
42
+ div[data-testid="stSliderTickBarMax"],
43
  div[data-testid="stSliderThumbValue"] {
44
  display: none !important;
45
  }
 
94
  }
95
 
96
  def calculate_score(ratings):
97
+ # Filter out None values (criteria excluded via unchecked checkbox)
98
  valid = [r for r in ratings if r is not None]
99
  if not valid:
100
  return "Please rate at least one criterion."
 
111
  for group, subcriteria in criteria.items():
112
  st.markdown(f"<div class='category-header'>{group}</div>", unsafe_allow_html=True)
113
  for idx, crit in enumerate(subcriteria):
114
+ # Create a container for each criterion
115
+ with st.container():
116
+ # Place the criterion name and a checkbox in one row.
117
+ header_cols = st.columns([4, 0.5])
118
+ header_cols[0].markdown(f"<span class='criteria-name'>{crit['name']}</span>", unsafe_allow_html=True)
119
+ include = header_cols[1].checkbox("", value=True, key=f"include_{group}_{idx}")
120
+ st.markdown(f"<div class='criteria-description'>{crit['description']}</div>", unsafe_allow_html=True)
121
+ # Display a float slider (with no min/max indicators)
122
+ rating = st.slider("", 1.0, 7.0, 4.0, step=0.1, key=f"slider_{group}_{idx}", disabled=(not include))
123
+ # If the criterion is unchecked, do not consider its rating
124
+ ratings.append(None if not include else rating)
 
 
 
125
 
126
  if st.button("Calculate Score"):
127
  result = calculate_score(ratings)