Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -73,7 +73,7 @@ def predict_depth(image, model): | |
| 73 | 
             
            #def predict_depth(model, image):
         | 
| 74 | 
             
            #    return model(image)["depth"]
         | 
| 75 |  | 
| 76 | 
            -
            def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data=blurin, o=1, b=32):
         | 
| 77 | 
             
                if encoder not in ["vitl","vitb","vits","vitg"]:
         | 
| 78 | 
             
                    encoder = "vits"
         | 
| 79 |  | 
| @@ -241,7 +241,9 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data | |
| 241 | 
             
                        masks.append(f"f{count}_mask.png")            
         | 
| 242 | 
             
                        count += 1
         | 
| 243 |  | 
| 244 | 
            -
                     | 
|  | |
|  | |
| 245 |  | 
| 246 | 
             
                    j=0
         | 
| 247 | 
             
                    while j<len(frames):
         | 
| @@ -681,6 +683,7 @@ with gr.Blocks(css=css, js=js, head=head) as demo: | |
| 681 | 
             
                          input_url = gr.Textbox(elem_id="url_in", value="./examples/streetview.mp4", label="URL")
         | 
| 682 | 
             
                          input_video = gr.Video(label="Input Video", format="mp4")
         | 
| 683 | 
             
                          input_url.input(fn=loadfile, inputs=[input_url], outputs=[input_video])
         | 
|  | |
| 684 | 
             
                          submit = gr.Button("Submit")
         | 
| 685 | 
             
                        with gr.Group():
         | 
| 686 | 
             
                          output_frame = gr.Gallery(label="Frames", preview=True, columns=8192, interactive=False)
         | 
| @@ -782,7 +785,7 @@ with gr.Blocks(css=css, js=js, head=head) as demo: | |
| 782 | 
             
                      input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth])
         | 
| 783 |  | 
| 784 |  | 
| 785 | 
            -
                def on_submit(uploaded_video,model_type,blur_in,boffset,bsize,coordinates):
         | 
| 786 | 
             
                    global locations
         | 
| 787 | 
             
                    locations = []
         | 
| 788 | 
             
                    avg = [0, 0]
         | 
| @@ -841,14 +844,14 @@ with gr.Blocks(css=css, js=js, head=head) as demo: | |
| 841 | 
             
                    f.close()
         | 
| 842 |  | 
| 843 | 
             
                    # Process the video and get the path of the output video
         | 
| 844 | 
            -
                    output_video_path = make_video(uploaded_video,encoder=model_type,blur_data=blurin,o=boffset,b=bsize)
         | 
| 845 |  | 
| 846 | 
             
                    return output_video_path
         | 
| 847 |  | 
| 848 | 
            -
                submit.click(on_submit, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth])
         | 
| 849 |  | 
| 850 | 
            -
                example_files = [["./examples/streetview.mp4", "vits", blurin, 1, 32, example_coords]]
         | 
| 851 | 
            -
                examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth])
         | 
| 852 |  | 
| 853 |  | 
| 854 | 
             
            if __name__ == '__main__':
         | 
|  | |
| 73 | 
             
            #def predict_depth(model, image):
         | 
| 74 | 
             
            #    return model(image)["depth"]
         | 
| 75 |  | 
| 76 | 
            +
            def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data=blurin, o=1, b=32, ctr=True):
         | 
| 77 | 
             
                if encoder not in ["vitl","vitb","vits","vitg"]:
         | 
| 78 | 
             
                    encoder = "vits"
         | 
| 79 |  | 
|  | |
| 241 | 
             
                        masks.append(f"f{count}_mask.png")            
         | 
| 242 | 
             
                        count += 1
         | 
| 243 |  | 
| 244 | 
            +
                    global frame_selected
         | 
| 245 | 
            +
                    if ctr === True:
         | 
| 246 | 
            +
                        color_transfer(frame_selected)
         | 
| 247 |  | 
| 248 | 
             
                    j=0
         | 
| 249 | 
             
                    while j<len(frames):
         | 
|  | |
| 683 | 
             
                          input_url = gr.Textbox(elem_id="url_in", value="./examples/streetview.mp4", label="URL")
         | 
| 684 | 
             
                          input_video = gr.Video(label="Input Video", format="mp4")
         | 
| 685 | 
             
                          input_url.input(fn=loadfile, inputs=[input_url], outputs=[input_video])
         | 
| 686 | 
            +
                          ct = gr.Checkbox(label="Color transfer", value=True)
         | 
| 687 | 
             
                          submit = gr.Button("Submit")
         | 
| 688 | 
             
                        with gr.Group():
         | 
| 689 | 
             
                          output_frame = gr.Gallery(label="Frames", preview=True, columns=8192, interactive=False)
         | 
|  | |
| 785 | 
             
                      input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth])
         | 
| 786 |  | 
| 787 |  | 
| 788 | 
            +
                def on_submit(uploaded_video,model_type,blur_in,boffset,bsize,ct,coordinates):
         | 
| 789 | 
             
                    global locations
         | 
| 790 | 
             
                    locations = []
         | 
| 791 | 
             
                    avg = [0, 0]
         | 
|  | |
| 844 | 
             
                    f.close()
         | 
| 845 |  | 
| 846 | 
             
                    # Process the video and get the path of the output video
         | 
| 847 | 
            +
                    output_video_path = make_video(uploaded_video,encoder=model_type,blur_data=blurin,o=boffset,b=bsize,ctr=ct)
         | 
| 848 |  | 
| 849 | 
             
                    return output_video_path
         | 
| 850 |  | 
| 851 | 
            +
                submit.click(on_submit, inputs=[input_video, model_type, blur_in, boffset, bsize, ct, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth])
         | 
| 852 |  | 
| 853 | 
            +
                example_files = [["./examples/streetview.mp4", "vits", blurin, 1, 32, True, example_coords]]
         | 
| 854 | 
            +
                examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, blur_in, boffset, bsize, ct, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth])
         | 
| 855 |  | 
| 856 |  | 
| 857 | 
             
            if __name__ == '__main__':
         | 
