Spaces:
Sleeping
Sleeping
VJyzCELERY
commited on
Commit
·
5fd0bf8
1
Parent(s):
390326d
Updated page
Browse files
app.py
CHANGED
|
@@ -61,26 +61,6 @@ def recommend_game(description=None, app_name=None, price_range=None, year_relea
|
|
| 61 |
# Load external CSS file
|
| 62 |
with open('style.css', 'r') as f:
|
| 63 |
custom_css = f.read()
|
| 64 |
-
# for nav
|
| 65 |
-
def set_active_section(btn_id):
|
| 66 |
-
"""
|
| 67 |
-
button active function and handle visibility section
|
| 68 |
-
"""
|
| 69 |
-
# First set all sections to invisible
|
| 70 |
-
updates = [gr.update(visible=False) for _ in sections]
|
| 71 |
-
|
| 72 |
-
# Then set the selected section to visible
|
| 73 |
-
if btn_id in sections:
|
| 74 |
-
index = list(sections.keys()).index(btn_id)
|
| 75 |
-
updates[index] = gr.update(visible=True)
|
| 76 |
-
|
| 77 |
-
# Also update button active states
|
| 78 |
-
button_states = []
|
| 79 |
-
for btn in nav_buttons:
|
| 80 |
-
state = ("active" if btn.elem_id == btn_id else "")
|
| 81 |
-
button_states.append(gr.update(elem_classes=f"nav-btn {state}"))
|
| 82 |
-
|
| 83 |
-
return updates + button_states
|
| 84 |
|
| 85 |
"""
|
| 86 |
MAIN DEMO
|
|
@@ -88,145 +68,100 @@ def set_active_section(btn_id):
|
|
| 88 |
with gr.Blocks(css = custom_css) as demo:
|
| 89 |
# container
|
| 90 |
with gr.Row(elem_classes="container"):
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
Multiselect=True
|
| 126 |
)
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
Label=
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
)
|
| 133 |
-
|
| 134 |
-
expected_playtime = input_number(
|
| 135 |
-
Label='Expected Playtime (Hours)',
|
| 136 |
-
Precision=2,
|
| 137 |
-
minimum=0
|
| 138 |
-
)
|
| 139 |
-
|
| 140 |
-
expected_score = input_number(
|
| 141 |
-
Label='Expected Score (% Positive)',
|
| 142 |
-
Precision=2,
|
| 143 |
-
minimum=0
|
| 144 |
-
)
|
| 145 |
-
|
| 146 |
-
dlc_count = input_number(
|
| 147 |
-
Label='DLC Count',
|
| 148 |
-
Precision=0,
|
| 149 |
-
minimum=0
|
| 150 |
-
)
|
| 151 |
-
|
| 152 |
-
description = input_paragaph_textbox('Description', 'Describe the game (max 1200 characters)...')
|
| 153 |
-
|
| 154 |
-
genre = input_choice(
|
| 155 |
-
Label="Select Your Genre (Multiple Choice)",
|
| 156 |
-
Choices=genres,
|
| 157 |
-
Multiselect=True
|
| 158 |
-
)
|
| 159 |
-
|
| 160 |
-
categories = input_choice(
|
| 161 |
-
Label="Select Your Categories (Multiple Choice)",
|
| 162 |
-
Choices=categories,
|
| 163 |
-
Multiselect=True
|
| 164 |
-
)
|
| 165 |
-
|
| 166 |
-
# single selection (multiselect=False)
|
| 167 |
-
price_range = input_choice(
|
| 168 |
-
Label="Select Your Price Range (Only Single Choice)",
|
| 169 |
-
Choices=price_ranges,
|
| 170 |
-
Multiselect=False
|
| 171 |
-
)
|
| 172 |
-
|
| 173 |
-
top_n= input_number(
|
| 174 |
-
Label='Output amount',
|
| 175 |
-
Precision=0,
|
| 176 |
-
minimum=0,
|
| 177 |
-
value=10
|
| 178 |
-
)
|
| 179 |
-
weight_text = input_number(
|
| 180 |
-
Label='Weight Text',
|
| 181 |
-
Precision=2,
|
| 182 |
-
minimum=0,
|
| 183 |
-
maximum=1,
|
| 184 |
-
value=0.5,
|
| 185 |
-
step=0.01
|
| 186 |
-
)
|
| 187 |
-
weight_collab = input_number(
|
| 188 |
-
Label='Weight Of Collaborative Model',
|
| 189 |
-
Precision=2,
|
| 190 |
-
minimum=0,
|
| 191 |
-
maximum=1,
|
| 192 |
-
value=0.5,
|
| 193 |
-
step=0.01
|
| 194 |
)
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
value=0.5,
|
| 201 |
-
step=0.01
|
| 202 |
)
|
| 203 |
-
submit_btn = gr.Button("Get Recommendations", variant="primary", elem_id="submit-btn")
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
demo.launch()
|
|
|
|
| 61 |
# Load external CSS file
|
| 62 |
with open('style.css', 'r') as f:
|
| 63 |
custom_css = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
"""
|
| 66 |
MAIN DEMO
|
|
|
|
| 68 |
with gr.Blocks(css = custom_css) as demo:
|
| 69 |
# container
|
| 70 |
with gr.Row(elem_classes="container"):
|
| 71 |
+
with gr.Column(elem_id="system", elem_classes='content-section', visible=True) as system_section:
|
| 72 |
+
# special for this section
|
| 73 |
+
gr.HTML('<h1 class="header-title">Game Recommendation System</h1>', elem_id='system')
|
| 74 |
+
with gr.Row():
|
| 75 |
+
with gr.Column(min_width=500, elem_classes='input-column'):
|
| 76 |
+
|
| 77 |
+
app_name = input_choice(
|
| 78 |
+
Label='Select games that you liked',
|
| 79 |
+
Choices=available_names,
|
| 80 |
+
Multiselect=True
|
| 81 |
+
)
|
| 82 |
+
year = input_number(
|
| 83 |
+
Label='Year Release',
|
| 84 |
+
Precision=0,
|
| 85 |
+
minimum=0
|
| 86 |
+
)
|
| 87 |
+
expected_playtime = input_number(
|
| 88 |
+
Label='Expected Playtime (Hours)',
|
| 89 |
+
Precision=2,
|
| 90 |
+
minimum=0
|
| 91 |
+
)
|
| 92 |
+
expected_score = input_number(
|
| 93 |
+
Label='Expected Score (% Positive)',
|
| 94 |
+
Precision=2,
|
| 95 |
+
minimum=0
|
| 96 |
+
)
|
| 97 |
+
dlc_count = input_number(
|
| 98 |
+
Label='DLC Count',
|
| 99 |
+
Precision=0,
|
| 100 |
+
minimum=0
|
| 101 |
+
)
|
| 102 |
+
description = input_paragaph_textbox('Description', 'Describe the game (max 1200 characters)...')
|
| 103 |
+
genre = input_choice(
|
| 104 |
+
Label="Select Your Genre (Multiple Choice)",
|
| 105 |
+
Choices=genres,
|
| 106 |
Multiselect=True
|
| 107 |
)
|
| 108 |
+
|
| 109 |
+
categories = input_choice(
|
| 110 |
+
Label="Select Your Categories (Multiple Choice)",
|
| 111 |
+
Choices=categories,
|
| 112 |
+
Multiselect=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
)
|
| 114 |
+
# single selection (multiselect=False)
|
| 115 |
+
price_range = input_choice(
|
| 116 |
+
Label="Select Your Price Range (Only Single Choice)",
|
| 117 |
+
Choices=price_ranges,
|
| 118 |
+
Multiselect=False
|
|
|
|
|
|
|
| 119 |
)
|
|
|
|
| 120 |
|
| 121 |
+
top_n= input_number(
|
| 122 |
+
Label='Output amount',
|
| 123 |
+
Precision=0,
|
| 124 |
+
minimum=0,
|
| 125 |
+
value=10
|
| 126 |
+
)
|
| 127 |
+
weight_text = input_number(
|
| 128 |
+
Label='Weight Text',
|
| 129 |
+
Precision=2,
|
| 130 |
+
minimum=0,
|
| 131 |
+
maximum=1,
|
| 132 |
+
value=0.5,
|
| 133 |
+
step=0.01
|
| 134 |
+
)
|
| 135 |
+
weight_collab = input_number(
|
| 136 |
+
Label='Weight Of Collaborative Model',
|
| 137 |
+
Precision=2,
|
| 138 |
+
minimum=0,
|
| 139 |
+
maximum=1,
|
| 140 |
+
value=0.5,
|
| 141 |
+
step=0.01
|
| 142 |
+
)
|
| 143 |
+
weight_content = input_number(
|
| 144 |
+
Label='Weight Of Content Based Model',
|
| 145 |
+
Precision=2,
|
| 146 |
+
minimum=0,
|
| 147 |
+
maximum=1,
|
| 148 |
+
value=0.5,
|
| 149 |
+
step=0.01
|
| 150 |
+
)
|
| 151 |
+
submit_btn = gr.Button("Get Recommendations", variant="primary", elem_id="submit-btn")
|
| 152 |
+
|
| 153 |
+
# Results column
|
| 154 |
+
with gr.Column(min_width=500, elem_classes='results-column'):
|
| 155 |
+
h2('Result')
|
| 156 |
+
with gr.Column(elem_id='Output'):
|
| 157 |
+
# Results column using the modular component
|
| 158 |
+
h2('Recommended Game')
|
| 159 |
+
recommended_game = gr.DataFrame()
|
| 160 |
+
# click button logic
|
| 161 |
+
submit_btn.click(
|
| 162 |
+
fn=recommend_game,
|
| 163 |
+
inputs=[description,app_name,price_range,year,expected_playtime,expected_score,dlc_count, genre, categories,top_n,weight_text,weight_collab,weight_content],
|
| 164 |
+
outputs=recommended_game
|
| 165 |
+
)
|
| 166 |
|
| 167 |
demo.launch()
|