skytnt commited on
Commit
a91e1f6
1 Parent(s): 48c1b5c

add examples

Browse files
Files changed (7) hide show
  1. app.py +13 -4
  2. examples/01.png +0 -0
  3. examples/02.png +0 -0
  4. examples/03.png +0 -0
  5. examples/04.png +0 -0
  6. examples/05.png +0 -0
  7. examples/06.png +0 -0
app.py CHANGED
@@ -226,11 +226,17 @@ class Model:
226
  video.close()
227
 
228
 
 
 
 
 
 
 
229
  def gen_fn(method, seed, psi):
230
  z = RandomState(int(seed) + 2 ** 31).randn(1, 512) if method == 1 else np.random.randn(1, 512)
231
  w = model.get_w(z.astype(dtype=np.float32), psi)
232
  img_out = model.get_img(w)
233
- return img_out, w, img_out
234
 
235
 
236
  def encode_img_fn(img):
@@ -241,7 +247,7 @@ def encode_img_fn(img):
241
  return "failed to detect waifu", None, None, None, None
242
  w = model.encode_img(imgs[0])
243
  img_out = model.get_img(w)
244
- return "success", imgs[0], img_out, w, img_out
245
 
246
 
247
  def gen_video_fn(w1, w2, frame):
@@ -281,6 +287,8 @@ if __name__ == '__main__':
281
  with gr.Column():
282
  gr.Markdown("you'd better upload a standing full-body image")
283
  encode_img_input = gr.Image(label="input image")
 
 
284
  with gr.Group():
285
  encode_img_submit = gr.Button("Run", variant="primary")
286
  with gr.Column():
@@ -302,7 +310,7 @@ if __name__ == '__main__':
302
  choices=["current generated image",
303
  "current encoded image"], type="index")
304
  with gr.Group():
305
- select_img1_button = gr.Button("select", variant="primary")
306
  select_img1_output_img = gr.Image(label="selected image 1")
307
  select_img1_output_w = gr.Variable()
308
  with gr.Column():
@@ -311,7 +319,7 @@ if __name__ == '__main__':
311
  choices=["current generated image",
312
  "current encoded image"], type="index")
313
  with gr.Group():
314
- select_img2_button = gr.Button("select", variant="primary")
315
  select_img2_output_img = gr.Image(label="selected image 2")
316
  select_img2_output_w = gr.Variable()
317
  generate_video_frame = gr.Slider(minimum=10, maximum=30, step=1, label="frame", value=15)
@@ -324,6 +332,7 @@ if __name__ == '__main__':
324
  encode_img_submit.click(encode_img_fn, [encode_img_input],
325
  [encode_img_output1, encode_img_output2, encode_img_output3, select_img_input_w2,
326
  select_img_input_img2])
 
327
  select_img1_button.click(lambda i, img1, img2, w1, w2: (img1, w1) if i == 0 else (img2, w2),
328
  [select_img1_dropdown, select_img_input_img1, select_img_input_img2,
329
  select_img_input_w1, select_img_input_w2],
 
226
  video.close()
227
 
228
 
229
+ def get_thumbnail(img):
230
+ img_new = np.full((256, 384, 3), 200, dtype=np.uint8)
231
+ img_new[:, 128:256] = transform.resize(img, (256, 128), preserve_range=True)
232
+ return img_new
233
+
234
+
235
  def gen_fn(method, seed, psi):
236
  z = RandomState(int(seed) + 2 ** 31).randn(1, 512) if method == 1 else np.random.randn(1, 512)
237
  w = model.get_w(z.astype(dtype=np.float32), psi)
238
  img_out = model.get_img(w)
239
+ return img_out, w, get_thumbnail(img_out)
240
 
241
 
242
  def encode_img_fn(img):
 
247
  return "failed to detect waifu", None, None, None, None
248
  w = model.encode_img(imgs[0])
249
  img_out = model.get_img(w)
250
+ return "success", imgs[0], img_out, w, get_thumbnail(img_out)
251
 
252
 
253
  def gen_video_fn(w1, w2, frame):
 
287
  with gr.Column():
288
  gr.Markdown("you'd better upload a standing full-body image")
289
  encode_img_input = gr.Image(label="input image")
290
+ examples_data = [[f"examples/{x:02d}.png"] for x in range(1, 7)]
291
+ encode_img_examples = gr.Dataset(components=[encode_img_input], samples=examples_data)
292
  with gr.Group():
293
  encode_img_submit = gr.Button("Run", variant="primary")
294
  with gr.Column():
 
310
  choices=["current generated image",
311
  "current encoded image"], type="index")
312
  with gr.Group():
313
+ select_img1_button = gr.Button("Select", variant="primary")
314
  select_img1_output_img = gr.Image(label="selected image 1")
315
  select_img1_output_w = gr.Variable()
316
  with gr.Column():
 
319
  choices=["current generated image",
320
  "current encoded image"], type="index")
321
  with gr.Group():
322
+ select_img2_button = gr.Button("Select", variant="primary")
323
  select_img2_output_img = gr.Image(label="selected image 2")
324
  select_img2_output_w = gr.Variable()
325
  generate_video_frame = gr.Slider(minimum=10, maximum=30, step=1, label="frame", value=15)
 
332
  encode_img_submit.click(encode_img_fn, [encode_img_input],
333
  [encode_img_output1, encode_img_output2, encode_img_output3, select_img_input_w2,
334
  select_img_input_img2])
335
+ encode_img_examples.click(lambda x: x[0], [encode_img_examples], [encode_img_input])
336
  select_img1_button.click(lambda i, img1, img2, w1, w2: (img1, w1) if i == 0 else (img2, w2),
337
  [select_img1_dropdown, select_img_input_img1, select_img_input_img2,
338
  select_img_input_w1, select_img_input_w2],
examples/01.png ADDED
examples/02.png ADDED
examples/03.png ADDED
examples/04.png ADDED
examples/05.png ADDED
examples/06.png ADDED