rynmurdock commited on
Commit
350784c
1 Parent(s): d6f0e0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -32
app.py CHANGED
@@ -246,38 +246,40 @@ def background_next_image():
246
  rated_rows = prevs_df[[i[1]['user:rating'] != {' ': ' '} for i in prevs_df.iterrows()]]
247
  time.sleep(.01)
248
  print('all users have 8 or more rows left to rate')
249
-
250
- latest_user_id = rated_rows.iloc[-1]['latest_user_to_rate']
251
- rated_rows = prevs_df[[i[1]['user:rating'].get(latest_user_id, None) is not None for i in prevs_df.iterrows()]]
252
- not_rated_rows = prevs_df[[i[1]['user:rating'].get(latest_user_id, None) is None for i in prevs_df.iterrows()]]
253
- while len(rated_rows) < 4 or len(not_rated_rows) > 10:
254
- rated_rows = prevs_df[[i[1]['user:rating'].get(latest_user_id, None) is not None for i in prevs_df.iterrows()]]
255
- not_rated_rows = prevs_df[[i[1]['user:rating'].get(latest_user_id, None) is None for i in prevs_df.iterrows()]]
256
- time.sleep(.01)
257
- print('latest user has < 4 rated_rows')
258
-
259
- print(latest_user_id)
260
- embs, ys = pluck_embs_ys(latest_user_id)
261
-
262
- user_emb = get_user_emb(embs, ys)
263
- img, embs = generate(user_emb)
264
- print(img)
265
- if img:
266
- tmp_df = pd.DataFrame(columns=['paths', 'embeddings', 'ips', 'user:rating', 'latest_user_to_rate'])
267
- tmp_df['paths'] = [img]
268
- tmp_df['embeddings'] = [embs]
269
- tmp_df['user:rating'] = [{' ': ' '}]
270
- prevs_df = pd.concat((prevs_df, tmp_df))
271
- # we can free up storage by deleting the image
272
- if len(prevs_df) > 50:
273
- oldest_path = prevs_df.iloc[6]['paths']
274
- if os.path.isfile(oldest_path):
275
- os.remove(oldest_path)
276
- else:
277
- # If it fails, inform the user.
278
- print("Error: %s file not found" % oldest_path)
279
- # only keep 50 images & embeddings & ips, then remove oldest besides calibrating
280
- prevs_df = pd.concat((prevs_df.iloc[:6], prevs_df.iloc[7:]))
 
 
281
 
282
 
283
  def pluck_embs_ys(user_id):
 
246
  rated_rows = prevs_df[[i[1]['user:rating'] != {' ': ' '} for i in prevs_df.iterrows()]]
247
  time.sleep(.01)
248
  print('all users have 8 or more rows left to rate')
249
+
250
+
251
+ # TODO set this to run such that it's on a per-user-in-the-db basis; we only want to be ~5 ahead of every user in the db
252
+ user_id_list = set(rated_rows['latest_user_to_rate'].to_list())
253
+
254
+ for uid in user_id_list:
255
+ rated_rows = prevs_df[[i[1]['user:rating'].get(uid, None) is not None for i in prevs_df.iterrows()]]
256
+ not_rated_rows = prevs_df[[i[1]['user:rating'].get(uid, None) is None for i in prevs_df.iterrows()]]
257
+ if len(rated_rows) < 4 or len(not_rated_rows) > 7:
258
+ print(f'latest user {uid} has < 4 rows or > 7 unrated rows')
259
+ continue
260
+
261
+ print(uid)
262
+ embs, ys = pluck_embs_ys(uid)
263
+
264
+ user_emb = get_user_emb(embs, ys)
265
+ img, embs = generate(user_emb)
266
+ print(img)
267
+ if img:
268
+ tmp_df = pd.DataFrame(columns=['paths', 'embeddings', 'ips', 'user:rating', 'latest_user_to_rate'])
269
+ tmp_df['paths'] = [img]
270
+ tmp_df['embeddings'] = [embs]
271
+ tmp_df['user:rating'] = [{' ': ' '}]
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):