dvruette Krebzonide commited on
Commit
3d99c27
β€’
1 Parent(s): e6dc824

show previous seed used (#5)

Browse files

- show previous seed used (7fe459f90cba7c089af300c45433c7905df6378a)


Co-authored-by: Krebzonide <[email protected]>

Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import functools
 
2
 
3
  import gradio as gr
4
  import torch
@@ -95,7 +96,8 @@ def generate_fn(
95
  ):
96
  try:
97
  if seed < 0:
98
- seed = None
 
99
 
100
  max_feedback_imgs = max(0, int(max_feedback_imgs))
101
  total_images = (len(liked) if liked else 0) + (len(disliked) if disliked else 0)
@@ -141,7 +143,7 @@ def generate_fn(
141
  if 'out of memory' in str(err):
142
  generator.reload()
143
  raise
144
- return [(img, f"Image {i+1}") for i, img in enumerate(images)], images
145
  except Exception as err:
146
  raise gr.Error(str(err))
147
 
@@ -164,6 +166,8 @@ def remove_img_from_list(event: gr.SelectData, imgs):
164
  imgs.pop(event.index)
165
  return imgs, imgs
166
 
 
 
167
 
168
  with gr.Blocks(css=css) as demo:
169
 
@@ -225,6 +229,9 @@ with gr.Blocks(css=css) as demo:
225
  dislike_btn = gr.Button(f"πŸ‘Ž Image {i+1}", elem_classes="btn-red")
226
  dislike_btns.append(dislike_btn)
227
 
 
 
 
228
  generate_params = [
229
  feedback_enabled,
230
  max_feedback_imgs,
@@ -242,8 +249,9 @@ with gr.Blocks(css=css) as demo:
242
  batch_size,
243
  seed,
244
  ]
245
- submit_btn.click(generate_fn, generate_params, [gallery, curr_imgs], queue=True)
246
-
 
247
  for i, like_btn in enumerate(like_btns):
248
  like_btn.click(functools.partial(add_img_from_list, i), [curr_imgs, liked_imgs], [like_gallery, liked_imgs], queue=False)
249
  for i, dislike_btn in enumerate(dislike_btns):
 
1
  import functools
2
+ import random
3
 
4
  import gradio as gr
5
  import torch
 
96
  ):
97
  try:
98
  if seed < 0:
99
+ seed = random.randint(1,9999999999999999) #16 digits is an arbitrary limit
100
+ print("seed: ", seed)
101
 
102
  max_feedback_imgs = max(0, int(max_feedback_imgs))
103
  total_images = (len(liked) if liked else 0) + (len(disliked) if disliked else 0)
 
143
  if 'out of memory' in str(err):
144
  generator.reload()
145
  raise
146
+ return [(img, f"Image {i+1}") for i, img in enumerate(images)], images, seed
147
  except Exception as err:
148
  raise gr.Error(str(err))
149
 
 
166
  imgs.pop(event.index)
167
  return imgs, imgs
168
 
169
+ def duplicate_seed_value(seed): #I don't like the progress bar showing on the previous seed box and this is how I hide it
170
+ return seed
171
 
172
  with gr.Blocks(css=css) as demo:
173
 
 
229
  dislike_btn = gr.Button(f"πŸ‘Ž Image {i+1}", elem_classes="btn-red")
230
  dislike_btns.append(dislike_btn)
231
 
232
+ prev_seed = gr.Number(-1, label="Previous seed", interactive=False)
233
+ prev_seed_hid = gr.Number(-1, visible=False)
234
+
235
  generate_params = [
236
  feedback_enabled,
237
  max_feedback_imgs,
 
249
  batch_size,
250
  seed,
251
  ]
252
+ submit_btn.click(generate_fn, generate_params, [gallery, curr_imgs, prev_seed_hid], queue=True)
253
+ prev_seed_hid.change(duplicate_seed_value, prev_seed_hid, prev_seed, queue=False)
254
+
255
  for i, like_btn in enumerate(like_btns):
256
  like_btn.click(functools.partial(add_img_from_list, i), [curr_imgs, liked_imgs], [like_gallery, liked_imgs], queue=False)
257
  for i, dislike_btn in enumerate(dislike_btns):