Bnava13 commited on
Commit
70f03d3
·
verified ·
1 Parent(s): dbeda2b

Updated to pos_ratio instead of Meta score

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -9,7 +9,7 @@ import numpy as np
9
  def load_data():
10
  try:
11
  # For Hugging Face Spaces deployment, you might need to adjust this path
12
- data = pd.read_csv('games_march2025_cleaned.csv', nrows=20000, on_bad_lines='skip', engine='python')
13
  return data
14
  except Exception as e:
15
  print(f"Error loading data: {e}")
@@ -93,17 +93,25 @@ def get_recommendations(game_name, data, feature_vectors):
93
 
94
 
95
  # Gradio interface function
96
- def recommend_games(game_name, max_age, max_price, min_metacritic):
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
- data = data[
103
- (data['required_age'] <= max_age) &
104
- (data['price'] <= max_price) &
105
- ((data['metacritic_score'].fillna(0) >= min_metacritic) | data['metacritic_score'].isna())
106
- ].reset_index(drop=True)
 
 
 
 
 
 
 
 
107
 
108
  if data.empty:
109
  return "No games found matching your filter criteria."
@@ -125,7 +133,7 @@ with gr.Blocks(title="Steam Game Recommender") as demo:
125
  with gr.Row():
126
  max_age_slider = gr.Slider(0, 21, value=17, label="Max Age Rating (Avoid Adult Games)")
127
  max_price_slider = gr.Slider(0.0, 100.0, value=60.0, step=0.5, label="Maximum Price ($)")
128
- min_metacritic_slider = gr.Slider(0, 100, value=50, step=1, label="Minimum Metacritic Score")
129
 
130
  with gr.Row():
131
  submit_btn = gr.Button("Get Recommendations")
@@ -135,11 +143,10 @@ with gr.Blocks(title="Steam Game Recommender") as demo:
135
 
136
  submit_btn.click(
137
  fn=recommend_games,
138
- inputs=[input_text, max_age_slider, max_price_slider, min_metacritic_slider],
139
  outputs=output_text
140
  )
141
 
142
-
143
  # Launch the app
144
  if __name__ == "__main__":
145
  demo.launch()
 
9
  def load_data():
10
  try:
11
  # For Hugging Face Spaces deployment, you might need to adjust this path
12
+ data = pd.read_csv('games_march2025_cleaned.csv', nrows=50000, on_bad_lines='skip', engine='python')
13
  return data
14
  except Exception as e:
15
  print(f"Error loading data: {e}")
 
93
 
94
 
95
  # Gradio interface function
96
+ def recommend_games(game_name, max_age, max_price, min_pos_ratio):
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['pos_ratio'] >= min_pos_ratio)
113
+ ].reset_index(drop=True)
114
+
115
 
116
  if data.empty:
117
  return "No games found matching your filter criteria."
 
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
+ min_pos_ratio_slider = gr.Slider(0.0, 1.0, value=0.7, step=0.01, label="Minimum Positive Review Ratio")
137
 
138
  with gr.Row():
139
  submit_btn = gr.Button("Get Recommendations")
 
143
 
144
  submit_btn.click(
145
  fn=recommend_games,
146
+ inputs=[input_text, max_age_slider, max_price_slider, min_pos_ratio_slider],
147
  outputs=output_text
148
  )
149
 
 
150
  # Launch the app
151
  if __name__ == "__main__":
152
  demo.launch()