Spaces:
Runtime error
Runtime error
Commit
Β·
299cc79
1
Parent(s):
ef6f6bd
interface
Browse files- .gitignore +2 -1
- README.md +1 -0
- app.py +12 -14
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
__pycache__*
|
|
|
|
|
|
| 1 |
+
__pycache__*
|
| 2 |
+
.gradio/
|
README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
license: mit
|
| 3 |
title: The Other Tiger
|
| 4 |
sdk: gradio
|
|
|
|
| 5 |
emoji: π
|
| 6 |
colorFrom: blue
|
| 7 |
colorTo: purple
|
|
|
|
| 2 |
license: mit
|
| 3 |
title: The Other Tiger
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 5.31.0
|
| 6 |
emoji: π
|
| 7 |
colorFrom: blue
|
| 8 |
colorTo: purple
|
app.py
CHANGED
|
@@ -176,13 +176,11 @@ def background_next_image():
|
|
| 176 |
|
| 177 |
def pluck_img(user_id):
|
| 178 |
rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, None) is not None for i in prevs_df.iterrows()]]
|
| 179 |
-
print(rated_rows)
|
| 180 |
ems = rated_rows['embeddings'].to_list()
|
| 181 |
ys = [i[user_id][0] for i in rated_rows['user:rating'].to_list()]
|
| 182 |
user_emb = get_user_emb(ems, ys)
|
| 183 |
|
| 184 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
| 185 |
-
print(not_rated_rows)
|
| 186 |
while len(not_rated_rows) == 0:
|
| 187 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
| 188 |
time.sleep(.1)
|
|
@@ -212,11 +210,10 @@ def next_image(calibrate_prompts, user_id):
|
|
| 212 |
if len(m_calibrate) - len(calibrate_prompts) < 5:
|
| 213 |
cal_video = calibrate_prompts.pop(random.randint(0, len(calibrate_prompts)-1))
|
| 214 |
image = prevs_df[prevs_df['paths'] == cal_video]['paths'].to_list()[0]
|
| 215 |
-
return image, calibrate_prompts
|
| 216 |
# we switch to just getting media by similarity.
|
| 217 |
else:
|
| 218 |
image = pluck_img(user_id)
|
| 219 |
-
|
| 220 |
|
| 221 |
|
| 222 |
|
|
@@ -269,16 +266,13 @@ def choose(img, choice, calibrate_prompts, user_id, request: gr.Request):
|
|
| 269 |
prevs_df.loc[row_mask, 'latest_user_to_rate'] = [user_id]
|
| 270 |
else:
|
| 271 |
print('Image apparently removed', img)
|
| 272 |
-
breakpoint()
|
| 273 |
img, calibrate_prompts = next_image(calibrate_prompts, user_id)
|
| 274 |
return img, calibrate_prompts
|
| 275 |
|
| 276 |
-
css = '''.gradio-container{
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
text-align: center
|
| 281 |
-
}
|
| 282 |
#description{text-align: center}
|
| 283 |
#description h1, #description h3{display: block}
|
| 284 |
#description p{margin-top: 0}
|
|
@@ -330,11 +324,13 @@ document.body.addEventListener('click', function(event) {
|
|
| 330 |
</script>
|
| 331 |
'''
|
| 332 |
|
| 333 |
-
with gr.Blocks(
|
| 334 |
gr.Markdown('''# The Other Tiger
|
| 335 |
### Generative Recommenders for Exporation of Possible Images
|
| 336 |
|
| 337 |
-
Explore the latent space
|
|
|
|
|
|
|
| 338 |
''', elem_id="description")
|
| 339 |
user_id = gr.State()
|
| 340 |
# calibration videos -- this is a misnomer now :D
|
|
@@ -423,7 +419,7 @@ def encode_space(x):
|
|
| 423 |
# NOTE:
|
| 424 |
# media is moved into a random tmp folder so we need to parse filenames carefully.
|
| 425 |
# do not have any cases where a file name is the same or could be `in` another filename
|
| 426 |
-
# you also can't use jpegs lmao
|
| 427 |
|
| 428 |
# prep our calibration videos
|
| 429 |
m_calibrate = glob.glob('image_init/*')
|
|
@@ -436,6 +432,8 @@ for im in m_calibrate:
|
|
| 436 |
tmp_df['embeddings'] = [im_emb.detach().to('cpu')]
|
| 437 |
tmp_df['user:rating'] = [{' ': ' '}]
|
| 438 |
tmp_df['text'] = ['']
|
|
|
|
|
|
|
| 439 |
tmp_df['from_user_id'] = [0]
|
| 440 |
tmp_df['latest_user_to_rate'] = [0]
|
| 441 |
prevs_df = pd.concat((prevs_df, tmp_df))
|
|
|
|
| 176 |
|
| 177 |
def pluck_img(user_id):
|
| 178 |
rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, None) is not None for i in prevs_df.iterrows()]]
|
|
|
|
| 179 |
ems = rated_rows['embeddings'].to_list()
|
| 180 |
ys = [i[user_id][0] for i in rated_rows['user:rating'].to_list()]
|
| 181 |
user_emb = get_user_emb(ems, ys)
|
| 182 |
|
| 183 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
|
|
|
| 184 |
while len(not_rated_rows) == 0:
|
| 185 |
not_rated_rows = prevs_df[[i[1]['user:rating'].get(user_id, 'gone') == 'gone' for i in prevs_df.iterrows()]]
|
| 186 |
time.sleep(.1)
|
|
|
|
| 210 |
if len(m_calibrate) - len(calibrate_prompts) < 5:
|
| 211 |
cal_video = calibrate_prompts.pop(random.randint(0, len(calibrate_prompts)-1))
|
| 212 |
image = prevs_df[prevs_df['paths'] == cal_video]['paths'].to_list()[0]
|
|
|
|
| 213 |
# we switch to just getting media by similarity.
|
| 214 |
else:
|
| 215 |
image = pluck_img(user_id)
|
| 216 |
+
return image, calibrate_prompts
|
| 217 |
|
| 218 |
|
| 219 |
|
|
|
|
| 266 |
prevs_df.loc[row_mask, 'latest_user_to_rate'] = [user_id]
|
| 267 |
else:
|
| 268 |
print('Image apparently removed', img)
|
|
|
|
| 269 |
img, calibrate_prompts = next_image(calibrate_prompts, user_id)
|
| 270 |
return img, calibrate_prompts
|
| 271 |
|
| 272 |
+
css = '''.gradio-container{max-width: 700px !important}
|
| 273 |
+
|
| 274 |
+
#component-0{display: block; text-align: center; margin-top: 0}
|
| 275 |
+
|
|
|
|
|
|
|
| 276 |
#description{text-align: center}
|
| 277 |
#description h1, #description h3{display: block}
|
| 278 |
#description p{margin-top: 0}
|
|
|
|
| 324 |
</script>
|
| 325 |
'''
|
| 326 |
|
| 327 |
+
with gr.Blocks(head=js_head, css=css) as demo:
|
| 328 |
gr.Markdown('''# The Other Tiger
|
| 329 |
### Generative Recommenders for Exporation of Possible Images
|
| 330 |
|
| 331 |
+
Explore the latent space using binary feedback.
|
| 332 |
+
|
| 333 |
+
[rynmurdock.github.io](https://rynmurdock.github.io/)
|
| 334 |
''', elem_id="description")
|
| 335 |
user_id = gr.State()
|
| 336 |
# calibration videos -- this is a misnomer now :D
|
|
|
|
| 419 |
# NOTE:
|
| 420 |
# media is moved into a random tmp folder so we need to parse filenames carefully.
|
| 421 |
# do not have any cases where a file name is the same or could be `in` another filename
|
| 422 |
+
# you also maybe can't use jpegs lmao
|
| 423 |
|
| 424 |
# prep our calibration videos
|
| 425 |
m_calibrate = glob.glob('image_init/*')
|
|
|
|
| 432 |
tmp_df['embeddings'] = [im_emb.detach().to('cpu')]
|
| 433 |
tmp_df['user:rating'] = [{' ': ' '}]
|
| 434 |
tmp_df['text'] = ['']
|
| 435 |
+
|
| 436 |
+
# seems to break things...
|
| 437 |
tmp_df['from_user_id'] = [0]
|
| 438 |
tmp_df['latest_user_to_rate'] = [0]
|
| 439 |
prevs_df = pd.concat((prevs_df, tmp_df))
|