latentblending/example1_standard.py

55 lines
2.2 KiB
Python
Raw Normal View History

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
from stable_diffusion_holder import StableDiffusionHolder
2023-02-22 09:15:03 +00:00
from huggingface_hub import hf_hub_download
2022-11-21 09:49:33 +00:00
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.
# fp_ckpt = hf_hub_download(repo_id="stabilityai/stable-diffusion-2-1-base", filename="v2-1_512-ema-pruned.ckpt")
fp_ckpt = hf_hub_download(repo_id="stabilityai/stable-diffusion-2-1", filename="v2-1_768-ema-pruned.ckpt")
2023-01-12 09:06:02 +00:00
sdh = StableDiffusionHolder(fp_ckpt)
2023-02-22 09:15:03 +00:00
# %% Next let's set up all parameters
depth_strength = 0.65 # Specifies how deep (in terms of diffusion iterations the first branching happens)
t_compute_max_allowed = 15 # Determines the quality of the transition in terms of compute time you grant it
fixed_seeds = [69731932, 504430820]
2023-02-22 09:15:03 +00:00
2023-01-09 07:52:53 +00:00
prompt1 = "photo of a beautiful cherry forest covered in white flowers, ambient light, very detailed, magic"
prompt2 = "photo of an golden statue with a funny hat, surrounded by ferns and vines, grainy analog photograph, mystical ambience, incredible detail"
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
2022-11-28 17:14:20 +00:00
lb = LatentBlending(sdh)
2022-11-21 09:49:33 +00:00
lb.set_prompt1(prompt1)
lb.set_prompt2(prompt2)
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,
t_compute_max_allowed=t_compute_max_allowed,
fixed_seeds=fixed_seeds)
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)