mjdolan commited on
Commit
510b308
1 Parent(s): 369b861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -47,7 +47,7 @@ model_repos = {
47
  interface_gan_map = {"None": None, "Masculine": ("gender", 1.0), "Feminine": ("gender", -1.0),
48
  "Smiling": ("smile", 1.0),
49
  "Frowning": ("smile", -1.0), "Young": ("age", -1.0), "Old": ("age", 1.0),
50
- "Short Hair": ("hair_length", -1.0), "Long Hair": ("hair_length", 1.0)}
51
 
52
 
53
  def get_models():
@@ -152,13 +152,6 @@ class ImageEditor(object):
152
 
153
  return [self.generators[style] for style in output_styles]
154
 
155
- def _pack_edits(func):
156
- def inner(self,
157
- alter,
158
- *args):
159
- return func(self, *args, alter)
160
-
161
- return inner
162
 
163
 
164
  def get_target_latent(self, source_latent, alter, generators):
@@ -169,7 +162,6 @@ class ImageEditor(object):
169
  projected_code_np = project_code_by_edit_name(np_source_latent, edit[0], edit[1])
170
  return torch.from_numpy(projected_code_np).float().to(self.device)
171
 
172
- @_pack_edits
173
  def edit_image(self, input, output_styles, edit_choices):
174
  return self.predict(input, output_styles, edit_choices=edit_choices)
175
 
@@ -238,10 +230,10 @@ with blocks:
238
 
239
  with gr.Row():
240
  img_output = gr.Gallery(label="Output Images")
 
241
 
242
-
243
- img_button.click(fn=editor.edit_image, inputs=[alter, input_img, style_choice], outputs=img_output)
244
- ex = gr.Examples(examples=[["Smiling", 'example1.jpg', editor.get_style_list()], ["Long Hair", 'example2.jpg', editor.get_style_list()]], fn=editor.edit_image, inputs=[alter, input_img, style_choice],
245
  outputs=[img_output], cache_examples=True,
246
  run_on_click=True)
247
  ex.dataset.headers = [""]
 
47
  interface_gan_map = {"None": None, "Masculine": ("gender", 1.0), "Feminine": ("gender", -1.0),
48
  "Smiling": ("smile", 1.0),
49
  "Frowning": ("smile", -1.0), "Young": ("age", -1.0), "Old": ("age", 1.0),
50
+ "Long Hair": ("hair_length", -1.0), "Short Hair": ("hair_length", 1.0)}
51
 
52
 
53
  def get_models():
 
152
 
153
  return [self.generators[style] for style in output_styles]
154
 
 
 
 
 
 
 
 
155
 
156
 
157
  def get_target_latent(self, source_latent, alter, generators):
 
162
  projected_code_np = project_code_by_edit_name(np_source_latent, edit[0], edit[1])
163
  return torch.from_numpy(projected_code_np).float().to(self.device)
164
 
 
165
  def edit_image(self, input, output_styles, edit_choices):
166
  return self.predict(input, output_styles, edit_choices=edit_choices)
167
 
 
230
 
231
  with gr.Row():
232
  img_output = gr.Gallery(label="Output Images")
233
+ img_output.style(grid=(3, 3, 4, 4, 6, 6))
234
 
235
+ img_button.click(fn=editor.edit_image, inputs=[input_img, style_choice, alter], outputs=img_output)
236
+ ex = gr.Examples(examples=[['example1.jpg', editor.get_style_list(), "Smiling"], ['example2.jpg', editor.get_style_list(), "Long Hair"]], fn=editor.edit_image, inputs=[input_img, style_choice, alter],
 
237
  outputs=[img_output], cache_examples=True,
238
  run_on_click=True)
239
  ex.dataset.headers = [""]