Spaces:
Build error
Build error
IceClear commited on
Commit ·
c5715dc
1
Parent(s): bf4296b
update
Browse files10 unmodified lines1112131415161718194 unmodified lines2425262728296 unmodified lines36373839404118 unmodified lines60616263646566676869707172737475767778798081828384858662 unmodified lines1491501511521531541559 unmodified lines16516616716816917017150 unmodified lines22222322422522622722810 unmodified lines# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# // See the License for the specific language governing permissions and# // limitations under the License.from torchvision.transforms import functional as TVFimport spacesfrom typing import Unionimport osimport torchimport mediapy4 unmodified linesfrom tqdm import tqdmimport gcfrom data.image.transforms.na_resize import NaResizefrom data.video.transforms.rearrange import Rearrangeif os.path.exists("./projects/video_diffusion_sr/color_fix.py"):6 unmodified linesfrom torchvision.io.video import read_videoimport argparsefrom common.distributed import (get_device,init_torch,18 unmodified linesfrom urllib.parse import urlparsefrom torch.hub import download_url_to_file, get_dirclass DivisibleCrop:def __init__(self, factor):if not isinstance(factor, tuple):factor = (factor, factor)self.height_factor, self.width_factor = factor[0], factor[1]def __call__(self, image: Union[torch.Tensor, Image.Image]):if isinstance(image, torch.Tensor):height, width = image.shape[-2:]elif isinstance(image, Image.Image):width, height = image.sizeelse:raise NotImplementedErrorcropped_height = height - (height % self.height_factor)cropped_width = width - (width % self.width_factor)image = TVF.center_crop(img=image, output_size=(cropped_height, cropped_width))return imagedef load_file_from_url(url, model_dir=None, progress=True, file_name=None):"""Load file form http url, will download models if necessary.62 unmodified linesif sp_size > 1:init_sequence_parallel(sp_size)@spaces.GPU(duration=90)def configure_runner(sp_size):config_path = os.path.join('./configs_3b', 'main.yaml')config = load_config(config_path)9 unmodified linesrunner.vae.set_memory_limit(**runner.config.vae.memory_limit)return runner@spaces.GPU(duration=90)def generation_step(runner, text_embeds_dict, cond_latents):def _move_to_cuda(x):return [i.to(torch.device("cuda")) for i in x]50 unmodified linesreturn samples@spaces.GPU(duration=90)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):runner = configure_runner(1)output_dir = 'output/out.mp4'10 unmodified lines1112131415164 unmodified lines212223242526276 unmodified lines343536373839404118 unmodified lines60616263646562 unmodified lines1281291301311321331349 unmodified lines14414514614714814915050 unmodified lines20120220320420520620710 unmodified lines# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# // See the License for the specific language governing permissions and# // limitations under the License.import osimport torchimport mediapy4 unmodified linesfrom tqdm import tqdmimport gcfrom data.image.transforms.divisible_crop import DivisibleCropfrom data.image.transforms.na_resize import NaResizefrom data.video.transforms.rearrange import Rearrangeif os.path.exists("./projects/video_diffusion_sr/color_fix.py"):6 unmodified linesfrom torchvision.io.video import read_videoimport argparseimport spacesfrom common.distributed import (get_device,init_torch,18 unmodified linesfrom urllib.parse import urlparsefrom torch.hub import download_url_to_file, get_dirdef load_file_from_url(url, model_dir=None, progress=True, file_name=None):"""Load file form http url, will download models if necessary.62 unmodified linesif sp_size > 1:init_sequence_parallel(sp_size)@spaces.GPU(duration=120)def configure_runner(sp_size):config_path = os.path.join('./configs_3b', 'main.yaml')config = load_config(config_path)9 unmodified linesrunner.vae.set_memory_limit(**runner.config.vae.memory_limit)return runner@spaces.GPU(duration=120)def generation_step(runner, text_embeds_dict, cond_latents):def _move_to_cuda(x):return [i.to(torch.device("cuda")) for i in x]50 unmodified linesreturn samples@spaces.GPU(duration=120)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):runner = configure_runner(1)output_dir = 'output/out.mp4'
app.py+6-27