nandovallec commited on
Commit
9cb5f62
1 Parent(s): f3e36b8

Optimization

Browse files
Files changed (2) hide show
  1. app.py +4 -2
  2. recommender.py +14 -8
app.py CHANGED
@@ -9,7 +9,7 @@ import requests
9
  import base64
10
  import json
11
  import sys
12
- from fetchPlaylistTrackUris import *
13
  import re
14
  import asyncio
15
  # import streamlit.components.v1 as components
@@ -20,7 +20,6 @@ import numpy as np
20
  import pandas as pd
21
  import os
22
  from scipy.sparse import vstack
23
- from recommender import *
24
  import huggingface_hub
25
  from huggingface_hub import Repository
26
 
@@ -44,6 +43,9 @@ repo_mat = Repository(
44
  local_dir="data_mat", clone_from=DATASET_REPO_URL_MAT, use_auth_token=HF_TOKEN, repo_type="dataset"
45
  )
46
 
 
 
 
47
  def get_repo_train():
48
  repo_train = Repository(
49
  local_dir="data_train", clone_from=DATASET_REPO_URL_TRAIN, use_auth_token=HF_TOKEN, repo_type="dataset"
 
9
  import base64
10
  import json
11
  import sys
12
+
13
  import re
14
  import asyncio
15
  # import streamlit.components.v1 as components
 
20
  import pandas as pd
21
  import os
22
  from scipy.sparse import vstack
 
23
  import huggingface_hub
24
  from huggingface_hub import Repository
25
 
 
43
  local_dir="data_mat", clone_from=DATASET_REPO_URL_MAT, use_auth_token=HF_TOKEN, repo_type="dataset"
44
  )
45
 
46
+ from fetchPlaylistTrackUris import *
47
+ from recommender import *
48
+
49
  def get_repo_train():
50
  repo_train = Repository(
51
  local_dir="data_train", clone_from=DATASET_REPO_URL_TRAIN, use_auth_token=HF_TOKEN, repo_type="dataset"
recommender.py CHANGED
@@ -5,6 +5,15 @@ import numpy as np
5
  import pandas as pd
6
  from scipy.sparse import vstack
7
 
 
 
 
 
 
 
 
 
 
8
  def add_row_train(df, list_tid):
9
  new_pid_add = df.iloc[-1].name +1
10
  list_tid_add = list_tid
@@ -25,9 +34,9 @@ def inference_row(list_tid, ps_matrix):
25
 
26
 
27
  def get_best_tid(current_list, ps_matrix_row, K=50, MAX_tid=10):
28
- df_ps_train = pd.read_hdf('model/df_ps_train_new.hdf')
29
- df_ps_train_extra = pd.read_hdf('data_train/df_ps_train_extra.hdf')
30
- df_ps_train = pd.concat([df_ps_train,df_ps_train_extra])
31
 
32
  sim_vector, sparse_row = inference_row(current_list, ps_matrix_row)
33
  sim_vector = sim_vector.toarray()[0].tolist()
@@ -76,16 +85,13 @@ def get_best_tid(current_list, ps_matrix_row, K=50, MAX_tid=10):
76
 
77
 
78
  def inference_from_tid(list_tid, K=50, MAX_tid=10):
79
- pickle_path = 'model/giantMatrix_new.pickle'
80
- # pickle_path = 'data/giantMatrix_truth_new.pickle'
81
 
82
- with open(pickle_path, 'rb') as f:
83
- ps_matrix = pickle.load(f)
84
 
85
  with open("data_mat/giantMatrix_extra.pickle",'rb') as f:
86
  ps_matrix_extra = pickle.load(f)
87
 
88
- ps_matrix = vstack((ps_matrix,ps_matrix_extra))
89
 
90
  result, sparse_row = get_best_tid(list_tid, ps_matrix.tocsr(), K, MAX_tid)
91
  ps_matrix_extra = vstack((ps_matrix_extra,sparse_row.todok()))
 
5
  import pandas as pd
6
  from scipy.sparse import vstack
7
 
8
+
9
+ df_ps_train_ori = pd.read_hdf('model/df_ps_train_new.hdf')
10
+ df_ps_train_extra = pd.read_hdf('data_train/df_ps_train_extra.hdf')
11
+ pickle_path = 'model/giantMatrix_new.pickle'
12
+ with open(pickle_path, 'rb') as f:
13
+ ps_matrix_ori = pickle.load(f)
14
+
15
+
16
+
17
  def add_row_train(df, list_tid):
18
  new_pid_add = df.iloc[-1].name +1
19
  list_tid_add = list_tid
 
34
 
35
 
36
  def get_best_tid(current_list, ps_matrix_row, K=50, MAX_tid=10):
37
+
38
+
39
+ df_ps_train = pd.concat([df_ps_train_ori,df_ps_train_extra])
40
 
41
  sim_vector, sparse_row = inference_row(current_list, ps_matrix_row)
42
  sim_vector = sim_vector.toarray()[0].tolist()
 
85
 
86
 
87
  def inference_from_tid(list_tid, K=50, MAX_tid=10):
 
 
88
 
89
+ # pickle_path = 'data/giantMatrix_truth_new.pickle'
 
90
 
91
  with open("data_mat/giantMatrix_extra.pickle",'rb') as f:
92
  ps_matrix_extra = pickle.load(f)
93
 
94
+ ps_matrix = vstack((ps_matrix_ori,ps_matrix_extra))
95
 
96
  result, sparse_row = get_best_tid(list_tid, ps_matrix.tocsr(), K, MAX_tid)
97
  ps_matrix_extra = vstack((ps_matrix_extra,sparse_row.todok()))