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

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -61
app.py CHANGED
@@ -2,67 +2,75 @@ 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;
26
- margin-bottom: 4px;
27
- font-size: 16px;
28
- font-weight: bold;
29
- border-bottom: 1px solid #ccc;
30
- padding-bottom: 2px;
31
- }
32
- .app-header {
33
- text-align: center;
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"],
46
- div[data-testid="stSliderTickBarMax"],
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)
64
 
65
- # Define criteria grouped by category with names and descriptions
66
  criteria = {
67
  "Writing": [
68
  {"name": "Dialogue", "description": "Word choice, realism, subtext, and implications."},
@@ -113,26 +121,23 @@ def calculate_score(ratings):
113
  if not valid:
114
  return "Please rate at least one criterion."
115
  avg = sum(valid) / len(valid)
116
- # Quadratic scaling: f(x) = (1/18)*x^2 + (19/18)*x - (1/9)
117
  scaled_score = (1/18) * (avg ** 2) + (19/18) * avg - (1/9)
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
 
 
2
 
3
  st.set_page_config(layout="wide")
4
 
 
5
  css = """
6
  <style>
7
+ /* Compact spacing for headings and descriptions */
8
+ .criteria-name {
9
+ font-size: 14px;
10
+ font-weight: bold;
11
+ margin-bottom: 0px;
12
+ }
13
+ .criteria-description {
14
+ font-size: 12px;
15
+ color: #555;
16
+ margin-top: 0px;
17
+ margin-bottom: 2px;
18
+ }
19
+ .subcriteria {
20
+ margin-bottom: 2px;
21
+ padding: 1px 0;
22
+ }
23
+ .category-header {
24
+ margin-top: 6px;
25
+ margin-bottom: 4px;
26
+ font-size: 16px;
27
+ font-weight: bold;
28
+ border-bottom: 1px solid #ccc;
29
+ padding-bottom: 2px;
30
+ }
31
+ .app-header {
32
+ text-align: center;
33
+ margin-bottom: 6px;
34
+ font-size: 20px;
35
+ }
36
+ /* Enlarge slider thumb for easier touch */
37
+ div[data-baseweb="slider"] .Thumb {
38
+ width: 24px !important;
39
+ height: 24px !important;
40
+ }
41
+ /* Hide slider tick marks, tick bar, and min/max texts */
42
+ div[data-baseweb="slider"] .Tick,
43
+ div[data-baseweb="slider"] .TickBar,
44
+ div[data-testid="stSliderTickBarMin"],
45
+ div[data-testid="stSliderTickBarMax"],
46
+ div[data-testid="stSliderThumbValue"] {
47
+ display: none !important;
48
+ }
49
+ /* Remove extra margin above slider */
50
+ .stSlider {
51
+ margin-top: 0px !important;
52
+ }
53
+ /* Prevent header columns from stacking on mobile */
54
+ @media (max-width: 600px) {
55
+ .stHorizontalBlock {
56
+ flex-wrap: nowrap !important;
57
+ }
58
+ .stColumn {
59
+ padding-left: 2px !important;
60
+ padding-right: 2px !important;
61
+ min-width: 0;
62
+ }
63
+ /* Reduce checkbox size further on mobile */
64
+ .stCheckbox {
65
+ transform: scale(0.8);
66
+ transform-origin: left center;
67
+ }
68
+ }
69
  </style>
70
  """
71
  st.markdown(css, unsafe_allow_html=True)
72
 
73
+ # Define criteria with names and descriptions.
74
  criteria = {
75
  "Writing": [
76
  {"name": "Dialogue", "description": "Word choice, realism, subtext, and implications."},
 
121
  if not valid:
122
  return "Please rate at least one criterion."
123
  avg = sum(valid) / len(valid)
 
124
  scaled_score = (1/18) * (avg ** 2) + (19/18) * avg - (1/9)
125
  return f"Final Scaled Score: {scaled_score:.2f} / 10"
126
 
127
  st.markdown("<h1 class='app-header'>Movie Rating System</h1>", unsafe_allow_html=True)
128
  ratings = []
129
 
130
+ # Loop through criteria; for each, display a header row with the criterion name and a small include checkbox,
131
+ # then the description and the slider (with minimal spacing).
132
  for group, subcriteria in criteria.items():
133
  st.markdown(f"<div class='category-header'>{group}</div>", unsafe_allow_html=True)
134
  for idx, crit in enumerate(subcriteria):
135
  with st.container():
136
+ # Header row: name on the left and include checkbox on the right.
137
  header_cols = st.columns([4, 0.5])
138
  header_cols[0].markdown(f"<span class='criteria-name'>{crit['name']}</span>", unsafe_allow_html=True)
139
  include = header_cols[1].checkbox("", value=True, key=f"include_{group}_{idx}")
 
140
  st.markdown(f"<div class='criteria-description'>{crit['description']}</div>", unsafe_allow_html=True)
 
141
  rating = st.slider("", 1.0, 7.0, 4.0, step=0.1, key=f"slider_{group}_{idx}", disabled=(not include))
142
  ratings.append(None if not include else rating)
143