hysts HF staff commited on
Commit
f1383e1
1 Parent(s): 461ea3c

Place examples for each step

Browse files
Files changed (1) hide show
  1. app.py +49 -23
app.py CHANGED
@@ -212,7 +212,7 @@ def update_slider(choice: str) -> dict:
212
  'pixar': 121,
213
  'slamdunk': 119,
214
  }
215
- return gr.Slider.update(maximum=max_vals[choice], value=26)
216
 
217
 
218
  def update_style_image(style_name: str) -> dict:
@@ -220,14 +220,21 @@ def update_style_image(style_name: str) -> dict:
220
  return gr.Markdown.update(value=text)
221
 
222
 
223
- def set_example(example: list) -> list[dict]:
 
 
 
 
224
  return [
225
- gr.Image.update(value=example[0]),
226
- gr.Radio.update(value=example[1]),
227
- gr.Slider.update(value=example[2]),
228
- gr.Slider.update(value=example[3]),
229
- gr.Slider.update(value=example[4]),
230
- gr.Checkbox.update(value=example[5]),
 
 
 
231
  ]
232
 
233
 
@@ -262,7 +269,6 @@ This is an unofficial demo app for [https://github.com/williamyang1991/DualStyle
262
 
263
  - Drop an image containing a near-frontal face to the **Input Image**.
264
  - If there are multiple faces in the image, hit the Edit button in the upper right corner and crop the input image beforehand.
265
- - You can also load example inputs from the **Examples** section at the bottom of this page.
266
  - Hit the **Detect & Align Face** button.
267
  - Hit the **Reconstruct Face** button.
268
  - The final result will be based on this **Reconstructed Face**. So, if the reconstructed image is not satisfactory, you may want to change the input image.
@@ -285,6 +291,12 @@ This is an unofficial demo app for [https://github.com/williamyang1991/DualStyle
285
  type='numpy')
286
  instyle = gr.Variable()
287
 
 
 
 
 
 
 
288
  with gr.Box():
289
  gr.Markdown('''## Step 2 (Select Style Image)
290
 
@@ -303,6 +315,16 @@ This is an unofficial demo app for [https://github.com/williamyang1991/DualStyle
303
  label='Style Image Index',
304
  interactive=True)
305
 
 
 
 
 
 
 
 
 
 
 
306
  with gr.Box():
307
  gr.Markdown('''## Step 3 (Generate Style Transferred Image)
308
 
@@ -332,25 +354,20 @@ This is an unofficial demo app for [https://github.com/williamyang1991/DualStyle
332
  with gr.Column():
333
  output_image = gr.Image(label='Output Image')
334
 
335
- with gr.Box():
336
- gr.Markdown('## Examples')
337
-
338
- paths = sorted(pathlib.Path('images').glob('*.jpg'))
339
- samples = [[path.as_posix(), 'cartoon', 26, 0.6, 1.0, False]
340
- for path in paths]
341
- examples = gr.Dataset(components=[
342
- input_image, style_type, style_index, structure_weight,
343
- color_weight, structure_only
344
- ],
345
- samples=samples)
346
 
347
  gr.Markdown(
348
  '<center><img src="https://visitor-badge.glitch.me/badge?page_id=gradio-blocks.dualstylegan" alt="visitor badge"/></center>'
349
  )
350
 
351
- examples.click(fn=set_example,
352
- inputs=examples,
353
- outputs=examples.components)
354
  detect_button.click(fn=app.detect_and_align_face,
355
  inputs=input_image,
356
  outputs=face_image)
@@ -373,6 +390,15 @@ This is an unofficial demo app for [https://github.com/williamyang1991/DualStyle
373
  instyle,
374
  ],
375
  outputs=output_image)
 
 
 
 
 
 
 
 
 
376
 
377
  demo.launch(
378
  enable_queue=args.enable_queue,
 
212
  'pixar': 121,
213
  'slamdunk': 119,
214
  }
215
+ return gr.Slider.update(maximum=max_vals[choice])
216
 
217
 
218
  def update_style_image(style_name: str) -> dict:
 
220
  return gr.Markdown.update(value=text)
221
 
222
 
223
+ def set_example_image(example: list) -> dict:
224
+ return gr.Image.update(value=example[0])
225
+
226
+
227
+ def set_example_styles(example: list) -> list[dict]:
228
  return [
229
+ gr.Radio.update(value=example[0]),
230
+ gr.Slider.update(value=example[1]),
231
+ ]
232
+
233
+
234
+ def set_example_weights(example: list) -> list[dict]:
235
+ return [
236
+ gr.Slider.update(value=example[0]),
237
+ gr.Slider.update(value=example[1]),
238
  ]
239
 
240
 
 
269
 
270
  - Drop an image containing a near-frontal face to the **Input Image**.
271
  - If there are multiple faces in the image, hit the Edit button in the upper right corner and crop the input image beforehand.
 
272
  - Hit the **Detect & Align Face** button.
273
  - Hit the **Reconstruct Face** button.
274
  - The final result will be based on this **Reconstructed Face**. So, if the reconstructed image is not satisfactory, you may want to change the input image.
 
291
  type='numpy')
292
  instyle = gr.Variable()
293
 
294
+ with gr.Row():
295
+ paths = sorted(pathlib.Path('images').glob('*.jpg'))
296
+ example_images = gr.Dataset(components=[input_image],
297
+ samples=[[path.as_posix()]
298
+ for path in paths])
299
+
300
  with gr.Box():
301
  gr.Markdown('''## Step 2 (Select Style Image)
302
 
 
315
  label='Style Image Index',
316
  interactive=True)
317
 
318
+ with gr.Row():
319
+ example_styles = gr.Dataset(
320
+ components=[style_type, style_index],
321
+ samples=[
322
+ ['cartoon', 26],
323
+ ['caricature', 65],
324
+ ['arcane', 63],
325
+ ['pixar', 80],
326
+ ])
327
+
328
  with gr.Box():
329
  gr.Markdown('''## Step 3 (Generate Style Transferred Image)
330
 
 
354
  with gr.Column():
355
  output_image = gr.Image(label='Output Image')
356
 
357
+ with gr.Row():
358
+ example_weights = gr.Dataset(
359
+ components=[structure_weight, color_weight],
360
+ samples=[
361
+ [0.6, 1.0],
362
+ [0.3, 1.0],
363
+ [0.0, 1.0],
364
+ [1.0, 0.0],
365
+ ])
 
 
366
 
367
  gr.Markdown(
368
  '<center><img src="https://visitor-badge.glitch.me/badge?page_id=gradio-blocks.dualstylegan" alt="visitor badge"/></center>'
369
  )
370
 
 
 
 
371
  detect_button.click(fn=app.detect_and_align_face,
372
  inputs=input_image,
373
  outputs=face_image)
 
390
  instyle,
391
  ],
392
  outputs=output_image)
393
+ example_images.click(fn=set_example_image,
394
+ inputs=example_images,
395
+ outputs=example_images.components)
396
+ example_styles.click(fn=set_example_styles,
397
+ inputs=example_styles,
398
+ outputs=example_styles.components)
399
+ example_weights.click(fn=set_example_weights,
400
+ inputs=example_weights,
401
+ outputs=example_weights.components)
402
 
403
  demo.launch(
404
  enable_queue=args.enable_queue,