Spaces:
Runtime error
Runtime error
Removed Gallery
Browse files
app.py
CHANGED
|
@@ -49,39 +49,49 @@ def get_recommendations(game_name, data, feature_vectors):
|
|
| 49 |
game_similarity = cosine_similarity(feature_vectors)
|
| 50 |
similarity_scores = list(enumerate(game_similarity[index_of_the_game]))
|
| 51 |
sorted_similar_games = sorted(similarity_scores, key=lambda x: x[1], reverse=True)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
index = game[0]
|
| 56 |
name = data.loc[index, 'name']
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
image_url = data.loc[index, 'header_image'] if 'header_image' in data.columns else None
|
| 61 |
-
|
| 62 |
-
# Get platform information
|
| 63 |
platforms = []
|
| 64 |
-
if
|
| 65 |
platforms.append("Windows")
|
| 66 |
-
if
|
| 67 |
platforms.append("Mac")
|
| 68 |
-
if
|
| 69 |
platforms.append("Linux")
|
| 70 |
-
platforms_str = ", ".join(platforms)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
if
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# Gradio interface function
|
| 87 |
def recommend_games(game_name):
|
|
@@ -90,10 +100,10 @@ def recommend_games(game_name):
|
|
| 90 |
return "Failed to load data. Please check the data file."
|
| 91 |
|
| 92 |
feature_vectors = prepare_features(data)
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
# Format the output for Gradio
|
| 99 |
result_texts = []
|
|
@@ -126,22 +136,13 @@ with gr.Blocks(title="Steam Game Recommender") as demo:
|
|
| 126 |
with gr.Row():
|
| 127 |
output_text = gr.Markdown(label="Recommendations")
|
| 128 |
|
| 129 |
-
with gr.Row():
|
| 130 |
-
output_gallery = gr.Gallery(
|
| 131 |
-
label="Game Images",
|
| 132 |
-
show_label=True,
|
| 133 |
-
elem_id="gallery",
|
| 134 |
-
columns=[3],
|
| 135 |
-
rows=[3],
|
| 136 |
-
height="auto"
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
submit_btn.click(
|
| 140 |
fn=recommend_games,
|
| 141 |
inputs=input_text,
|
| 142 |
-
outputs=
|
| 143 |
)
|
| 144 |
|
|
|
|
| 145 |
# Launch the app
|
| 146 |
if __name__ == "__main__":
|
| 147 |
demo.launch()
|
|
|
|
| 49 |
game_similarity = cosine_similarity(feature_vectors)
|
| 50 |
similarity_scores = list(enumerate(game_similarity[index_of_the_game]))
|
| 51 |
sorted_similar_games = sorted(similarity_scores, key=lambda x: x[1], reverse=True)
|
| 52 |
+
|
| 53 |
+
result_html = ""
|
| 54 |
+
|
| 55 |
+
for i, game in enumerate(sorted_similar_games[1:10], 1):
|
| 56 |
index = game[0]
|
| 57 |
name = data.loc[index, 'name']
|
| 58 |
+
about = data.loc[index, 'short_description'] or "No description available"
|
| 59 |
+
image_url = data.loc[index, 'header_image'] or ""
|
| 60 |
+
|
|
|
|
|
|
|
|
|
|
| 61 |
platforms = []
|
| 62 |
+
if data.loc[index, 'windows'] == 1:
|
| 63 |
platforms.append("Windows")
|
| 64 |
+
if data.loc[index, 'mac'] == 1:
|
| 65 |
platforms.append("Mac")
|
| 66 |
+
if data.loc[index, 'linux'] == 1:
|
| 67 |
platforms.append("Linux")
|
| 68 |
+
platforms_str = ", ".join(platforms) or "Unknown"
|
| 69 |
+
|
| 70 |
+
metacritic = data.loc[index, 'metacritic_score']
|
| 71 |
+
price = data.loc[index, 'price']
|
| 72 |
+
pos = data.loc[index, 'positive']
|
| 73 |
+
neg = data.loc[index, 'negative']
|
| 74 |
+
total_reviews = pos + neg
|
| 75 |
+
pos_ratio = f"{(pos / total_reviews * 100):.1f}%" if total_reviews > 0 else "N/A"
|
| 76 |
+
|
| 77 |
+
# Combine into HTML
|
| 78 |
+
result_html += f"""
|
| 79 |
+
<div style="display:flex; align-items:flex-start; margin-bottom:20px;">
|
| 80 |
+
<img src="{image_url}" style="width:150px; height:auto; margin-right:15px; border-radius:8px;">
|
| 81 |
+
<div>
|
| 82 |
+
<h3>{i}. {name}</h3>
|
| 83 |
+
<p><b>Platforms:</b> {platforms_str}</p>
|
| 84 |
+
<p><b>Price:</b> ${price}</p>
|
| 85 |
+
<p><b>Metacritic Score:</b> {metacritic if pd.notnull(metacritic) else "N/A"}</p>
|
| 86 |
+
<p><b>Positive Reviews:</b> {pos_ratio}</p>
|
| 87 |
+
<p>{about}</p>
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
+
<hr>
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
return result_html
|
| 94 |
+
|
| 95 |
|
| 96 |
# Gradio interface function
|
| 97 |
def recommend_games(game_name):
|
|
|
|
| 100 |
return "Failed to load data. Please check the data file."
|
| 101 |
|
| 102 |
feature_vectors = prepare_features(data)
|
| 103 |
+
recommendations_html = get_recommendations(game_name, data, feature_vectors)
|
| 104 |
|
| 105 |
+
return recommendations_html
|
| 106 |
+
|
| 107 |
|
| 108 |
# Format the output for Gradio
|
| 109 |
result_texts = []
|
|
|
|
| 136 |
with gr.Row():
|
| 137 |
output_text = gr.Markdown(label="Recommendations")
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
submit_btn.click(
|
| 140 |
fn=recommend_games,
|
| 141 |
inputs=input_text,
|
| 142 |
+
outputs=output_text
|
| 143 |
)
|
| 144 |
|
| 145 |
+
|
| 146 |
# Launch the app
|
| 147 |
if __name__ == "__main__":
|
| 148 |
demo.launch()
|