# build upon InstantSplat https://huggingface.co/spaces/kairunwen/InstantSplat/blob/main/app.py import os, subprocess, shlex, sys, gc import numpy as np import shutil import argparse import gradio as gr import uuid import glob import re import torch import spaces subprocess.run(shlex.split("pip install wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/simple_knn-0.0.0-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/curope-0.0.0-cp310-cp310-linux_x86_64.whl")) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) os.sys.path.append(os.path.abspath(os.path.join(BASE_DIR, "dynamic_predictor"))) os.sys.path.append(os.path.abspath(os.path.join(BASE_DIR))) GRADIO_CACHE_FOLDER = './gradio_cache_folder' from dynamic_predictor.launch import main as dynamic_predictor_main from utils_das3r.rearrange import main as rearrange_main from train_gui import main as train_main from render import main as render_main def natural_sort(l): convert = lambda text: int(text) if text.isdigit() else text.lower() alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key.split('/')[-1])] return sorted(l, key=alphanum_key) def cmd(command): print(command) os.system(command) @spaces.GPU(duration=150) def process(inputfiles, input_path='demo'): if inputfiles: frames = natural_sort(inputfiles) else: frames = natural_sort(glob.glob('./assets/example/' + input_path + '/*')) if len(frames) > 20: stride = int(np.ceil(len(frames) / 20)) frames = frames[::stride] # Create a temporary directory to store the selected frames temp_dir = os.path.join(GRADIO_CACHE_FOLDER, str(uuid.uuid4())) os.makedirs(temp_dir, exist_ok=True) # Copy the selected frames to the temporary directory for i, frame in enumerate(frames): shutil.copy(frame, f"{temp_dir}/{i:04d}.{frame.split('.')[-1]}") imgs_path = temp_dir output_path = f'./results/{input_path}/output' rearranged_path = f'{output_path}_rearranged' # cmd(f"python dynamic_predictor/launch.py --mode=eval_pose_custom \ # --pretrained=Kai422kx/das3r \ # --dir_path={imgs_path} \ # --output_dir={output_path} \ # --use_pred_mask ") dynamic_predictor_main(pretrained='Kai422kx/das3r', dir_path=imgs_path, output_dir=output_path, use_pred_mask=True, n_iter=150) rearrange_main(output_dir=output_path, rearranged_path = rearranged_path) train_main(s = rearranged_path, m = rearranged_path, iter = 2000) render_main(s = rearranged_path, m = rearranged_path, iter = 2000, get_video = True) output_video_path = f"{rearranged_path}/rendered.mp4" output_ply_path = f"{rearranged_path}/point_cloud/iteration_2000/point_cloud.ply" return output_video_path, output_ply_path, output_ply_path _TITLE = '''DAS3R''' _DESCRIPTION = '''