Bnava13 commited on
Commit
243bf9f
·
verified ·
1 Parent(s): 65748c4

Removed Gallery

Browse files
Files changed (1) hide show
  1. app.py +42 -41
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
- results = []
54
- for i, game in enumerate(sorted_similar_games[1:10], 1): # Skip the first one as it's the game itself
 
55
  index = game[0]
56
  name = data.loc[index, 'name']
57
-
58
- # Get additional information
59
- about = data.loc[index, 'about_the_game'] if 'about_the_game' in data.columns else "No description available"
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 'windows' in data.columns and data.loc[index, 'windows'] == 1:
65
  platforms.append("Windows")
66
- if 'mac' in data.columns and data.loc[index, 'mac'] == 1:
67
  platforms.append("Mac")
68
- if 'linux' in data.columns and data.loc[index, 'linux'] == 1:
69
  platforms.append("Linux")
70
- platforms_str = ", ".join(platforms) if platforms else "Unknown"
71
-
72
- # Format the result
73
- result = f"**{i}. {name}**\n\n"
74
- result += f"**Platforms:** {platforms_str}\n\n"
75
-
76
- # Truncate the about text to keep output clean
77
- if about and about != "":
78
- result += f"**About the Game:** {about}\n\n"
79
- else:
80
- result += "**About the Game:** No description available\n\n"
81
-
82
- results.append((result, image_url))
83
-
84
- return results
 
 
 
 
 
 
 
 
 
 
 
 
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
- recommendations = get_recommendations(game_name, data, feature_vectors)
94
 
95
- if isinstance(recommendations, str):
96
- return recommendations
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=[output_text, output_gallery]
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()