Spaces:
Build error
Build error
Update app.py
Browse files81 unmodified lines8283848586878889144 unmodified lines2342352362372382392402412422432442454 unmodified lines25025125225325425525625725863 unmodified lines32232332432532632732871 unmodified lines40040140240340440540610 unmodified lines41741841942081 unmodified lineswith open(output_path, "wb") as f:f.write(splat_data)def get_reconstructed_scene(outdir, image_files, model, device):images = [process_image(img_path) for img_path in image_files]images = torch.stack(images, dim=0).unsqueeze(0).to(device) # [1, K, 3, 448, 448]b, v, c, h, w = images.shape144 unmodified linessession_id = uuid.uuid4().heximages_folder, image_paths = extract_frames(video_path, session_id)plyfile, rgb_vid, depth_vid = generate_splats_from_images(image_paths, session_id)return plyfile, rgb_vid, depth_vid, image_paths@spaces.GPU()def generate_splats_from_images(image_paths, session_id=None):if session_id is None:session_id = uuid.uuid4().hex4 unmodified linesbase_dir = os.path.join(os.environ["ANYSPLAT_PROCESSED"], session_id)print("Running run_model...")with torch.no_grad():plyfile, video, depth_colored = get_reconstructed_scene(base_dir, image_paths, model, device)end_time = time.time()print(f"Total time: {end_time - start_time:.2f} seconds (including IO)")63 unmodified lineswith gr.Tab("Video"):input_video = gr.Video(label="Upload Video", sources=["upload"], interactive=True, height=512)with gr.Tab("Images"):input_images = gr.File(file_count="multiple", label="Upload Files", type="filepath", height=512)submit_btn = gr.Button("Generate Gaussian Splat", scale=1, variant="primary"71 unmodified linessubmit_btn.click(fn=generate_splats_from_images,inputs=[image_gallery, session_state],outputs=[reconstruction_output, rgb_video, depth_video])input_video.upload(10 unmodified linesdemo.unload(cleanup)demo.queue()demo.launch(show_error=True, share=True)81 unmodified lines8283848586878889909192939495144 unmodified lines2402412422432442452462472482492502514 unmodified lines25625725825926026126226326426526626726826927027163 unmodified lines33533633733833934034171 unmodified lines41341441541641741841910 unmodified lines43043143243381 unmodified lineswith open(output_path, "wb") as f:f.write(splat_data)def get_reconstructed_scene(outdir, model, device):image_files = sorted([os.path.join(outdir, "images", f)for f in os.listdir(os.path.join(outdir, "images"))])images = [process_image(img_path) for img_path in image_files]images = torch.stack(images, dim=0).unsqueeze(0).to(device) # [1, K, 3, 448, 448]b, v, c, h, w = images.shape144 unmodified linessession_id = uuid.uuid4().heximages_folder, image_paths = extract_frames(video_path, session_id)plyfile, rgb_vid, depth_vid = generate_splats_from_images(images_folder, session_id)return plyfile, rgb_vid, depth_vid, image_paths@spaces.GPU()def generate_splats_from_images(images_folder, session_id=None):if session_id is None:session_id = uuid.uuid4().hex4 unmodified linesbase_dir = os.path.join(os.environ["ANYSPLAT_PROCESSED"], session_id)all_files = (sorted(os.listdir(images_folder))if os.path.isdir(images_folder)else [])all_files = [f"{i}: {filename}" for i, filename in enumerate(all_files)]print("Running run_model...")with torch.no_grad():plyfile, video, depth_colored = get_reconstructed_scene(base_dir, model, device)end_time = time.time()print(f"Total time: {end_time - start_time:.2f} seconds (including IO)")63 unmodified lineswith gr.Tab("Video"):input_video = gr.Video(label="Upload Video", sources=["upload"], interactive=True, height=512)with gr.Tab("Images"):input_images = gr.File(file_count="multiple", label="Upload Files", height=512)submit_btn = gr.Button("Generate Gaussian Splat", scale=1, variant="primary"71 unmodified linessubmit_btn.click(fn=generate_splats_from_images,inputs=[target_dir_output, session_state],outputs=[reconstruction_output, rgb_video, depth_video])input_video.upload(10 unmodified linesdemo.unload(cleanup)demo.queue()demo.launch(show_error=True, share=True)
app.py+20-7