Spaces:
Running
on
Zero
Running
on
Zero
File size: 10,531 Bytes
df13f4b b20f9b9 df13f4b 58423c5 b20f9b9 1f198ea 20f5dc1 df13f4b f29f494 df13f4b 58423c5 33fe5f3 58423c5 33fe5f3 58423c5 df13f4b f29f494 06a530c 58423c5 7ccdbd8 1f198ea 7ccdbd8 1f198ea 29dd4d7 58423c5 9681ac8 5cca3bb 9681ac8 579479d 7ccdbd8 df13f4b 58423c5 33fe5f3 30b2c1f 33fe5f3 df13f4b d1813ed df13f4b 061726b df13f4b 58423c5 33fe5f3 ec0c93a 58423c5 33fe5f3 30b2c1f 33fe5f3 58423c5 33fe5f3 ec0c93a 33fe5f3 ec0c93a 33fe5f3 58423c5 df13f4b 33fe5f3 df13f4b 7ccdbd8 58423c5 33fe5f3 df13f4b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
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',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=False)
elif mode == 'Right':
return gr.update(value='0 35; 0 0; 0 0',visible=True),gr.update(visible=False)
elif mode == 'Up':
return gr.update(value='0 0; 0 -30; 0 0',visible=True),gr.update(visible=False)
elif mode == 'Down':
return gr.update(value='0 0; 0 20; 0 0',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=False)
elif mode == 'Zoom out':
return gr.update(value='0 0; 0 0; 0 0.4',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)
elif mode == 'Reset':
return gr.update(value='0 0; 0 0; 0 0',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_both = spaces.GPU(image2video.run_both, duration=290) # fixme
with gr.Blocks(analytics_enabled=False, css=css) as viewcrafter_iface:
gr.Markdown("<div align='center'> <h1> ViewCrafter: Taming Video Diffusion Models for High-fidelity Novel View Synthesis </span> </h1> \
<h2 style='font-weight: 450; font-size: 1rem; margin: 0rem'>\
<a href='https://scholar.google.com/citations?user=UOE8-qsAAAAJ&hl=zh-CN'>Wangbo Yu</a>, \
<a href='https://doubiiu.github.io/'>Jinbo Xing</a>, <a href=''>Li Yuan</a>, \
<a href='https://wbhu.github.io/'>Wenbo Hu</a>, <a href='https://xiaoyu258.github.io/'>Xiaoyu Li</a>,\
<a href=''>Zhipeng Huang</a>, <a href='https://scholar.google.com/citations?user=qgdesEcAAAAJ&hl=en/'>Xiangjun Gao</a>,\
<a href='https://www.cse.cuhk.edu.hk/~ttwong/myself.html/'>Tien-Tsin Wong</a>,\
<a href='https://scholar.google.com/citations?hl=en&user=4oXBp9UAAAAJ&view_op=list_works&sortby=pubdate/'>Ying Shan</a>\
<a href=''>Yonghong Tian</a>\
</h2> \
<a style='font-size:18px;color: #000000' href='https://arxiv.org/abs/2409.02048'> [ArXiv] </a>\
<a style='font-size:18px;color: #000000' href='https://drexubery.github.io/ViewCrafter/'> [Project Page] </a>\
<a style='font-size:18px;color: #FF5DB0' href='https://github.com/Drexubery/ViewCrafter'> [Github] </a>\
<a style='font-size:18px;color: #000000' href='https://www.youtube.com/watch?v=WGIEmu9eXmU'> [Video] </a> </div>")
with gr.Row():
with gr.Column():
# # step 1: input an image
# gr.Markdown("---\n## Step 1: Input an Image, selet an elevation angle and a center_scale factor", show_label=False, visible=True)
# gr.Markdown("<div align='left' style='font-size:18px;color: #000000'>1. Estimate an elevation angle that represents the angle at which the image was taken; a value bigger than 0 indicates a top-down view, and it doesn't need to be precise. <br>2. The origin of the world coordinate system is by default defined at the point cloud corresponding to the center pixel of the input image. You can adjust the position of the origin by modifying center_scale; a value smaller than 1 brings the origin closer to you.</div>")
with gr.Column():
i2v_input_image = gr.Image(label="Input Image",elem_id="input_img")
with gr.Row():
i2v_elevation = gr.Slider(minimum=-45, maximum=45, step=1, elem_id="elevation", label="elevation", value=5)
i2v_center_scale = gr.Slider(minimum=0.1, maximum=2, step=0.1, elem_id="i2v_center_scale", label="center_scale", value=1)
with gr.Column():
with gr.Row():
left = gr.Button(value = "Left")
right = gr.Button(value = "Right")
up = gr.Button(value = "Up")
with gr.Row():
down = gr.Button(value = "Down")
zin = gr.Button(value = "Zoom in")
zout = gr.Button(value = "Zoom out")
with gr.Row():
custom = gr.Button(value = "Customize")
reset = gr.Button(value = "Reset")
with gr.Column():
with gr.Row():
with gr.Column():
i2v_pose = gr.Text(value = '0 0; 0 0; 0 0', label="Camera trajectory (d_phi sequence; d_theta sequence; d_r sequence)",visible=False)
with gr.Column(visible=False) as i2v_egs:
gr.Markdown("<div align='left' style='font-size:18px;color: #000000'>Please refer to the <a href='https://github.com/Drexubery/ViewCrafter/blob/main/docs/gradio_tutorial.md' target='_blank'>tutorial</a> for customizing camera trajectory.</div>")
gr.Examples(examples=traj_examples,
inputs=[i2v_pose],
)
# step 3 - Generate video
with gr.Column():
# gr.Markdown("---\n## Step 3: Generate video", show_label=False, visible=True)
# gr.Markdown("<div align='left' style='font-size:18px;color: #000000'> You can reduce the sampling steps for faster inference; try different random seed if the result is not satisfying. </div>")
i2v_output_video = gr.Video(label="Generated Video",elem_id="output_vid",autoplay=True,show_share_button=True)
with gr.Row():
i2v_steps = gr.Slider(minimum=1, maximum=50, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
i2v_seed = gr.Slider(label='Random seed', minimum=0, maximum=max_seed, step=1, value=0)
i2v_end_btn = gr.Button("Generate video")
i2v_traj_video = gr.Video(label="Camera Trajectory",elem_id="traj_vid",autoplay=True,show_share_button=True)
gr.Examples(examples=img_examples,
inputs=[i2v_input_image,i2v_elevation, i2v_center_scale,],
# examples_per_page=6
)
i2v_end_btn.click(inputs=[i2v_input_image, i2v_elevation, i2v_center_scale, i2v_pose, i2v_steps, i2v_seed],
outputs=[i2v_output_video,i2v_traj_video],
fn = image2video.run_both
)
left.click(inputs=[left],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
right.click(inputs=[right],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
up.click(inputs=[up],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
down.click(inputs=[down],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
zin.click(inputs=[zin],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
zout.click(inputs=[zout],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
custom.click(inputs=[custom],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
reset.click(inputs=[reset],
outputs=[i2v_pose,i2v_egs],
fn = show_traj
)
return viewcrafter_iface
viewcrafter_iface = viewcrafter_demo(opts)
viewcrafter_iface.queue(max_size=10)
viewcrafter_iface.launch() #fixme
# viewcrafter_iface.launch(server_name='11.220.92.96', server_port=80, max_threads=10,debug=True)
|