ez326 commited on
Commit
c25859b
·
verified ·
1 Parent(s): b8406fc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -22
app.py CHANGED
@@ -1,9 +1,37 @@
1
- import streamlit as st
2
- import numpy as np
3
 
4
- st.title("Movie Rating System")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # Define criteria grouped by category with subcategory descriptions
7
  criteria = {
8
  "Writing": [
9
  {"name": "Dialogue", "description": "Word choice, realism, subtext, and implications."},
@@ -49,23 +77,33 @@ criteria = {
49
  ]
50
  }
51
 
52
- ratings = {}
 
 
 
 
 
 
 
 
53
 
54
- # Create sliders for each subcategory under its category header
55
- for group, subcriteria in criteria.items():
56
- st.header(group)
57
- for crit in subcriteria:
58
- label = f"{crit['name']}: {crit['description']}"
59
- ratings[crit["name"]] = st.slider(label, min_value=1, max_value=7, value=4)
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- # When the button is pressed, calculate the overall score
62
- if st.button("Calculate Score"):
63
- valid_ratings = list(ratings.values())
64
- if valid_ratings:
65
- avg = np.mean(valid_ratings)
66
- # Quadratic mapping f(x) = (1/18)x^2 + (19/18)x - (1/9)
67
- # so that f(1)=1, f(4)=5, and f(7)=10.
68
- scaled_score = (1/18) * (avg ** 2) + (19/18) * avg - (1/9)
69
- st.success(f"Final Scaled Score: {scaled_score:.2f} / 10")
70
- else:
71
- st.warning("Please rate at least one category.")
 
1
+ import gradio as gr
 
2
 
3
+ # Custom CSS for styling
4
+ css = """
5
+ .criteria-name {
6
+ font-size: 18px;
7
+ font-weight: bold;
8
+ margin-bottom: 4px;
9
+ }
10
+ .criteria-description {
11
+ font-size: 14px;
12
+ color: #555;
13
+ margin-bottom: 12px;
14
+ }
15
+ .subcriteria {
16
+ margin-bottom: 20px;
17
+ padding: 10px;
18
+ border-bottom: 1px solid #eee;
19
+ }
20
+ .category-header {
21
+ margin-top: 30px;
22
+ margin-bottom: 10px;
23
+ font-size: 20px;
24
+ font-weight: bold;
25
+ border-bottom: 2px solid #ccc;
26
+ padding-bottom: 4px;
27
+ }
28
+ .app-header {
29
+ text-align: center;
30
+ margin-bottom: 30px;
31
+ }
32
+ """
33
 
34
+ # Define criteria grouped by category with names and descriptions
35
  criteria = {
36
  "Writing": [
37
  {"name": "Dialogue", "description": "Word choice, realism, subtext, and implications."},
 
77
  ]
78
  }
79
 
80
+ def calculate_score(*ratings):
81
+ # Exclude blank ratings (value 0 means not rated)
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"**Final Scaled Score:** {scaled_score:.2f} / 10"
89
 
90
+ with gr.Blocks(css=css, title="Movie Rating System") as demo:
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
+ demo.launch()