Spaces:
Runtime error
Runtime error
Updated visibility change callbacks
Browse files
app.py
CHANGED
|
@@ -120,7 +120,8 @@ class ImageEditor(object):
|
|
| 120 |
print("setup complete")
|
| 121 |
|
| 122 |
def get_style_list(self):
|
| 123 |
-
style_list = ['all', 'list - enter below']
|
|
|
|
| 124 |
|
| 125 |
for key in self.generators:
|
| 126 |
style_list.append(key)
|
|
@@ -208,12 +209,17 @@ class ImageEditor(object):
|
|
| 208 |
|
| 209 |
editor = ImageEditor()
|
| 210 |
|
| 211 |
-
def change_component_visibility(component_types, invert_choices):
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
blocks = gr.Blocks()
|
| 219 |
|
|
@@ -234,9 +240,14 @@ with blocks:
|
|
| 234 |
|
| 235 |
video_choice = gr.inputs.Checkbox(default=False, label="Generate Video?", optional=False)
|
| 236 |
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
| 239 |
|
|
|
|
|
|
|
| 240 |
img_button = gr.Button("Edit Image")
|
| 241 |
vid_button = gr.Button("Generate Video")
|
| 242 |
|
|
@@ -244,13 +255,45 @@ with blocks:
|
|
| 244 |
img_output = gr.outputs.Image(type="file")
|
| 245 |
vid_output = gr.outputs.Video()
|
| 246 |
|
| 247 |
-
visibility_fn = change_component_visibility(component_types=[gr.Checkbox, gr.Radio, gr.Video, gr.Button, gr.Image, gr.Button],
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
video_choice.change(fn=visibility_fn, inputs=video_choice, outputs=[edit_choice, vid_format_choice, vid_output, vid_button, img_output, img_button])
|
| 251 |
|
|
|
|
|
|
|
| 252 |
img_button.click(fn=editor.predict, inputs=[input_img, style_choice, video_choice, edit_choice, vid_format_choice], outputs=img_output)
|
| 253 |
vid_button.click(fn=editor.predict, inputs=[input_img, style_choice, video_choice, edit_choice, vid_format_choice], outputs=vid_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.00946' target='_blank'>StyleGAN-NADA: CLIP-Guided Domain Adaptation of Image Generators</a> | <a href='https://stylegan-nada.github.io/' target='_blank'>Project Page</a> | <a href='https://github.com/rinongal/StyleGAN-nada' target='_blank'>Code</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=rinong_sgnada' alt='visitor badge'></center>"
|
| 256 |
gr.Markdown(article)
|
|
|
|
| 120 |
print("setup complete")
|
| 121 |
|
| 122 |
def get_style_list(self):
|
| 123 |
+
# style_list = ['all', 'list - enter below']
|
| 124 |
+
style_list = []
|
| 125 |
|
| 126 |
for key in self.generators:
|
| 127 |
style_list.append(key)
|
|
|
|
| 209 |
|
| 210 |
editor = ImageEditor()
|
| 211 |
|
| 212 |
+
# def change_component_visibility(component_types, invert_choices):
|
| 213 |
|
| 214 |
+
# def visibility_impl(visible):
|
| 215 |
+
# return [component_types[idx].update(visible=visible ^ invert_choices[idx]) for idx in range(len(component_types))]
|
| 216 |
|
| 217 |
+
# return visibility_impl
|
| 218 |
+
|
| 219 |
+
def group_visibility(visible):
|
| 220 |
+
print("visible: ", visible)
|
| 221 |
+
|
| 222 |
+
return gr.Group.update(visibile=visible)
|
| 223 |
|
| 224 |
blocks = gr.Blocks()
|
| 225 |
|
|
|
|
| 240 |
|
| 241 |
video_choice = gr.inputs.Checkbox(default=False, label="Generate Video?", optional=False)
|
| 242 |
|
| 243 |
+
video_options_group = gr.Group()
|
| 244 |
+
|
| 245 |
+
with video_options_group:
|
| 246 |
+
edit_choice = gr.inputs.Checkbox(default=False, label="With Editing?", optional=False)
|
| 247 |
+
vid_format_choice = gr.inputs.Radio(choices=["gif", "mp4"], type="value", default='mp4', label="Video Format")
|
| 248 |
|
| 249 |
+
# img_button = gr.Button("Edit Image")
|
| 250 |
+
# vid_button = gr.Button("Generate Video")
|
| 251 |
img_button = gr.Button("Edit Image")
|
| 252 |
vid_button = gr.Button("Generate Video")
|
| 253 |
|
|
|
|
| 255 |
img_output = gr.outputs.Image(type="file")
|
| 256 |
vid_output = gr.outputs.Video()
|
| 257 |
|
| 258 |
+
# visibility_fn = change_component_visibility(component_types=[gr.Checkbox, gr.Radio, gr.Video, gr.Button, gr.Image, gr.Button],
|
| 259 |
+
# invert_choices=[False, False, False, False, True, True])
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
# video_choice.change(fn=visibility_fn, inputs=video_choice, outputs=[edit_choice, vid_format_choice, vid_output, vid_button, img_output, img_button])
|
| 262 |
+
video_choice.change(fn=group_visibility, inputs=video_choice, outputs=video_options_group)
|
| 263 |
img_button.click(fn=editor.predict, inputs=[input_img, style_choice, video_choice, edit_choice, vid_format_choice], outputs=img_output)
|
| 264 |
vid_button.click(fn=editor.predict, inputs=[input_img, style_choice, video_choice, edit_choice, vid_format_choice], outputs=vid_output)
|
| 265 |
+
|
| 266 |
+
# input_img = gr.inputs.Image(type="filepath", label="Input image")
|
| 267 |
+
# style_choice = gr.inputs.CheckboxGroup(choices=editor.get_style_list(), type="value", label="Choose your styles!")
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
# with gr.Tabs():
|
| 272 |
+
# with gr.TabItem("Edit Images"):
|
| 273 |
+
# with gr.Row():
|
| 274 |
+
# with gr.Column():
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
# video_choice = gr.inputs.Checkbox(default=False, label="Generate Video?", optional=False)
|
| 279 |
+
|
| 280 |
+
# edit_choice = gr.inputs.Checkbox(default=False, label="With Editing?", optional=False)
|
| 281 |
+
# vid_format_choice = gr.inputs.Radio(choices=["gif", "mp4"], type="value", default='mp4', label="Video Format")
|
| 282 |
+
|
| 283 |
+
# img_button = gr.Button("Edit Image")
|
| 284 |
+
# vid_button = gr.Button("Generate Video")
|
| 285 |
+
|
| 286 |
+
# with gr.Column():
|
| 287 |
+
# img_output = gr.outputs.Image(type="file")
|
| 288 |
+
# vid_output = gr.outputs.Video()
|
| 289 |
+
|
| 290 |
+
# visibility_fn = change_component_visibility(component_types=[gr.Checkbox, gr.Radio, gr.Video, gr.Button, gr.Image, gr.Button],
|
| 291 |
+
# invert_choices=[False, False, False, False, True, True])
|
| 292 |
+
|
| 293 |
+
# video_choice.change(fn=visibility_fn, inputs=video_choice, outputs=[edit_choice, vid_format_choice, vid_output, vid_button, img_output, img_button])
|
| 294 |
+
|
| 295 |
+
# img_button.click(fn=editor.predict, inputs=[input_img, style_choice, video_choice, edit_choice, vid_format_choice], outputs=img_output)
|
| 296 |
+
# vid_button.click(fn=editor.predict, inputs=[input_img, style_choice, video_choice, edit_choice, vid_format_choice], outputs=vid_output)
|
| 297 |
|
| 298 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.00946' target='_blank'>StyleGAN-NADA: CLIP-Guided Domain Adaptation of Image Generators</a> | <a href='https://stylegan-nada.github.io/' target='_blank'>Project Page</a> | <a href='https://github.com/rinongal/StyleGAN-nada' target='_blank'>Code</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=rinong_sgnada' alt='visitor badge'></center>"
|
| 299 |
gr.Markdown(article)
|