rynmurdock commited on
Commit
b4f2949
1 Parent(s): 3a1c1bf

30 length df; remove with most dislikes.

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -269,17 +269,23 @@ def background_next_image():
269
  tmp_df['user:rating'] = [{' ': ' '}]
270
  tmp_df['from_user_id'] = [uid]
271
  prevs_df = pd.concat((prevs_df, tmp_df))
 
272
  # we can free up storage by deleting the image
273
- if len(prevs_df) > 50:
274
- oldest_path = prevs_df.iloc[6]['paths']
275
- if os.path.isfile(oldest_path):
276
- os.remove(oldest_path)
 
 
 
 
277
  else:
278
  # If it fails, inform the user.
279
- print("Error: %s file not found" % oldest_path)
280
- # only keep 50 images & embeddings & ips, then remove oldest besides calibrating
281
- prevs_df = pd.concat((prevs_df.iloc[:6], prevs_df.iloc[7:]))
282
-
 
283
 
284
  def pluck_embs_ys(user_id):
285
  rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, None) != None for i in prevs_df.iterrows()]]
 
269
  tmp_df['user:rating'] = [{' ': ' '}]
270
  tmp_df['from_user_id'] = [uid]
271
  prevs_df = pd.concat((prevs_df, tmp_df))
272
+
273
  # we can free up storage by deleting the image
274
+ if len(prevs_df) > 30:
275
+ cands = prevs_df.iloc[6:]
276
+ cands['sum_bad_ratings'] = [sum([int(t==0) for t in i.values()]) for i in cands['user:rating']]
277
+ worst_row = cands.loc[cands['sum_bad_ratings']==cands['sum_bad_ratings'].max()].iloc[0]
278
+ worst_path = worst_row['paths']
279
+ print('Removing worst row:', worst_row, 'from prevs_df of len', len(prevs_df))
280
+ if os.path.isfile(worst_path):
281
+ os.remove(worst_path)
282
  else:
283
  # If it fails, inform the user.
284
+ print("Error: %s file not found" % worst_path)
285
+
286
+ # only keep x images & embeddings & ips, then remove the most often disliked besides calibrating
287
+ prevs_df = prevs_df[prevs_df['paths'] != worst_path]
288
+ print('prevs_df is now length:', len(prevs_df))
289
 
290
  def pluck_embs_ys(user_id):
291
  rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, None) != None for i in prevs_df.iterrows()]]