import os import torch import sys # import spaces #fixme import random import gradio as gr import random from configs.infer_config import get_parser from huggingface_hub import hf_hub_download traj_examples = [ ['0 -35; 0 0; 0 -0.1'], ['0 -3 -15 -20 -17 -5 0; 0 -2 -5 -10 -8 -5 0 2 5 3 0; 0 0'], ['0 3 10 20 17 10 0; 0 -2 -8 -6 0 2 5 3 0; 0 -0.02 -0.09 -0.16 -0.09 0'], ['0 30; 0 -1 -5 -4 0 1 5 4 0; 0 -0.2'], ] # img_examples = [ # ['test/images/boy.png'], # ['test/images/car.jpeg'], # ['test/images/fruit.jpg'], # ['test/images/room.png'], # ['test/images/castle.png'], # ] img_examples = [ ['test/images/boy.png',0,1], ['test/images/car.jpeg',5,1], ['test/images/fruit.jpg',5,1], ['test/images/room.png',10,1], ['test/images/castle.png',-4,1], ] max_seed = 2 ** 31 def download_model(): REPO_ID = 'Drexubery/ViewCrafter_25' filename_list = ['model.ckpt'] for filename in filename_list: local_file = os.path.join('./checkpoints/', filename) if not os.path.exists(local_file): hf_hub_download(repo_id=REPO_ID, filename=filename, local_dir='./checkpoints/', force_download=True) # download_model() #fixme parser = get_parser() # infer_config.py opts = parser.parse_args() # default device: 'cuda:0' tmp = str(random.randint(10**(5-1), 10**5 - 1)) opts.save_dir = f'./{tmp}' os.makedirs(opts.save_dir,exist_ok=True) test_tensor = torch.Tensor([0]).cuda() opts.device = str(test_tensor.device) # opts.config = './configs/inference_pvd_1024_gradio.yaml' #fixme opts.config = './configs/inference_pvd_1024_local.yaml' #fixme # # install pytorch3d # fixme # pyt_version_str=torch.__version__.split("+")[0].replace(".", "") # version_str="".join([ # f"py3{sys.version_info.minor}_cu", # torch.version.cuda.replace(".",""), # f"_pyt{pyt_version_str}" # ]) # print(version_str) # os.system(f"{sys.executable} -m pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/download.html") # os.system("mkdir -p checkpoints/ && wget https://download.europe.naverlabs.com/ComputerVision/DUSt3R/DUSt3R_ViTLarge_BaseDecoder_512_dpt.pth -P checkpoints/") # print(f'>>> System info: {version_str}') from viewcrafter import ViewCrafter CAMERA_MOTION_MODE = ["Basic Camera Trajectory", "Custom Camera Trajectory"] def show_traj(mode): if mode == 'Left': return gr.update(value='0 -35; 0 0; 0 0',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=False) elif mode == 'Right': return gr.update(value='0 35; 0 0; 0 0',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=False) elif mode == 'Up': return gr.update(value='0 0; 0 -30; 0 0',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=False) elif mode == 'Down': return gr.update(value='0 0; 0 20; 0 0',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=False) elif mode == 'Zoom in': return gr.update(value='0 0; 0 0; 0 -0.4',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=False) elif mode == 'Zoom out': return gr.update(value='0 0; 0 0; 0 0.4',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=False) elif mode == 'Customize': return gr.update(value='0 0; 0 0; 0 0',visible=True), gr.update(visible=True), gr.update(visible=True),gr.update(visible=True) elif mode == 'Reset': return gr.update(value='0 0; 0 0; 0 0',visible=False), gr.update(visible=False), gr.update(visible=False),gr.update(visible=False) def viewcrafter_demo(opts): css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}""" image2video = ViewCrafter(opts, gradio = True) # image2video.run_traj_basic = spaces.GPU(image2video.run_traj_basic, duration=50) # fixme # image2video.run_traj = spaces.GPU(image2video.run_traj, duration=50) # fixme # image2video.run_gen = spaces.GPU(image2video.run_gen, duration=260) # fixme with gr.Blocks(analytics_enabled=False, css=css) as viewcrafter_iface: gr.Markdown("