Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</style>
|
| 62 |
"""
|
| 63 |
st.markdown(css, unsafe_allow_html=True)
|
| 64 |
|
| 65 |
-
# Define criteria
|
| 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 |
-
#
|
| 124 |
-
#
|
| 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 |
-
#
|
| 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 |
|