Spaces:
Runtime error
Runtime error
rynmurdock
commited on
Commit
•
2395d0a
1
Parent(s):
4414403
seems generate may be blocking? unclear
Browse files- __pycache__/safety_checker_improved.cpython-310.pyc +0 -0
- app.py +60 -54
__pycache__/safety_checker_improved.cpython-310.pyc
ADDED
Binary file (1.38 kB). View file
|
|
app.py
CHANGED
@@ -25,7 +25,9 @@ from sklearn.svm import SVC
|
|
25 |
from sklearn.inspection import permutation_importance
|
26 |
from sklearn import preprocessing
|
27 |
import pandas as pd
|
28 |
-
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
|
|
29 |
|
30 |
import random
|
31 |
import time
|
@@ -223,57 +225,58 @@ def pluck_img(user_id, user_emb):
|
|
223 |
|
224 |
def background_next_image():
|
225 |
global prevs_df
|
226 |
-
|
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 |
-
from_user = prevs_df[[i[1]['from_user_id'] == uid for i in prevs_df.iterrows()]]
|
245 |
-
if len(from_user) >= 10:
|
246 |
-
oldest = from_user.iloc[-1]['paths']
|
247 |
-
print(f'User has {len(from_user)} rows. Popping oldest: {oldest}')
|
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')
|
252 |
-
continue
|
253 |
-
|
254 |
-
print(uid)
|
255 |
-
embs, ys = pluck_embs_ys(uid)
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
|
279 |
def pluck_embs_ys(user_id):
|
@@ -475,9 +478,12 @@ Explore the latent space without text prompts based on your preferences. Learn m
|
|
475 |
log = logging.getLogger('log_here')
|
476 |
log.setLevel(logging.ERROR)
|
477 |
|
478 |
-
scheduler = BackgroundScheduler()
|
479 |
-
scheduler.add_job(func=background_next_image, trigger="interval", seconds=.1)
|
480 |
-
scheduler.start()
|
|
|
|
|
|
|
481 |
|
482 |
def encode_space(x):
|
483 |
im_emb, _ = pipe.encode_image(
|
|
|
25 |
from sklearn.inspection import permutation_importance
|
26 |
from sklearn import preprocessing
|
27 |
import pandas as pd
|
28 |
+
#from apscheduler.schedulers.background import BackgroundScheduler
|
29 |
+
import sched
|
30 |
+
import threading
|
31 |
|
32 |
import random
|
33 |
import time
|
|
|
225 |
|
226 |
def background_next_image():
|
227 |
global prevs_df
|
228 |
+
while True:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from_user = prevs_df[[i[1]['from_user_id'] == uid for i in prevs_df.iterrows()]]
|
248 |
+
if len(from_user) >= 10:
|
249 |
+
oldest = from_user.iloc[-1]['paths']
|
250 |
+
print(f'User has {len(from_user)} rows. Popping oldest: {oldest}')
|
251 |
+
prevs_df = prevs_df[prevs_df['paths'] != oldest]
|
252 |
+
|
253 |
+
if len(rated_rows) < 4:
|
254 |
+
print(f'latest user {uid} has < 4 rows') # or > 7 unrated rows')
|
255 |
+
continue
|
256 |
+
|
257 |
+
print(uid)
|
258 |
+
embs, ys = pluck_embs_ys(uid)
|
259 |
+
|
260 |
+
user_emb = get_user_emb(embs, ys)
|
261 |
+
img, embs = generate(user_emb)
|
262 |
+
print(img)
|
263 |
+
if img:
|
264 |
+
tmp_df = pd.DataFrame(columns=['paths', 'embeddings', 'ips', 'user:rating', 'latest_user_to_rate'])
|
265 |
+
tmp_df['paths'] = [img]
|
266 |
+
tmp_df['embeddings'] = [embs]
|
267 |
+
tmp_df['user:rating'] = [{' ': ' '}]
|
268 |
+
tmp_df['from_user_id'] = [uid]
|
269 |
+
prevs_df = pd.concat((prevs_df, tmp_df))
|
270 |
+
# we can free up storage by deleting the image
|
271 |
+
if len(prevs_df) > 50:
|
272 |
+
oldest_path = prevs_df.iloc[6]['paths']
|
273 |
+
if os.path.isfile(oldest_path):
|
274 |
+
os.remove(oldest_path)
|
275 |
+
else:
|
276 |
+
# If it fails, inform the user.
|
277 |
+
print("Error: %s file not found" % oldest_path)
|
278 |
+
# only keep 50 images & embeddings & ips, then remove oldest besides calibrating
|
279 |
+
prevs_df = pd.concat((prevs_df.iloc[:6], prevs_df.iloc[7:]))
|
280 |
|
281 |
|
282 |
def pluck_embs_ys(user_id):
|
|
|
478 |
log = logging.getLogger('log_here')
|
479 |
log.setLevel(logging.ERROR)
|
480 |
|
481 |
+
#scheduler = BackgroundScheduler()
|
482 |
+
#scheduler.add_job(func=background_next_image, trigger="interval", seconds=.1)
|
483 |
+
#scheduler.start()
|
484 |
+
|
485 |
+
thread = threading.Thread(target=background_next_image,)
|
486 |
+
thread.start()
|
487 |
|
488 |
def encode_space(x):
|
489 |
im_emb, _ = pipe.encode_image(
|