Drexubery commited on
Commit
38c4bd2
1 Parent(s): 06a530c
Files changed (3) hide show
  1. app.py +2 -5
  2. app_bad.py +114 -0
  3. viewcrafter.py +0 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import torch
3
  import sys
 
4
 
5
  # os.system('pip install iopath')
6
  # os.system("pip install -v -v -v 'git+https://github.com/facebookresearch/pytorch3d.git@stable'")
@@ -32,16 +33,12 @@ def download_model():
32
  if not os.path.exists(local_file):
33
  hf_hub_download(repo_id=REPO_ID, filename=filename, local_dir='./checkpoints/', force_download=True)
34
 
35
- REPO_ID = 'naver/DUSt3R_ViTLarge_BaseDecoder_512_dpt'
36
-
37
-
38
-
39
-
40
  download_model()
41
 
42
  def viewcrafter_demo(opts):
43
  css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}"""
44
  image2video = ViewCrafter(opts, gradio = True)
 
45
  with gr.Blocks(analytics_enabled=False, css=css) as viewcrafter_iface:
46
  gr.Markdown("<div align='center'> <h1> ViewCrafter: Taming Video Diffusion Models for High-fidelity Novel View Synthesis </span> </h1> \
47
  <h2 style='font-weight: 450; font-size: 1rem; margin: 0rem'>\
 
1
  import os
2
  import torch
3
  import sys
4
+ import spaces
5
 
6
  # os.system('pip install iopath')
7
  # os.system("pip install -v -v -v 'git+https://github.com/facebookresearch/pytorch3d.git@stable'")
 
33
  if not os.path.exists(local_file):
34
  hf_hub_download(repo_id=REPO_ID, filename=filename, local_dir='./checkpoints/', force_download=True)
35
 
 
 
 
 
 
36
  download_model()
37
 
38
  def viewcrafter_demo(opts):
39
  css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}"""
40
  image2video = ViewCrafter(opts, gradio = True)
41
+ image2video.run_gradio = spaces.GPU(image2video.run_gradio, duration=120)
42
  with gr.Blocks(analytics_enabled=False, css=css) as viewcrafter_iface:
