Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import difflib
|
| 3 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
@@ -93,25 +94,17 @@ def get_recommendations(game_name, data, feature_vectors):
|
|
| 93 |
|
| 94 |
|
| 95 |
# Gradio interface function
|
| 96 |
-
def recommend_games(game_name, max_age, max_price,
|
| 97 |
data = load_data()
|
| 98 |
if data is None:
|
| 99 |
return "Failed to load data. Please check the data file."
|
| 100 |
|
| 101 |
# Apply filters BEFORE feature preparation
|
| 102 |
-
# Avoid division by zero and filter by positive ratio
|
| 103 |
-
data['pos_ratio'] = data.apply(
|
| 104 |
-
lambda row: (row['positive'] / (row['positive'] + row['negative']))
|
| 105 |
-
if (row['positive'] + row['negative']) > 0 else 0,
|
| 106 |
-
axis=1
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
data = data[
|
| 110 |
(data['required_age'] <= max_age) &
|
| 111 |
(data['price'] <= max_price) &
|
| 112 |
-
(data['
|
| 113 |
].reset_index(drop=True)
|
| 114 |
-
|
| 115 |
|
| 116 |
if data.empty:
|
| 117 |
return "No games found matching your filter criteria."
|
|
@@ -133,7 +126,7 @@ with gr.Blocks(title="Steam Game Recommender") as demo:
|
|
| 133 |
with gr.Row():
|
| 134 |
max_age_slider = gr.Slider(0, 21, value=17, label="Max Age Rating (Avoid Adult Games)")
|
| 135 |
max_price_slider = gr.Slider(0.0, 100.0, value=60.0, step=0.5, label="Maximum Price ($)")
|
| 136 |
-
|
| 137 |
|
| 138 |
with gr.Row():
|
| 139 |
submit_btn = gr.Button("Get Recommendations")
|
|
@@ -143,10 +136,13 @@ with gr.Blocks(title="Steam Game Recommender") as demo:
|
|
| 143 |
|
| 144 |
submit_btn.click(
|
| 145 |
fn=recommend_games,
|
| 146 |
-
inputs=[input_text, max_age_slider, max_price_slider,
|
| 147 |
outputs=output_text
|
| 148 |
)
|
| 149 |
|
|
|
|
| 150 |
# Launch the app
|
| 151 |
if __name__ == "__main__":
|
| 152 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
| 1 |
+
Can you help me filter this based on the pos_ratio instead?
|
| 2 |
import pandas as pd
|
| 3 |
import difflib
|
| 4 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
# Gradio interface function
|
| 97 |
+
def recommend_games(game_name, max_age, max_price, min_metacritic):
|
| 98 |
data = load_data()
|
| 99 |
if data is None:
|
| 100 |
return "Failed to load data. Please check the data file."
|
| 101 |
|
| 102 |
# Apply filters BEFORE feature preparation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
data = data[
|
| 104 |
(data['required_age'] <= max_age) &
|
| 105 |
(data['price'] <= max_price) &
|
| 106 |
+
((data['metacritic_score'].fillna(0) >= min_metacritic) | data['metacritic_score'].isna())
|
| 107 |
].reset_index(drop=True)
|
|
|
|
| 108 |
|
| 109 |
if data.empty:
|
| 110 |
return "No games found matching your filter criteria."
|
|
|
|
| 126 |
with gr.Row():
|
| 127 |
max_age_slider = gr.Slider(0, 21, value=17, label="Max Age Rating (Avoid Adult Games)")
|
| 128 |
max_price_slider = gr.Slider(0.0, 100.0, value=60.0, step=0.5, label="Maximum Price ($)")
|
| 129 |
+
min_metacritic_slider = gr.Slider(0, 100, value=50, step=1, label="Minimum Metacritic Score")
|
| 130 |
|
| 131 |
with gr.Row():
|
| 132 |
submit_btn = gr.Button("Get Recommendations")
|
|
|
|
| 136 |
|
| 137 |
submit_btn.click(
|
| 138 |
fn=recommend_games,
|
| 139 |
+
inputs=[input_text, max_age_slider, max_price_slider, min_metacritic_slider],
|
| 140 |
outputs=output_text
|
| 141 |
)
|
| 142 |
|
| 143 |
+
|
| 144 |
# Launch the app
|
| 145 |
if __name__ == "__main__":
|
| 146 |
+
demo.launch()
|
| 147 |
+
|
| 148 |
+
|