rynmurdock commited on
Commit
3baffd0
·
1 Parent(s): 65cfda3
Files changed (1) hide show
  1. app.py +60 -57
app.py CHANGED
@@ -223,63 +223,66 @@ def pluck_img(user_id, user_emb):
223
 
224
  def background_next_image():
225
  global prevs_df
226
- while True:
227
- # only let it get N (maybe 3) ahead of the user
228
- #not_rated_rows = prevs_df[[i[1]['user:rating'] == {' ': ' '} for i in prevs_df.iterrows()]]
229
- rated_rows = prevs_df[[i[1]['user:rating'] != {' ': ' '} for i in prevs_df.iterrows()]]
230
- #while len(rated_rows) < 4:
231
- # not_rated_rows = prevs_df[[i[1]['user:rating'] == {' ': ' '} for i in prevs_df.iterrows()]]
232
- # rated_rows = prevs_df[[i[1]['user:rating'] != {' ': ' '} for i in prevs_df.iterrows()]]
233
- # time.sleep(.01)
234
- # print('all users have 4 or less rows rated')
235
-
236
- user_id_list = set(rated_rows['latest_user_to_rate'].to_list())
237
- for uid in user_id_list:
238
- rated_rows = prevs_df[[i[1]['user:rating'].get(uid, None) is not None for i in prevs_df.iterrows()]]
239
- not_rated_rows = prevs_df[[i[1]['user:rating'].get(uid, None) is None for i in prevs_df.iterrows()]]
240
-
241
- # we need to intersect not_rated_rows from this user's embed > 7. Just add a new column on which user_id spawned the
242
- # media.
243
-
244
- unrated_from_user = not_rated_rows[[i[1]['from_user_id'] == uid for i in not_rated_rows.iterrows()]]
245
- rated_from_user = rated_rows[[i[1]['from_user_id'] == uid for i in rated_rows.iterrows()]]
246
-
247
- # we pop previous ratings if there are > 10
248
- if len(rated_from_user) >= 10:
249
- oldest = rated_from_user.iloc[0]['paths']
250
- prevs_df = prevs_df[prevs_df['paths'] != oldest]
251
- print('popping 10th rated')
252
- # we don't compute more after 10 are in the queue for them
253
- if len(unrated_from_user) >= 10:
254
- print('skipping because >=10 in queue unrated for user')
255
- continue
256
-
257
- if len(rated_from_user) < 4:
258
- continue
259
-
260
- print(uid)
261
- embs, ys = pluck_embs_ys(uid)
262
-
263
- user_emb = get_user_emb(embs, ys)
264
- img, embs = generate(user_emb)
265
- print(img)
266
- if img:
267
- tmp_df = pd.DataFrame(columns=['paths', 'embeddings', 'ips', 'user:rating', 'latest_user_to_rate'])
268
- tmp_df['paths'] = [img]
269
- tmp_df['embeddings'] = [embs]
270
- tmp_df['user:rating'] = [{' ': ' '}]
271
- tmp_df['from_user_id'] = [uid]
272
- prevs_df = pd.concat((prevs_df, tmp_df))
273
- # we can free up storage by deleting the image
274
- if len(prevs_df) > 50:
275
- oldest_path = prevs_df.iloc[6]['paths']
276
- if os.path.isfile(oldest_path):
277
- os.remove(oldest_path)
278
- else:
279
- # If it fails, inform the user.
280
- print("Error: %s file not found" % oldest_path)
281
- # only keep 50 images & embeddings & ips, then remove oldest besides calibrating
282
- prevs_df = pd.concat((prevs_df.iloc[:6], prevs_df.iloc[7:]))
 
 
 
283
 
284
 
285
  def pluck_embs_ys(user_id):
 
223
 
224
  def background_next_image():
225
  global prevs_df
226
+ global is_started
227
+ while not is_started:
228
+ time.time(.3)
229
+
230
+ # only let it get N (maybe 3) ahead of the user
231
+ #not_rated_rows = prevs_df[[i[1]['user:rating'] == {' ': ' '} for i in prevs_df.iterrows()]]
232
+ rated_rows = prevs_df[[i[1]['user:rating'] != {' ': ' '} for i in prevs_df.iterrows()]]
233
+ #while len(rated_rows) < 4:
234
+ # not_rated_rows = prevs_df[[i[1]['user:rating'] == {' ': ' '} for i in prevs_df.iterrows()]]
235
+ # rated_rows = prevs_df[[i[1]['user:rating'] != {' ': ' '} for i in prevs_df.iterrows()]]
236
+ # time.sleep(.01)
237
+ # print('all users have 4 or less rows rated')
238
+
239
+ user_id_list = set(rated_rows['latest_user_to_rate'].to_list())
240
+ for uid in user_id_list:
241
+ rated_rows = prevs_df[[i[1]['user:rating'].get(uid, None) is not None for i in prevs_df.iterrows()]]
242
+ not_rated_rows = prevs_df[[i[1]['user:rating'].get(uid, None) is None for i in prevs_df.iterrows()]]
243
+
244
+ # we need to intersect not_rated_rows from this user's embed > 7. Just add a new column on which user_id spawned the
245
+ # media.
246
+
247
+ unrated_from_user = not_rated_rows[[i[1]['from_user_id'] == uid for i in not_rated_rows.iterrows()]]
248
+ rated_from_user = rated_rows[[i[1]['from_user_id'] == uid for i in rated_rows.iterrows()]]
249
+
250
+ # we pop previous ratings if there are > 10
251
+ if len(rated_from_user) >= 10:
252
+ oldest = rated_from_user.iloc[0]['paths']
253
+ prevs_df = prevs_df[prevs_df['paths'] != oldest]
254
+ print('popping 10th rated')
255
+ # we don't compute more after 10 are in the queue for them
256
+ if len(unrated_from_user) >= 10:
257
+ print('skipping because >=10 in queue unrated for user')
258
+ continue
259
+
260
+ if len(rated_from_user) < 4:
261
+ continue
262
+
263
+ print(uid)
264
+ embs, ys = pluck_embs_ys(uid)
265
+
266
+ user_emb = get_user_emb(embs, ys)
267
+ img, embs = generate(user_emb)
268
+ print(img)
269
+ if img:
270
+ tmp_df = pd.DataFrame(columns=['paths', 'embeddings', 'ips', 'user:rating', 'latest_user_to_rate'])
271
+ tmp_df['paths'] = [img]
272
+ tmp_df['embeddings'] = [embs]
273
+ tmp_df['user:rating'] = [{' ': ' '}]
274
+ tmp_df['from_user_id'] = [uid]
275
+ prevs_df = pd.concat((prevs_df, tmp_df))
276
+ # we can free up storage by deleting the image
277
+ if len(prevs_df) > 50:
278
+ oldest_path = prevs_df.iloc[6]['paths']
279
+ if os.path.isfile(oldest_path):
280
+ os.remove(oldest_path)
281
+ else:
282
+ # If it fails, inform the user.
283
+ print("Error: %s file not found" % oldest_path)
284
+ # only keep 50 images & embeddings & ips, then remove oldest besides calibrating
285
+ prevs_df = pd.concat((prevs_df.iloc[:6], prevs_df.iloc[7:]))
286
 
287
 
288
  def pluck_embs_ys(user_id):