deppfellow commited on
Commit
1c645c1
·
1 Parent(s): 9c380b8

Fixing error handling but honestly I am not so sure

Browse files
Files changed (4) hide show
  1. app.py +15 -12
  2. contentBased_model.py +2 -2
  3. easeBased_model.py +5 -1
  4. func.py +11 -6
app.py CHANGED
@@ -39,10 +39,12 @@ def games_recomm(preferences_id):
39
  })
40
  ease_df = pred_df[pred_df['app_id'].isin(ease_ids)]
41
 
42
- res_cbf = cbf_model(pred_df=pred_df, k=100)
43
- res_ease = ease_model(pred_df=ease_df, k=100)
44
-
45
- res = combine_hybrid_result(res_ease, res_cbf)
 
 
46
 
47
  # st.write(res)
48
  # st.write("Result of EASE:")
@@ -58,15 +60,18 @@ def games_recomm(preferences_id):
58
 
59
  if type(res) == ValueError:
60
  st.error("Recommendation failed. Please select with at least 3 games title.")
61
- st.session_state
62
  return
63
  else:
64
  st.session_state['rs'] = res
65
 
66
- if len(st.session_state['rs']) >= 1:
67
- st.success(f"Go to result page to view top {len(st.session_state['rs'])} recommendations.")
68
- else:
69
- st.error("Recommendation failed. Please reload the session.")
 
 
 
70
 
71
  # st.write(res)
72
 
@@ -154,9 +159,7 @@ def result_page():
154
  def about_page():
155
  st.header("Development")
156
  """
157
- Cek [repositori](https://github.com/deppfellow/ta-steam_recsys) untuk informasi, source code, dan metode yang digunakan. Jangan ragu Jika anda memiliki pertanyaan.
158
-
159
- Periksa repositori untuk kode sumber. Jangan ragu jika Anda memiliki pertanyaan. Anda dapat menghubungi saya melalui discord atau email dengan informasi di bawah:
160
  - Discord: deppfellow
161
  - Email : raid.rafif@mail.ugm.ac.id
162
  """
 
39
  })
40
  ease_df = pred_df[pred_df['app_id'].isin(ease_ids)]
41
 
42
+ if ease_df.empty:
43
+ res = cbf_model(pred_df=pred_df, k=20)['app_id'].tolist()
44
+ else:
45
+ res_cbf = cbf_model(pred_df=pred_df, k=100)
46
+ res_ease = ease_model(pred_df=ease_df, k=100)
47
+ res = combine_hybrid_result(res_ease, res_cbf)
48
 
49
  # st.write(res)
50
  # st.write("Result of EASE:")
 
60
 
61
  if type(res) == ValueError:
62
  st.error("Recommendation failed. Please select with at least 3 games title.")
63
+
64
  return
65
  else:
66
  st.session_state['rs'] = res
67
 
68
+ try:
69
+ if len(st.session_state['rs']) >= 1:
70
+ st.success(f"Go to result page to view top {len(st.session_state['rs'])} recommendations.")
71
+ else:
72
+ st.error("Recommendation failed. Please reload the session.")
73
+ except:
74
+ st.error("There is some error in recommendation process. Please restart the session.")
75
 
76
  # st.write(res)
77
 
 
159
  def about_page():
160
  st.header("Development")
161
  """
162
+ Cek [repositori](https://huggingface.co/spaces/deppfellow/steam-recsys/tree/main) untuk informasi, source code, dan metode yang digunakan. Jangan ragu Jika anda memiliki pertanyaan, terbuka melalui media sosial di bawah:
 
 
163
  - Discord: deppfellow
164
  - Email : raid.rafif@mail.ugm.ac.id
165
  """
contentBased_model.py CHANGED
@@ -120,8 +120,8 @@ class KnnCBF:
120
  def cbf_model(pred_df, k=10):
121
  # items = pd.read_csv("data/games_attributes.csv")
122
  items = pd.read_csv("data/all_games_attributes.csv")
123
-
124
  cbf = KnnCBF(items)
125
  res = cbf.predict_active(pred_df=pred_df, k=k)
126
-
127
  return res
 
120
  def cbf_model(pred_df, k=10):
121
  # items = pd.read_csv("data/games_attributes.csv")
122
  items = pd.read_csv("data/all_games_attributes.csv")
123
+
124
  cbf = KnnCBF(items)
125
  res = cbf.predict_active(pred_df=pred_df, k=k)
126
+
127
  return res
easeBased_model.py CHANGED
@@ -120,7 +120,11 @@ def ease_model(pred_df, k=10):
120
  train = pd.read_csv("data/recs.csv")
121
 
122
  ease = EASE(train)
123
- res = ease.predict_active(pred_df=pred_df, weight_mx=ease_B, k=k)
 
 
 
 
124
 
125
  return res
126
 
 
120
  train = pd.read_csv("data/recs.csv")
121
 
122
  ease = EASE(train)
123
+
124
+ try:
125
+ res = ease.predict_active(pred_df=pred_df, weight_mx=ease_B, k=k)
126
+ except:
127
+ return
128
 
129
  return res
130
 
func.py CHANGED
@@ -51,17 +51,22 @@ def generate_res_gamebox(ids):
51
  if resp.status_code == 200:
52
  with st.container():
53
  st.image(BytesIO(resp.content))
54
- st.caption(data_ids[id])
 
 
55
 
56
  st.divider()
57
 
58
  def combine_hybrid_result(res_ease, res_cbf):
59
- df = pd.concat([res_ease, res_cbf], axis=0)
60
- res_final = df.groupby("app_id").sum().sort_values(["predicted_score"], ascending=False)
61
-
62
- predictions = res_final.head(10)
 
 
63
 
64
- return predictions.index.tolist()
 
65
 
66
  # for title in titles_list:
67
  # # url = f"https://store.steampowered.com/app/"
 
51
  if resp.status_code == 200:
52
  with st.container():
53
  st.image(BytesIO(resp.content))
54
+ # st.caption(data_ids[id])
55
+ st.caption(f"[{data_ids[id]}]({url_page})")
56
+
57
 
58
  st.divider()
59
 
60
  def combine_hybrid_result(res_ease, res_cbf):
61
+ try:
62
+ df = pd.concat([res_ease, res_cbf], axis=0)
63
+
64
+ res_final = df.groupby("app_id").sum().sort_values(["predicted_score"], ascending=False)
65
+
66
+ return res_final.head(10).index.tolist()
67
 
68
+ except:
69
+ st.error("Recommendation failed. Please select with at least 3 games title.")
70
 
71
  # for title in titles_list:
72
  # # url = f"https://store.steampowered.com/app/"