Spaces:
Paused
Paused
IceClear
commited on
Commit
·
c5715dc
1
Parent(s):
bf4296b
update
Browse files
app.py
CHANGED
|
@@ -11,9 +11,6 @@
|
|
| 11 |
# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
# // See the License for the specific language governing permissions and
|
| 13 |
# // limitations under the License.
|
| 14 |
-
from torchvision.transforms import functional as TVF
|
| 15 |
-
import spaces
|
| 16 |
-
from typing import Union
|
| 17 |
import os
|
| 18 |
import torch
|
| 19 |
import mediapy
|
|
@@ -24,6 +21,7 @@ import datetime
|
|
| 24 |
from tqdm import tqdm
|
| 25 |
import gc
|
| 26 |
|
|
|
|
| 27 |
from data.image.transforms.na_resize import NaResize
|
| 28 |
from data.video.transforms.rearrange import Rearrange
|
| 29 |
if os.path.exists("./projects/video_diffusion_sr/color_fix.py"):
|
|
@@ -36,6 +34,8 @@ from torchvision.transforms import Compose, Lambda, Normalize
|
|
| 36 |
from torchvision.io.video import read_video
|
| 37 |
import argparse
|
| 38 |
|
|
|
|
|
|
|
| 39 |
from common.distributed import (
|
| 40 |
get_device,
|
| 41 |
init_torch,
|
|
@@ -60,27 +60,6 @@ from pathlib import Path
|
|
| 60 |
from urllib.parse import urlparse
|
| 61 |
from torch.hub import download_url_to_file, get_dir
|
| 62 |
|
| 63 |
-
class DivisibleCrop:
|
| 64 |
-
def __init__(self, factor):
|
| 65 |
-
if not isinstance(factor, tuple):
|
| 66 |
-
factor = (factor, factor)
|
| 67 |
-
|
| 68 |
-
self.height_factor, self.width_factor = factor[0], factor[1]
|
| 69 |
-
|
| 70 |
-
def __call__(self, image: Union[torch.Tensor, Image.Image]):
|
| 71 |
-
if isinstance(image, torch.Tensor):
|
| 72 |
-
height, width = image.shape[-2:]
|
| 73 |
-
elif isinstance(image, Image.Image):
|
| 74 |
-
width, height = image.size
|
| 75 |
-
else:
|
| 76 |
-
raise NotImplementedError
|
| 77 |
-
|
| 78 |
-
cropped_height = height - (height % self.height_factor)
|
| 79 |
-
cropped_width = width - (width % self.width_factor)
|
| 80 |
-
|
| 81 |
-
image = TVF.center_crop(img=image, output_size=(cropped_height, cropped_width))
|
| 82 |
-
return image
|
| 83 |
-
|
| 84 |
def load_file_from_url(url, model_dir=None, progress=True, file_name=None):
|
| 85 |
"""Load file form http url, will download models if necessary.
|
| 86 |
|
|
@@ -149,7 +128,7 @@ def configure_sequence_parallel(sp_size):
|
|
| 149 |
if sp_size > 1:
|
| 150 |
init_sequence_parallel(sp_size)
|
| 151 |
|
| 152 |
-
@spaces.GPU(duration=
|
| 153 |
def configure_runner(sp_size):
|
| 154 |
config_path = os.path.join('./configs_3b', 'main.yaml')
|
| 155 |
config = load_config(config_path)
|
|
@@ -165,7 +144,7 @@ def configure_runner(sp_size):
|
|
| 165 |
runner.vae.set_memory_limit(**runner.config.vae.memory_limit)
|
| 166 |
return runner
|
| 167 |
|
| 168 |
-
@spaces.GPU(duration=
|
| 169 |
def generation_step(runner, text_embeds_dict, cond_latents):
|
| 170 |
def _move_to_cuda(x):
|
| 171 |
return [i.to(torch.device("cuda")) for i in x]
|
|
@@ -222,7 +201,7 @@ def generation_step(runner, text_embeds_dict, cond_latents):
|
|
| 222 |
|
| 223 |
return samples
|
| 224 |
|
| 225 |
-
@spaces.GPU(duration=
|
| 226 |
def generation_loop(video_path='./test_videos', output_dir='./results', seed=666, batch_size=1, cfg_scale=1.0, cfg_rescale=0.0, sample_steps=1, res_h=1280, res_w=720, sp_size=1):
|
| 227 |
runner = configure_runner(1)
|
| 228 |
output_dir = 'output/out.mp4'
|
|
|
|
| 11 |
# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
# // See the License for the specific language governing permissions and
|
| 13 |
# // limitations under the License.
|
|
|
|
|
|
|
|
|
|
| 14 |
import os
|
| 15 |
import torch
|
| 16 |
import mediapy
|
|
|
|
| 21 |
from tqdm import tqdm
|
| 22 |
import gc
|
| 23 |
|
| 24 |
+
from data.image.transforms.divisible_crop import DivisibleCrop
|
| 25 |
from data.image.transforms.na_resize import NaResize
|
| 26 |
from data.video.transforms.rearrange import Rearrange
|
| 27 |
if os.path.exists("./projects/video_diffusion_sr/color_fix.py"):
|
|
|
|
| 34 |
from torchvision.io.video import read_video
|
| 35 |
import argparse
|
| 36 |
|
| 37 |
+
import spaces
|
| 38 |
+
|
| 39 |
from common.distributed import (
|
| 40 |
get_device,
|
| 41 |
init_torch,
|
|
|
|
| 60 |
from urllib.parse import urlparse
|
| 61 |
from torch.hub import download_url_to_file, get_dir
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
def load_file_from_url(url, model_dir=None, progress=True, file_name=None):
|
| 64 |
"""Load file form http url, will download models if necessary.
|
| 65 |
|
|
|
|
| 128 |
if sp_size > 1:
|
| 129 |
init_sequence_parallel(sp_size)
|
| 130 |
|
| 131 |
+
@spaces.GPU(duration=120)
|
| 132 |
def configure_runner(sp_size):
|
| 133 |
config_path = os.path.join('./configs_3b', 'main.yaml')
|
| 134 |
config = load_config(config_path)
|
|
|
|
| 144 |
runner.vae.set_memory_limit(**runner.config.vae.memory_limit)
|
| 145 |
return runner
|
| 146 |
|
| 147 |
+
@spaces.GPU(duration=120)
|
| 148 |
def generation_step(runner, text_embeds_dict, cond_latents):
|
| 149 |
def _move_to_cuda(x):
|
| 150 |
return [i.to(torch.device("cuda")) for i in x]
|
|
|
|
| 201 |
|
| 202 |
return samples
|
| 203 |
|
| 204 |
+
@spaces.GPU(duration=120)
|
| 205 |
def generation_loop(video_path='./test_videos', output_dir='./results', seed=666, batch_size=1, cfg_scale=1.0, cfg_rescale=0.0, sample_steps=1, res_h=1280, res_w=720, sp_size=1):
|
| 206 |
runner = configure_runner(1)
|
| 207 |
output_dir = 'output/out.mp4'
|