Spaces:
Sleeping
Sleeping
rynmurdock
commited on
Commit
•
350784c
1
Parent(s):
d6f0e0b
Update app.py
Browse files
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 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
if
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
|
|
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):
|