Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Updated to new blocks SDK, testing visibility
Browse files- README.md +1 -1
- app.py +48 -50
- generate_videos.py +1 -1
    	
        README.md
    CHANGED
    
    | @@ -4,7 +4,7 @@ emoji: 🌖 | |
| 4 | 
             
            colorFrom: blue
         | 
| 5 | 
             
            colorTo: gray
         | 
| 6 | 
             
            sdk: gradio
         | 
| 7 | 
            -
            sdk_version: 3. | 
| 8 | 
             
            app_file: app.py
         | 
| 9 | 
             
            pinned: false
         | 
| 10 | 
             
            license: mit
         | 
|  | |
| 4 | 
             
            colorFrom: blue
         | 
| 5 | 
             
            colorTo: gray
         | 
| 6 | 
             
            sdk: gradio
         | 
| 7 | 
            +
            sdk_version: 3.0.1
         | 
| 8 | 
             
            app_file: app.py
         | 
| 9 | 
             
            pinned: false
         | 
| 10 | 
             
            license: mit
         | 
    	
        app.py
    CHANGED
    
    | @@ -236,17 +236,17 @@ class ImageEditor(object): | |
| 236 |  | 
| 237 | 
             
            editor = ImageEditor()
         | 
| 238 |  | 
| 239 | 
            -
             | 
| 240 |  | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 |  | 
| 244 | 
            -
             | 
| 245 |  | 
| 246 | 
            -
            def group_visibility(visible):
         | 
| 247 | 
            -
             | 
| 248 |  | 
| 249 | 
            -
             | 
| 250 |  | 
| 251 | 
             
            blocks = gr.Blocks()
         | 
| 252 |  | 
| @@ -259,61 +259,59 @@ with blocks: | |
| 259 | 
             
                    "For more information about the paper and code for training your own models (with examples OR text), see below."
         | 
| 260 | 
             
                )
         | 
| 261 |  | 
| 262 | 
            -
                 | 
| 263 |  | 
| 264 | 
            -
             | 
| 265 | 
            -
             | 
| 266 | 
            -
             | 
| 267 |  | 
| 268 | 
            -
             | 
| 269 | 
            -
                        
         | 
| 270 | 
            -
                #         video_options_group = gr.Group()
         | 
| 271 |  | 
| 272 | 
            -
             | 
| 273 | 
            -
             | 
| 274 | 
            -
             | 
| 275 |  | 
| 276 | 
            -
             | 
| 277 | 
            -
             | 
| 278 | 
            -
             | 
| 279 | 
            -
             | 
| 280 |  | 
| 281 | 
            -
             | 
| 282 | 
            -
             | 
| 283 | 
            -
             | 
| 284 |  | 
| 285 | 
            -
                 | 
| 286 | 
            -
             | 
| 287 |  | 
| 288 | 
            -
                 | 
| 289 | 
             
                # video_choice.change(fn=group_visibility, inputs=video_choice, outputs=video_options_group)
         | 
| 290 | 
            -
                 | 
| 291 | 
            -
                 | 
| 292 |  | 
| 293 | 
            -
                with gr.Row():
         | 
| 294 | 
            -
             | 
| 295 | 
            -
             | 
| 296 | 
            -
             | 
| 297 | 
            -
                with gr.Tabs():
         | 
| 298 | 
            -
             | 
| 299 | 
            -
             | 
| 300 | 
            -
             | 
| 301 | 
            -
             | 
| 302 | 
            -
             | 
| 303 |  | 
| 304 | 
            -
             | 
| 305 | 
            -
             | 
| 306 | 
            -
             | 
| 307 | 
            -
             | 
| 308 | 
            -
             | 
| 309 | 
            -
             | 
| 310 | 
            -
             | 
| 311 |  | 
| 312 | 
            -
             | 
| 313 | 
            -
             | 
