Spaces:
Runtime error
Runtime error
Positive Reviews should show percentages
Browse files
app.py
CHANGED
|
@@ -51,8 +51,7 @@ def get_recommendations(game_name, data, feature_vectors):
|
|
| 51 |
|
| 52 |
result_html = ""
|
| 53 |
|
| 54 |
-
for i,
|
| 55 |
-
index = game[0]
|
| 56 |
name = data.loc[index, 'name']
|
| 57 |
about = data.loc[index, 'short_description'] or "No description available"
|
| 58 |
image_url = data.loc[index, 'header_image'] or ""
|
|
@@ -66,22 +65,19 @@ def get_recommendations(game_name, data, feature_vectors):
|
|
| 66 |
platforms.append("Linux")
|
| 67 |
platforms_str = ", ".join(platforms) or "Unknown"
|
| 68 |
|
| 69 |
-
metacritic = data.loc[index, 'metacritic_score']
|
| 70 |
price = data.loc[index, 'price']
|
| 71 |
pos = data.loc[index, 'positive']
|
| 72 |
neg = data.loc[index, 'negative']
|
| 73 |
total_reviews = pos + neg
|
| 74 |
pos_ratio = f"{(pos / total_reviews * 100):.1f}%" if total_reviews > 0 else "N/A"
|
| 75 |
|
| 76 |
-
# Combine into HTML
|
| 77 |
result_html += f"""
|
| 78 |
<div style="display:flex; align-items:flex-start; margin-bottom:20px;">
|
| 79 |
<img src="{image_url}" style="width:150px; height:auto; margin-right:15px; border-radius:8px;">
|
| 80 |
<div>
|
| 81 |
-
<h3>{i}. {name}</h3>
|
| 82 |
<p><b>Platforms:</b> {platforms_str}</p>
|
| 83 |
<p><b>Price:</b> ${price}</p>
|
| 84 |
-
<p><b>Metacritic Score:</b> {metacritic if pd.notnull(metacritic) else "N/A"}</p>
|
| 85 |
<p><b>Positive Reviews:</b> {pos_ratio}</p>
|
| 86 |
<p>{about}</p>
|
| 87 |
</div>
|
|
@@ -91,20 +87,29 @@ def get_recommendations(game_name, data, feature_vectors):
|
|
| 91 |
|
| 92 |
return result_html
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
data = data[
|
| 103 |
(data['required_age'] <= max_age) &
|
| 104 |
(data['price'] <= max_price) &
|
| 105 |
-
(data['
|
| 106 |
].reset_index(drop=True)
|
| 107 |
-
|
| 108 |
if data.empty:
|
| 109 |
return "No games found matching your filter criteria."
|
| 110 |
|
|
@@ -113,6 +118,7 @@ def recommend_games(game_name, max_age, max_price, min_positive_reviews):
|
|
| 113 |
|
| 114 |
return recommendations_html
|
| 115 |
|
|
|
|
| 116 |
|
| 117 |
# Format the output for Gradio
|
| 118 |
result_texts = []
|
|
@@ -135,32 +141,29 @@ def recommend_games(game_name, max_age, max_price, min_positive_reviews):
|
|
| 135 |
|
| 136 |
# Create the Gradio interface
|
| 137 |
with gr.Blocks(title="Steam Game Recommender") as demo:
|
| 138 |
-
gr.Markdown("#Steam Game Recommender")
|
| 139 |
-
gr.Markdown("Enter a game you like and
|
| 140 |
|
| 141 |
with gr.Row():
|
| 142 |
-
input_text = gr.Textbox(label="Favorite Game")
|
| 143 |
|
| 144 |
with gr.Row():
|
| 145 |
max_age_slider = gr.Slider(0, 21, value=17, label="Max Age Rating (Avoid Adult Games)")
|
| 146 |
max_price_slider = gr.Slider(0.0, 100.0, value=60.0, step=0.5, label="Maximum Price ($)")
|
| 147 |
-
|
| 148 |
|
| 149 |
with gr.Row():
|
| 150 |
-
submit_btn = gr.Button("Get Recommendations")
|
| 151 |
|
| 152 |
with gr.Row():
|
| 153 |
-
output_text = gr.Markdown(label="Recommendations")
|
| 154 |
|
| 155 |
submit_btn.click(
|
| 156 |
fn=recommend_games,
|
| 157 |
-
inputs=[input_text, max_age_slider, max_price_slider,
|
| 158 |
outputs=output_text
|
| 159 |
)
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
# Launch the app
|
| 165 |
if __name__ == "__main__":
|
| 166 |
demo.launch()
|
|
|
|
| 51 |
|
| 52 |
result_html = ""
|
| 53 |
|
| 54 |
+
for i, (index, score) in enumerate(sorted_similar_games[1:10], 1):
|
|
|
|
| 55 |
name = data.loc[index, 'name']
|
| 56 |
about = data.loc[index, 'short_description'] or "No description available"
|
| 57 |
image_url = data.loc[index, 'header_image'] or ""
|
|
|
|
| 65 |
platforms.append("Linux")
|
| 66 |
platforms_str = ", ".join(platforms) or "Unknown"
|
| 67 |
|
|
|
|
| 68 |
price = data.loc[index, 'price']
|
| 69 |
pos = data.loc[index, 'positive']
|
| 70 |
neg = data.loc[index, 'negative']
|
| 71 |
total_reviews = pos + neg
|
| 72 |
pos_ratio = f"{(pos / total_reviews * 100):.1f}%" if total_reviews > 0 else "N/A"
|
| 73 |
|
|
|
|
| 74 |
result_html += f"""
|
| 75 |
<div style="display:flex; align-items:flex-start; margin-bottom:20px;">
|
| 76 |
<img src="{image_url}" style="width:150px; height:auto; margin-right:15px; border-radius:8px;">
|
| 77 |
<div>
|
| 78 |
+
<h3>{i}. {name} <small>(Similarity: {score:.2f})</small></h3>
|
| 79 |
<p><b>Platforms:</b> {platforms_str}</p>
|
| 80 |
<p><b>Price:</b> ${price}</p>
|
|
|
|
| 81 |
<p><b>Positive Reviews:</b> {pos_ratio}</p>
|
| 82 |
<p>{about}</p>
|
| 83 |
</div>
|
|
|
|
| 87 |
|
| 88 |
return result_html
|
| 89 |
|
|
|
|
| 90 |
# Gradio interface function
|
| 91 |
+
def recommend_games(game_name, max_age, max_price, min_pos_neg_ratio):
|
| 92 |
data = load_data()
|
| 93 |
if data is None:
|
| 94 |
return "Failed to load data. Please check the data file."
|
| 95 |
+
|
| 96 |
+
# Fill NA values to avoid division errors
|
| 97 |
+
data['positive'] = data['positive'].fillna(0)
|
| 98 |
+
data['negative'] = data['negative'].fillna(0)
|
| 99 |
+
|
| 100 |
+
# Calculate the positive-to-negative ratio (avoid division by zero)
|
| 101 |
+
data['pos_neg_ratio'] = data.apply(
|
| 102 |
+
lambda row: (row['positive'] / row['negative']) if row['negative'] > 0 else row['positive'],
|
| 103 |
+
axis=1
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# Apply filters
|
| 107 |
data = data[
|
| 108 |
(data['required_age'] <= max_age) &
|
| 109 |
(data['price'] <= max_price) &
|
| 110 |
+
(data['pos_neg_ratio'] >= min_pos_neg_ratio)
|
| 111 |
].reset_index(drop=True)
|
| 112 |
+
|
| 113 |
if data.empty:
|
| 114 |
return "No games found matching your filter criteria."
|
| 115 |
|
|
|
|
| 118 |
|
| 119 |
return recommendations_html
|
| 120 |
|
| 121 |
+
|
| 122 |
|
| 123 |
# Format the output for Gradio
|
| 124 |
result_texts = []
|
|
|
|
| 141 |
|
| 142 |
# Create the Gradio interface
|
| 143 |
with gr.Blocks(title="Steam Game Recommender") as demo:
|
| 144 |
+
gr.Markdown("# ๐ฎ Steam Game Recommender")
|
| 145 |
+
gr.Markdown("Enter a game you like and adjust filters to get the best matches.")
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
+
input_text = gr.Textbox(label="๐ฏ Favorite Game")
|
| 149 |
|
| 150 |
with gr.Row():
|
| 151 |
max_age_slider = gr.Slider(0, 21, value=17, label="Max Age Rating (Avoid Adult Games)")
|
| 152 |
max_price_slider = gr.Slider(0.0, 100.0, value=60.0, step=0.5, label="Maximum Price ($)")
|
| 153 |
+
min_pos_neg_slider = gr.Slider(0.0, 10.0, value=2.0, step=0.1, label="Min Positive:Negative Ratio")
|
| 154 |
|
| 155 |
with gr.Row():
|
| 156 |
+
submit_btn = gr.Button("๐ Get Recommendations")
|
| 157 |
|
| 158 |
with gr.Row():
|
| 159 |
+
output_text = gr.Markdown(label="๐ง Recommendations")
|
| 160 |
|
| 161 |
submit_btn.click(
|
| 162 |
fn=recommend_games,
|
| 163 |
+
inputs=[input_text, max_age_slider, max_price_slider, min_pos_neg_slider],
|
| 164 |
outputs=output_text
|
| 165 |
)
|
| 166 |
|
|
|
|
|
|
|
|
|
|
| 167 |
# Launch the app
|
| 168 |
if __name__ == "__main__":
|
| 169 |
demo.launch()
|