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

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -1,20 +1,25 @@
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;
12
  color: #555;
13
- margin-bottom: 4px;
 
14
  }
15
  .subcriteria {
16
- margin-bottom: 8px;
17
- padding: 5px 0;
18
  }
19
  .category-header {
20
  margin-top: 10px;
@@ -29,13 +34,12 @@ css = """
29
  margin-bottom: 10px;
30
  font-size: 20px;
31
  }
32
- /* When slider is disabled, change the track and thumb to gray */
33
- div[data-baseweb="slider"][aria-disabled="true"] .Track,
34
- div[data-baseweb="slider"][aria-disabled="true"] .Thumb {
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"],
@@ -43,6 +47,17 @@ css = """
43
  div[data-testid="stSliderThumbValue"] {
44
  display: none !important;
45
  }
 
 
 
 
 
 
 
 
 
 
 
46
  </style>
47
  """
48
  st.markdown(css, unsafe_allow_html=True)
@@ -94,7 +109,6 @@ criteria = {
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."
@@ -104,23 +118,22 @@ def calculate_score(ratings):
104
  return f"Final Scaled Score: {scaled_score:.2f} / 10"
105
 
106
  st.markdown("<h1 class='app-header'>Movie Rating System</h1>", unsafe_allow_html=True)
107
-
108
  ratings = []
109
 
110
- # Loop over each category and its subcriteria
 
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"):
 
1
  import streamlit as st
2
 
3
+ st.set_page_config(layout="wide")
4
+
5
+ # Custom CSS to improve compactness and mobile usability
6
  css = """
7
  <style>
8
+ /* Criteria header and description compact styling */
9
  .criteria-name {
10
  font-size: 14px;
11
  font-weight: bold;
12
+ margin-bottom: 0px;
13
  }
14
  .criteria-description {
15
  font-size: 12px;
16
  color: #555;
17
+ margin-top: 0px;
18
+ margin-bottom: 2px;
19
  }
20
  .subcriteria {
21
+ margin-bottom: 4px;
22
+ padding: 2px 0;
23
  }
24
  .category-header {
25
  margin-top: 10px;
 
34
  margin-bottom: 10px;
35
  font-size: 20px;
36
  }
37
+ /* Enlarge the slider thumb for touch screens */
38
+ div[data-baseweb="slider"] .Thumb {
39
+ width: 24px !important;
40
+ height: 24px !important;
 
41
  }
42
+ /* Remove slider tick marks, tick bar, and min/max texts */
43
  div[data-baseweb="slider"] .Tick,
44
  div[data-baseweb="slider"] .TickBar,
45
  div[data-testid="stSliderTickBarMin"],
 
47
  div[data-testid="stSliderThumbValue"] {
48
  display: none !important;
49
  }
50
+ /* Remove extra margin above the slider widget */
51
+ .stSlider {
52
+ margin-top: 0px !important;
53
+ }
54
+ /* Make the include checkbox smaller on mobile */
55
+ @media (max-width: 600px) {
56
+ .stCheckbox {
57
+ transform: scale(0.8);
58
+ transform-origin: left center;
59
+ }
60
+ }
61
  </style>
62
  """
63
  st.markdown(css, unsafe_allow_html=True)
 
109
  }
110
 
111
  def calculate_score(ratings):
 
112
  valid = [r for r in ratings if r is not None]
113
  if not valid:
114
  return "Please rate at least one criterion."
 
118
  return f"Final Scaled Score: {scaled_score:.2f} / 10"
119
 
120
  st.markdown("<h1 class='app-header'>Movie Rating System</h1>", unsafe_allow_html=True)
 
121
  ratings = []
122
 
123
+ # For each category and criterion, display the header with a small checkbox (checked by default)
124
+ # and the description immediately below; then the slider without extra padding.
125
  for group, subcriteria in criteria.items():
126
  st.markdown(f"<div class='category-header'>{group}</div>", unsafe_allow_html=True)
127
  for idx, crit in enumerate(subcriteria):
 
128
  with st.container():
129
+ # Row for the criterion name with a small checkbox beside it
130
  header_cols = st.columns([4, 0.5])
131
  header_cols[0].markdown(f"<span class='criteria-name'>{crit['name']}</span>", unsafe_allow_html=True)
132
  include = header_cols[1].checkbox("", value=True, key=f"include_{group}_{idx}")
133
+ # Description immediately below
134
  st.markdown(f"<div class='criteria-description'>{crit['description']}</div>", unsafe_allow_html=True)
135
+ # Float slider without extra padding; disabled if not included.
136
  rating = st.slider("", 1.0, 7.0, 4.0, step=0.1, key=f"slider_{group}_{idx}", disabled=(not include))
 
137
  ratings.append(None if not include else rating)
138
 
139
  if st.button("Calculate Score"):