| 314 |  | 
| 315 | 
            -
                img_button.click(fn=editor.edit_image, inputs=[input_img, style_choice], outputs=img_output)
         | 
| 316 | 
            -
                vid_button.click(fn=editor.edit_video, inputs=[input_img, style_choice, edit_choice, vid_format_choice, loop_styles], outputs=vid_output)
         | 
| 317 |  | 
| 318 | 
             
                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>"
         | 
| 319 | 
             
                gr.Markdown(article)
         | 
|  | |
| 236 |  | 
| 237 | 
             
            editor = ImageEditor()
         | 
| 238 |  | 
| 239 | 
            +
            def change_component_visibility(component_types, invert_choices):
         | 
| 240 |  | 
| 241 | 
            +
                def visibility_impl(visible):
         | 
| 242 | 
            +
                    return [component_types[idx].update(visible=visible ^ invert_choices[idx]) for idx in range(len(component_types))]
         | 
| 243 |  | 
| 244 | 
            +
                return visibility_impl
         | 
| 245 |  | 
| 246 | 
            +
            # def group_visibility(visible):
         | 
| 247 | 
            +
            #     print("visible: ", visible)
         | 
| 248 |  | 
| 249 | 
            +
            #     return gr.Group.update(visibile=visible)
         | 
| 250 |  | 
| 251 | 
             
            blocks = gr.Blocks()
         | 
| 252 |  | 
|  | |
| 259 | 
             
                    "For more information about the paper and code for training your own models (with examples OR text), see below."
         | 
| 260 | 
             
                )
         | 
| 261 |  | 
| 262 | 
            +
                with gr.Row():
         | 
| 263 |  | 
| 264 | 
            +
                    with gr.Column():
         | 
| 265 | 
            +
                        input_img    = gr.inputs.Image(type="filepath", label="Input image")
         | 
| 266 | 
            +
                        style_choice = gr.inputs.CheckboxGroup(choices=editor.get_style_list(), type="value", label="Choose your styles!")
         | 
| 267 |  | 
| 268 | 
            +
                        video_choice = gr.inputs.Checkbox(default=False, label="Generate Video?", optional=False)
         | 
|  | |
|  | |
| 269 |  | 
| 270 | 
            +
                        loop_styles       = gr.inputs.Checkbox(default=True, label="Loop video back to the initial style?", visible=False)
         | 
| 271 | 
            +
                        edit_choice       = gr.inputs.Checkbox(default=False, label="With Editing?", visible=False)
         | 
| 272 | 
            +
                        vid_format_choice = gr.inputs.Radio(choices=["gif", "mp4"], type="value", default='mp4', label="Video Format", visible=False)
         | 
| 273 |  | 
| 274 | 
            +
                        # img_button = gr.Button("Edit Image")
         | 
| 275 | 
            +
                        # vid_button = gr.Button("Generate Video")
         | 
| 276 | 
            +
                        img_button = gr.Button("Edit Image")
         | 
| 277 | 
            +
                        vid_button = gr.Button("Generate Video", visible=False)
         | 
| 278 |  | 
| 279 | 
            +
                    with gr.Column():
         | 
| 280 | 
            +
                        img_output = gr.outputs.Image(type="file")
         | 
| 281 | 
            +
                        vid_output = gr.outputs.Video(visible=False)
         | 
| 282 |  | 
| 283 | 
            +
                visibility_fn = change_component_visibility(component_types=[gr.Checkbox, gr.Radio, gr.Video, gr.Button, gr.Image, gr.Button, gr.Checkbox],
         | 
| 284 | 
            +
                                                            invert_choices=[False, False, False, False, True, True, False])
         | 
| 285 |  | 
| 286 | 
            +
                video_choice.change(fn=visibility_fn, inputs=video_choice, outputs=[edit_choice, vid_format_choice, vid_output, vid_button, img_output, img_button])
         | 
