Spaces:
Runtime error
Runtime error
Commit
·
3c0ab73
1
Parent(s):
22185c3
pop > 10 rated and stop queuing > 10 queued per user
Browse files
app.py
CHANGED
@@ -126,11 +126,10 @@ pipe.to(device=DEVICE)
|
|
126 |
#pipe.unet = torch.compile(pipe.unet)
|
127 |
#pipe.vae = torch.compile(pipe.vae)
|
128 |
|
129 |
-
@spaces.GPU(duration=
|
130 |
def generate_gpu(in_im_embs):
|
131 |
print('start gen')
|
132 |
in_im_embs = in_im_embs.to('cuda').unsqueeze(0).unsqueeze(0)
|
133 |
-
|
134 |
output = pipe(prompt='', guidance_scale=0, added_cond_kwargs={}, ip_adapter_image_embeds=[in_im_embs], num_inference_steps=STEPS)
|
135 |
print('image is made')
|
136 |
im_emb, _ = pipe.encode_image(
|
@@ -209,7 +208,7 @@ def pluck_img(user_id, user_emb):
|
|
209 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
210 |
while len(not_rated_rows) == 0:
|
211 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
212 |
-
time.sleep(
|
213 |
# TODO optimize this lol
|
214 |
best_sim = -100000
|
215 |
for i in not_rated_rows.iterrows():
|
@@ -241,11 +240,16 @@ def background_next_image():
|
|
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 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
|
|
248 |
prevs_df = prevs_df[prevs_df['paths'] != oldest]
|
|
|
|
|
|
|
249 |
|
250 |
if len(rated_rows) < 4:
|
251 |
print(f'latest user {uid} has < 4 rows') # or > 7 unrated rows')
|
|
|
126 |
#pipe.unet = torch.compile(pipe.unet)
|
127 |
#pipe.vae = torch.compile(pipe.vae)
|
128 |
|
129 |
+
@spaces.GPU(duration=5)
|
130 |
def generate_gpu(in_im_embs):
|
131 |
print('start gen')
|
132 |
in_im_embs = in_im_embs.to('cuda').unsqueeze(0).unsqueeze(0)
|
|
|
133 |
output = pipe(prompt='', guidance_scale=0, added_cond_kwargs={}, ip_adapter_image_embeds=[in_im_embs], num_inference_steps=STEPS)
|
134 |
print('image is made')
|
135 |
im_emb, _ = pipe.encode_image(
|
|
|
208 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
209 |
while len(not_rated_rows) == 0:
|
210 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
211 |
+
time.sleep(.001)
|
212 |
# TODO optimize this lol
|
213 |
best_sim = -100000
|
214 |
for i in not_rated_rows.iterrows():
|
|
|
240 |
# we need to intersect not_rated_rows from this user's embed > 7. Just add a new column on which user_id spawned the
|
241 |
# media.
|
242 |
|
243 |
+
unrated_from_user = not_rated_rows[[i[1]['from_user_id'] == uid for i in not_rated_rows.iterrows()]]
|
244 |
+
rated_from_user = rated_rows[[i[1]['from_user_id'] == uid for i in rated_rows.iterrows()]]
|
245 |
+
|
246 |
+
# we pop previous ratings if there are > 10
|
247 |
+
if len(rated_from_user) >= 10:
|
248 |
+
oldest = unrated_from_user.iloc[-1]['paths']
|
249 |
prevs_df = prevs_df[prevs_df['paths'] != oldest]
|
250 |
+
# we don't compute more after 10 are in the queue for them
|
251 |
+
if len(unrated_from_user) >= 10:
|
252 |
+
continue
|
253 |
|
254 |
if len(rated_rows) < 4:
|
255 |
print(f'latest user {uid} has < 4 rows') # or > 7 unrated rows')
|