Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
| 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
|
| 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
|
| 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 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 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)
|