2022-11-21 09:49:33 +00:00
|
|
|
# Copyright 2022 Lunar Ring. All rights reserved.
|
2023-01-11 11:58:59 +00:00
|
|
|
# Written by Johannes Stelzer, email stelzer@lunar-ring.ai twitter @j_stelzer
|
2022-11-21 09:49:33 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# 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 torch
|
|
|
|
torch.backends.cudnn.benchmark = False
|
2023-02-22 09:15:03 +00:00
|
|
|
torch.set_grad_enabled(False)
|
2022-11-21 09:49:33 +00:00
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings('ignore')
|
|
|
|
import warnings
|
2023-02-22 09:15:03 +00:00
|
|
|
from latent_blending import LatentBlending
|
2023-07-20 11:49:19 +00:00
|
|
|
from diffusers_holder import DiffusersHolder
|
|
|
|
from diffusers import DiffusionPipeline
|
2023-02-18 07:19:40 +00:00
|
|
|
|
2023-02-22 09:15:03 +00:00
|
|
|
# %% First let us spawn a stable diffusion holder. Uncomment your version of choice.
|
2023-10-13 09:58:25 +00:00
|
|
|
pretrained_model_name_or_path = "stabilityai/stable-diffusion-xl-base-1.0"
|
2023-07-20 11:49:19 +00:00
|
|
|
pipe = DiffusionPipeline.from_pretrained(pretrained_model_name_or_path, torch_dtype=torch.float16)
|
|
|
|
pipe.to('cuda')
|
|
|
|
dh = DiffusersHolder(pipe)
|
2023-02-22 09:15:03 +00:00
|
|
|
# %% Next let's set up all parameters
|
2023-07-20 11:49:19 +00:00
|
|
|
depth_strength = 0.55 # Specifies how deep (in terms of diffusion iterations the first branching happens)
|
|
|
|
t_compute_max_allowed = 60 # Determines the quality of the transition in terms of compute time you grant it
|
|
|
|
num_inference_steps = 50
|
2023-10-13 09:58:25 +00:00
|
|
|
size_output = (1024, 768)
|
2023-02-22 09:15:03 +00:00
|
|
|
|
2023-07-20 11:49:19 +00:00
|
|
|
prompt1 = "underwater landscape, fish, und the sea, incredible detail, high resolution"
|
|
|
|
prompt2 = "rendering of an alien planet, strange plants, strange creatures, surreal"
|
2022-11-28 17:14:20 +00:00
|
|
|
|
2023-02-18 07:19:40 +00:00
|
|
|
fp_movie = 'movie_example1.mp4'
|
2023-02-22 09:15:03 +00:00
|
|
|
duration_transition = 12 # In seconds
|
2022-12-03 10:55:54 +00:00
|
|
|
|
|
|
|
# Spawn latent blending
|
2023-07-20 11:49:19 +00:00
|
|
|
lb = LatentBlending(dh)
|
2022-11-21 09:49:33 +00:00
|
|
|
lb.set_prompt1(prompt1)
|
|
|
|
lb.set_prompt2(prompt2)
|
2023-10-13 09:58:25 +00:00
|
|
|
lb.set_dimensions(size_output)
|
2023-02-17 09:51:38 +00:00
|
|
|
|
2022-12-03 10:55:54 +00:00
|
|
|
# Run latent blending
|
2023-02-18 07:19:40 +00:00
|
|
|
lb.run_transition(
|
2023-02-22 09:15:03 +00:00
|
|
|
depth_strength=depth_strength,
|
2023-07-20 11:49:19 +00:00
|
|
|
num_inference_steps=num_inference_steps,
|
2023-10-13 09:58:25 +00:00
|
|
|
t_compute_max_allowed=t_compute_max_allowed)
|
2023-02-17 09:51:38 +00:00
|
|
|
|
2023-02-18 07:19:40 +00:00
|
|
|
# Save movie
|
2023-02-22 09:15:03 +00:00
|
|
|
lb.write_movie_transition(fp_movie, duration_transition)
|