Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
import
|
| 2 |
|
| 3 |
# Custom CSS for styling
|
| 4 |
css = """
|
|
|
|
| 5 |
.criteria-name {
|
| 6 |
font-size: 18px;
|
| 7 |
font-weight: bold;
|
|
@@ -29,7 +30,9 @@ css = """
|
|
| 29 |
text-align: center;
|
| 30 |
margin-bottom: 30px;
|
| 31 |
}
|
|
|
|
| 32 |
"""
|
|
|
|
| 33 |
|
| 34 |
# Define criteria grouped by category with names and descriptions
|
| 35 |
criteria = {
|
|
@@ -77,33 +80,35 @@ criteria = {
|
|
| 77 |
]
|
| 78 |
}
|
| 79 |
|
| 80 |
-
def calculate_score(
|
| 81 |
-
# Exclude
|
| 82 |
valid = [r for r in ratings if r and r > 0]
|
| 83 |
if not valid:
|
| 84 |
return "Please rate at least one criterion."
|
| 85 |
avg = sum(valid) / len(valid)
|
| 86 |
# Quadratic scaling: f(x) = (1/18)*x^2 + (19/18)*x - (1/9)
|
| 87 |
scaled_score = (1/18) * (avg ** 2) + (19/18) * avg - (1/9)
|
| 88 |
-
return f"
|
| 89 |
|
| 90 |
-
|
| 91 |
-
gr.Markdown("<h1 class='app-header'>Movie Rating System</h1>", unsafe_allow_html=True)
|
| 92 |
-
rating_components = []
|
| 93 |
-
# Loop over each category and its subcriteria
|
| 94 |
-
for group, subcriteria in criteria.items():
|
| 95 |
-
gr.Markdown(f"<div class='category-header'>{group}</div>", unsafe_allow_html=True)
|
| 96 |
-
for crit in subcriteria:
|
| 97 |
-
with gr.Box(elem_classes="subcriteria"):
|
| 98 |
-
gr.Markdown(f"<div class='criteria-name'>{crit['name']}</div>", unsafe_allow_html=True)
|
| 99 |
-
gr.Markdown(f"<div class='criteria-description'>{crit['description']}</div>", unsafe_allow_html=True)
|
| 100 |
-
# The Rating component: 0 means not rated (i.e. blank)
|
| 101 |
-
rating = gr.Rating(num_stars=7, value=0, label="")
|
| 102 |
-
rating_components.append(rating)
|
| 103 |
-
|
| 104 |
-
calculate_btn = gr.Button("Calculate Score")
|
| 105 |
-
output = gr.Markdown("", elem_classes="app-header")
|
| 106 |
-
|
| 107 |
-
calculate_btn.click(fn=calculate_score, inputs=rating_components, outputs=output)
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
|
| 3 |
# Custom CSS for styling
|
| 4 |
css = """
|
| 5 |
+
<style>
|
| 6 |
.criteria-name {
|
| 7 |
font-size: 18px;
|
| 8 |
font-weight: bold;
|
|
|
|
| 30 |
text-align: center;
|
| 31 |
margin-bottom: 30px;
|
| 32 |
}
|
| 33 |
+
</style>
|
| 34 |
"""
|
| 35 |
+
st.markdown(css, unsafe_allow_html=True)
|
| 36 |
|
| 37 |
# Define criteria grouped by category with names and descriptions
|
| 38 |
criteria = {
|
|
|
|
| 80 |
]
|
| 81 |
}
|
| 82 |
|
| 83 |
+
def calculate_score(ratings):
|
| 84 |
+
# Exclude ratings of 0 (0 means not rated)
|
| 85 |
valid = [r for r in ratings if r and r > 0]
|
| 86 |
if not valid:
|
| 87 |
return "Please rate at least one criterion."
|
| 88 |
avg = sum(valid) / len(valid)
|
| 89 |
# Quadratic scaling: f(x) = (1/18)*x^2 + (19/18)*x - (1/9)
|
| 90 |
scaled_score = (1/18) * (avg ** 2) + (19/18) * avg - (1/9)
|
| 91 |
+
return f"Final Scaled Score: {scaled_score:.2f} / 10"
|
| 92 |
|
| 93 |
+
st.markdown("<h1 class='app-header'>Movie Rating System</h1>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
ratings = []
|
| 96 |
+
|
| 97 |
+
# Loop over each category and its subcriteria
|
| 98 |
+
for group, subcriteria in criteria.items():
|
| 99 |
+
st.markdown(f"<div class='category-header'>{group}</div>", unsafe_allow_html=True)
|
| 100 |
+
for idx, crit in enumerate(subcriteria):
|
| 101 |
+
st.markdown(f"""
|
| 102 |
+
<div class='subcriteria'>
|
| 103 |
+
<div class='criteria-name'>{crit['name']}</div>
|
| 104 |
+
<div class='criteria-description'>{crit['description']}</div>
|
| 105 |
+
</div>
|
| 106 |
+
""", unsafe_allow_html=True)
|
| 107 |
+
# Use a slider for rating (0 means not rated)
|
| 108 |
+
key = f"{group}_{idx}"
|
| 109 |
+
rating = st.slider(f"Rate {crit['name']} (0-7)", 0, 7, 0, key=key)
|
| 110 |
+
ratings.append(rating)
|
| 111 |
+
|
| 112 |
+
if st.button("Calculate Score"):
|
| 113 |
+
result = calculate_score(ratings)
|
| 114 |
+
st.markdown(f"<h2 style='text-align:center;'>{result}</h2>", unsafe_allow_html=True)
|