43
  gr.Markdown("<div align='center'> <h1> ViewCrafter: Taming Video Diffusion Models for High-fidelity Novel View Synthesis </span> </h1> \
44
  <h2 style='font-weight: 450; font-size: 1rem; margin: 0rem'>\
app_bad.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import sys
4
+
5
+ # os.system('pip install iopath')
6
+ # os.system("pip install -v -v -v 'git+https://github.com/facebookresearch/pytorch3d.git@stable'")
7
+ # os.system("cd pytorch3d && pip install -e . && cd ..")
8
+ os.system("pip install 'git+https://github.com/facebookresearch/pytorch3d.git'")
9
+
10
+
11
+ import gradio as gr
12
+ import random
13
+ from viewcrafter import ViewCrafter
14
+ from configs.infer_config import get_parser
15
+ from huggingface_hub import hf_hub_download
16
+
17
+ i2v_examples = [
18
+ ['test/images/boy.png', 0, 1.0, '0 40', '0 0', '0 0', 50, 123],
19
+ ['test/images/car.jpeg', 0, 1.0, '0 -35', '0 0', '0 -0.1', 50, 123],
20
+ ['test/images/fruit.jpg', 0, 1.0, '0 -3 -15 -20 -17 -5 0', '0 -2 -5 -10 -8 -5 0 2 5 3 0', '0 0', 50, 123],
21
+ ['test/images/room.png', 5, 1.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', 50, 123],
22
+ ['test/images/castle.png', 0, 1.0, '0 30', '0 -1 -5 -4 0 1 5 4 0', '0 -0.2', 50, 123],
23
+ ]
24
+
25
+ max_seed = 2 ** 31
26
+
27
+ def download_model():
28
+ REPO_ID = 'Drexubery/ViewCrafter_25'
29
+ filename_list = ['model.ckpt']
30
+ for filename in filename_list:
31
+ local_file = os.path.join('./checkpoints/', filename)
32
+ if not os.path.exists(local_file):
33
+ hf_hub_download(repo_id=REPO_ID, filename=filename, local_dir='./checkpoints/', force_download=True)
34
+
35
+ REPO_ID = 'naver/DUSt3R_ViTLarge_BaseDecoder_512_dpt'
36
+
37
+ download_model()
38
+
39
+ def viewcrafter_demo(opts):
40
+ css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}"""
41
+ image2video = ViewCrafter(opts, gradio = True)
42
+ with gr.Blocks(analytics_enabled=False, css=css) as viewcrafter_iface:
43
+ gr.Markdown("<div align='center'> <h1> ViewCrafter: Taming Video Diffusion Models for High-fidelity Novel View Synthesis </span> </h1> \
44
+ <h2 style='font-weight: 450; font-size: 1rem; margin: 0rem'>\
45
+ <a href='https://scholar.google.com/citations?user=UOE8-qsAAAAJ&hl=zh-CN'>Wangbo Yu</a>, \
46
+ <a href='https://doubiiu.github.io/'>Jinbo Xing</a>, <a href=''>Li Yuan</a>, \
47
+ <a href='https://wbhu.github.io/'>Wenbo Hu</a>, <a href='https://xiaoyu258.github.io/'>Xiaoyu Li</a>,\
48
+ <a href=''>Zhipeng Huang</a>, <a href='https://scholar.google.com/citations?user=qgdesEcAAAAJ&hl=en/'>Xiangjun Gao</a>,\
49
+ <a href='https://www.cse.cuhk.edu.hk/~ttwong/myself.html/'>Tien-Tsin Wong</a>,\
50
+ <a href='https://scholar.google.com/citations?hl=en&user=4oXBp9UAAAAJ&view_op=list_works&sortby=pubdate/'>Ying Shan</a>\
51
+ <a href=''>Yonghong Tian</a>\
52
+ </h2> \
53
+ <a style='font-size:18px;color: #FF5DB0' href='https://github.com/Drexubery/ViewCrafter/blob/main/docs/render_help.md'> [Guideline] </a>\
54
+ <a style='font-size:18px;color: #000000' href=''> [ArXiv] </a>\
55
+ <a style='font-size:18px;color: #000000' href='https://drexubery.github.io/ViewCrafter/'> [Project Page] </a>\
56
+ <a style='font-size:18px;color: #000000' href='https://github.com/Drexubery/ViewCrafter'> [Github] </a> </div>")
57
+
58
+ #######image2video######
59
+ with gr.Tab(label="ViewCrafter_25, 'single_view_txt' mode"):
60
+ with gr.Column():
61
+ with gr.Row():
62
+ with gr.Column():
63
+ with gr.Row():
64
+ i2v_input_image = gr.Image(label="Input Image",elem_id="input_img")
65
+ with gr.Row():
66
+ i2v_elevation = gr.Slider(minimum=-45, maximum=45, step=1, elem_id="elevation", label="elevation", value=5)
67
+ with gr.Row():
68
+ i2v_center_scale = gr.Slider(minimum=0.1, maximum=2, step=0.1, elem_id="i2v_center_scale", label="center_scale", value=1)
69
+ with gr.Row():
70
+ i2v_d_phi = gr.Text(label='d_phi sequence, should start with 0')
71
+ with gr.Row():
72
+ i2v_d_theta = gr.Text(label='d_theta sequence, should start with 0')
73
+ with gr.Row():
74
+ i2v_d_r = gr.Text(label='d_r sequence, should start with 0')
75
+ with gr.Row():
76
+ i2v_steps = gr.Slider(minimum=1, maximum=50, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
77
+ with gr.Row():
78
+ i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123)
79
+ i2v_end_btn = gr.Button("Generate")
80
+ # with gr.Tab(label='Result'):
81
+ with gr.Column():
82
+ with gr.Row():
83
+ i2v_traj_video = gr.Video(label="Camera Trajectory",elem_id="traj_vid",autoplay=True,show_share_button=True)
84
+ with gr.Row():
85
+ i2v_output_video = gr.Video(label="Generated Video",elem_id="output_vid",autoplay=True,show_share_button=True)
86
+
87
+ gr.Examples(examples=i2v_examples,
88
+ inputs=[i2v_input_image, i2v_elevation, i2v_center_scale, i2v_d_phi, i2v_d_theta, i2v_d_r, i2v_steps, i2v_seed],
89
+ outputs=[i2v_traj_video,i2v_output_video],
90
+ fn = image2video.run_gradio,
91
+ cache_examples=False,
92
+ )
93
+
94
+ # image2video.run_gradio(i2v_input_image='test/images/boy.png', i2v_elevation='10', i2v_d_phi='0 40', i2v_d_theta='0 0', i2v_d_r='0 0', i2v_center_scale=1, i2v_steps=50, i2v_seed=123)
95
+ i2v_end_btn.click(inputs=[i2v_input_image, i2v_elevation, i2v_center_scale, i2v_d_phi, i2v_d_theta, i2v_d_r, i2v_steps, i2v_seed],
96
+ outputs=[i2v_traj_video,i2v_output_video],
97
+ fn = image2video.run_gradio
98
+ )
99
+
100
+ return viewcrafter_iface
101
+
102
+
103
+ if __name__ == "__main__":
104
+ parser = get_parser() # infer_config.py
105
+ opts = parser.parse_args() # default device: 'cuda:0'
106
+ opts.save_dir = './'
107
+ os.makedirs(opts.save_dir,exist_ok=True)
108
+ test_tensor = torch.Tensor([0]).cuda()
109
+ opts.device = str(test_tensor.device)
110
+ viewcrafter_iface = viewcrafter_demo(opts)
111
+ viewcrafter_iface.queue(max_size=10)
112
+ viewcrafter_iface.launch()
113
+ # viewcrafter_iface.launch(server_name='127.0.0.1', server_port=80, max_threads=1,debug=False)
114
+
viewcrafter.py CHANGED
@@ -25,7 +25,6 @@ from pytorch_lightning import seed_everything
25
  from utils.diffusion_utils import instantiate_from_config,load_model_checkpoint,image_guided_synthesis
26
  from pathlib import Path
27
  from torchvision.utils import save_image
28
- import spaces
29
 
30
  class ViewCrafter:
31
  def __init__(self, opts, gradio = False):
@@ -342,7 +341,6 @@ class ViewCrafter:
342
 
343
  return images, img_ori
344
 
345
- @spaces.GPU(duration=300)
346
  def run_gradio(self,i2v_input_image, i2v_elevation, i2v_center_scale, i2v_d_phi, i2v_d_theta, i2v_d_r, i2v_steps, i2v_seed):
347
  self.opts.elevation = float(i2v_elevation)
348
  self.opts.center_scale = float(i2v_center_scale)
 
25
  from utils.diffusion_utils import instantiate_from_config,load_model_checkpoint,image_guided_synthesis
26
  from pathlib import Path
27
  from torchvision.utils import save_image
 
28
 
29
  class ViewCrafter:
30
  def __init__(self, opts, gradio = False):
 
341
 
342
  return images, img_ori
343
 
 
344
  def run_gradio(self,i2v_input_image, i2v_elevation, i2v_center_scale, i2v_d_phi, i2v_d_theta, i2v_d_r, i2v_steps, i2v_seed):
345
  self.opts.elevation = float(i2v_elevation)
346
  self.opts.center_scale = float(i2v_center_scale)