| 287 | 
             
                # video_choice.change(fn=group_visibility, inputs=video_choice, outputs=video_options_group)
         | 
| 288 | 
            +
                img_button.click(fn=editor.edit_image, inputs=[input_img, style_choice], outputs=img_output)
         | 
| 289 | 
            +
                vid_button.click(fn=editor.edit_video, inputs=[input_img, style_choice, edit_choice, vid_format_choice, loop_styles], outputs=vid_output)
         | 
| 290 |  | 
| 291 | 
            +
                # with gr.Row():
         | 
| 292 | 
            +
                #     input_img = gr.inputs.Image(type="filepath", label="Input image")    
         | 
| 293 | 
            +
                #     style_choice = gr.inputs.CheckboxGroup(choices=editor.get_style_list(), type="value", label="Choose your styles!")
         | 
| 294 | 
            +
             | 
| 295 | 
            +
                # with gr.Tabs():
         | 
| 296 | 
            +
                #     with gr.TabItem("Edit Images"):
         | 
| 297 | 
            +
                #         with gr.Column():
         | 
| 298 | 
            +
                #             img_button = gr.Button("Edit Image")
         | 
| 299 | 
            +
                #         with gr.Column():
         | 
| 300 | 
            +
                #             img_output = gr.outputs.Image(type="file", label="Output Image")
         | 
| 301 |  | 
| 302 | 
            +
                #     with gr.TabItem("Create Video"):
         | 
| 303 | 
            +
                #         with gr.Column():
         | 
| 304 | 
            +
                #             with gr.Row():
         | 
| 305 | 
            +
                #                 vid_button = gr.Button("Generate Video")
         | 
| 306 | 
            +
                #                 loop_styles       = gr.inputs.Checkbox(default=True, label="Loop video back to the initial style?")
         | 
| 307 | 
            +
                #                 edit_choice       = gr.inputs.Checkbox(default=False, label="With latent space editing?")
         | 
| 308 | 
            +
                #                 vid_format_choice = gr.inputs.Radio(choices=["gif", "mp4"], type="value", default='mp4', label="Video Format")
         | 
| 309 |  | 
| 310 | 
            +
                #         with gr.Column():
         | 
| 311 | 
            +
                #             vid_output = gr.outputs.Video(label="Output Video")
         | 
| 312 |  | 
| 313 | 
            +
                # img_button.click(fn=editor.edit_image, inputs=[input_img, style_choice], outputs=img_output)
         | 
| 314 | 
            +
                # vid_button.click(fn=editor.edit_video, inputs=[input_img, style_choice, edit_choice, vid_format_choice, loop_styles], outputs=vid_output)
         | 
| 315 |  | 
| 316 | 
             
                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>"
         | 
| 317 | 
             
                gr.Markdown(article)
         | 
    	
        generate_videos.py
    CHANGED
    
    | @@ -151,7 +151,7 @@ def video_from_interpolations(fps, output_dir): | |
| 151 | 
             
                           "-r", f"{fps}", 
         | 
| 152 | 
             
                           "-i", f"{output_dir}/%03d.jpg", 
         | 
| 153 | 
             
                           "-c:v", "libx264", 
         | 
| 154 | 
            -
                           "-vf", f"fps={fps} | 
| 155 | 
             
                           "-pix_fmt", "yuv420p", 
         | 
| 156 | 
             
                           f"{output_dir}/out.mp4"]
         | 
| 157 |  | 
|  | |
| 151 | 
             
                           "-r", f"{fps}", 
         | 
| 152 | 
             
                           "-i", f"{output_dir}/%03d.jpg", 
         | 
| 153 | 
             
                           "-c:v", "libx264", 
         | 
| 154 | 
            +
                           "-vf", f"fps={fps}", 
         | 
| 155 | 
             
                           "-pix_fmt", "yuv420p", 
         | 
| 156 | 
             
                           f"{output_dir}/out.mp4"]
         | 
| 157 |  | 
