Spaces:
Runtime error
Runtime error
Update app_utils.py
Browse files- app_utils.py +80 -44
app_utils.py
CHANGED
@@ -103,52 +103,88 @@ def wall_of_checkboxes(labels, max_width=10):
|
|
103 |
checkboxes.append(st.empty())
|
104 |
return checkboxes
|
105 |
|
106 |
-
def
|
107 |
-
genres_output = dict()
|
108 |
legit_genres_formatted = [lg.replace('-', '').replace(' ', '') for lg in legit_genres]
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
if
|
124 |
-
|
|
|
|
|
|
|
|
|
125 |
best_match = legit_glabel
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
def get_all_playlists_uris_from_users(sp, user_ids):
|
154 |
all_uris = []
|
|
|
103 |
checkboxes.append(st.empty())
|
104 |
return checkboxes
|
105 |
|
106 |
+
def find_legit_genre(glabel, legit_genres, verbose=False):
|
|
|
107 |
legit_genres_formatted = [lg.replace('-', '').replace(' ', '') for lg in legit_genres]
|
108 |
+
glabel_formatted = glabel.replace(' ', '').replace('-', '')
|
109 |
+
if verbose: print('\n', glabel)
|
110 |
+
best_match = None
|
111 |
+
best_match_score = 0
|
112 |
+
for legit_glabel, legit_glabel_formatted in zip(legit_genres, legit_genres_formatted):
|
113 |
+
if 'jazz' in glabel_formatted:
|
114 |
+
best_match = 'jazz'
|
115 |
+
if verbose: print('\t', 'pop')
|
116 |
+
break
|
117 |
+
if 'ukpop' in glabel_formatted:
|
118 |
+
best_match = 'pop'
|
119 |
+
if verbose: print('\t', 'pop')
|
120 |
+
break
|
121 |
+
if legit_glabel_formatted == glabel_formatted:
|
122 |
+
if verbose: print('\t', legit_glabel_formatted)
|
123 |
+
best_match = legit_glabel
|
124 |
+
break
|
125 |
+
elif glabel_formatted in legit_glabel_formatted:
|
126 |
+
if verbose: print('\t', legit_glabel_formatted)
|
127 |
+
if len(glabel_formatted) > best_match_score:
|
128 |
best_match = legit_glabel
|
129 |
+
best_match_score = len(glabel_formatted)
|
130 |
+
elif legit_glabel_formatted in glabel_formatted:
|
131 |
+
if verbose: print('\t', legit_glabel_formatted)
|
132 |
+
if len(legit_glabel_formatted) > best_match_score:
|
133 |
+
best_match = legit_glabel
|
134 |
+
best_match_score = len(legit_glabel_formatted)
|
135 |
+
|
136 |
+
if best_match is None:
|
137 |
+
return "unknown"
|
138 |
+
else:
|
139 |
+
return best_match
|
140 |
+
|
141 |
+
|
142 |
+
# def aggregate_genres(genres, legit_genres, verbose=False):
|
143 |
+
# genres_output = dict()
|
144 |
+
# legit_genres_formatted = [lg.replace('-', '').replace(' ', '') for lg in legit_genres]
|
145 |
+
# for glabel in genres.keys():
|
146 |
+
# if verbose: print('\n', glabel)
|
147 |
+
# glabel_formatted = glabel.replace(' ', '').replace('-', '')
|
148 |
+
# best_match = None
|
149 |
+
# best_match_score = 0
|
150 |
+
# for legit_glabel, legit_glabel_formatted in zip(legit_genres, legit_genres_formatted):
|
151 |
+
# if 'jazz' in glabel_formatted:
|
152 |
+
# best_match = 'jazz'
|
153 |
+
# if verbose: print('\t', 'pop')
|
154 |
+
# break
|
155 |
+
# if 'ukpop' in glabel_formatted:
|
156 |
+
# best_match = 'pop'
|
157 |
+
# if verbose: print('\t', 'pop')
|
158 |
+
# break
|
159 |
+
# if legit_glabel_formatted == glabel_formatted:
|
160 |
+
# if verbose: print('\t', legit_glabel_formatted)
|
161 |
+
# best_match = legit_glabel
|
162 |
+
# break
|
163 |
+
# elif glabel_formatted in legit_glabel_formatted:
|
164 |
+
# if verbose: print('\t', legit_glabel_formatted)
|
165 |
+
# if len(glabel_formatted) > best_match_score:
|
166 |
+
# best_match = legit_glabel
|
167 |
+
# best_match_score = len(glabel_formatted)
|
168 |
+
# elif legit_glabel_formatted in glabel_formatted:
|
169 |
+
# if verbose: print('\t', legit_glabel_formatted)
|
170 |
+
# if len(legit_glabel_formatted) > best_match_score:
|
171 |
+
# best_match = legit_glabel
|
172 |
+
# best_match_score = len(legit_glabel_formatted)
|
173 |
+
#
|
174 |
+
# if best_match is not None:
|
175 |
+
# if verbose: print('\t', '-->', best_match)
|
176 |
+
# if best_match in genres_output.keys():
|
177 |
+
# genres_output[best_match] += genres[glabel]
|
178 |
+
# else:
|
179 |
+
# genres_output[best_match] = genres[glabel]
|
180 |
+
# else:
|
181 |
+
# if "unknown" in genres_output.keys():
|
182 |
+
# genres_output["unknown"] += genres[glabel]
|
183 |
+
# else:
|
184 |
+
# genres_output["unknown"] = genres[glabel]
|
185 |
+
# for k in genres_output.keys():
|
186 |
+
# genres_output[k] = sorted(set(genres_output[k]))
|
187 |
+
# return genres_output
|
188 |
|
189 |
def get_all_playlists_uris_from_users(sp, user_ids):
|
190 |
all_uris = []
|