Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import os
- import string
- import json
- import cv2
- from datetime import datetime
- from tqdm import tqdm
- from ldm.simplet2i import T2I
- from random import choice
- import PIL
- from PIL.Image import Resampling
- import math
- _t2i = T2I()
- def get_folder_name(prompt = ""):
- now = datetime.now()
- prompt_parts = prompt.split()
- first_word = prompt_parts[0] if len(prompt_parts) > 0 else ""
- h, m, s = (str(t).ljust(2, "0") for t in [now.hour, now.minute, now.second])
- return f"{first_word}-{now.year}-{now.month}-{now.day}-{h}{m}{s}"
- def get_vid_path(prompt = ""):
- return os.path.join(".", "outputs", "vid-samples", get_folder_name(prompt))
- def prompt2vid(**config):
- prompt = config["prompt"]
- n_frames = config["n_frames"]
- #initial_image = config["init_img"]
- fps = config["fps"] if "fps" in config else 30.0
- cfg_scale = config["cfg_scale"] if "cfg_scale" in config else 7.5
- strength = config["strength"] if "strength" in config else 0.8
- zoom_speed = config["zoom_speed"] if "zoom_speed" in config else 2.0
- vid_path = get_vid_path(prompt)
- frames_path = os.path.join(vid_path, "frames")
- os.makedirs(frames_path, exist_ok=True)
- pixels_sizes = (
- #64,128,
- #256,
- 512,
- )
- stepsize = 55
- #stepsize = 35
- seed = 666
- fixed_seed = 666
- many_iterations=1
- for pixel in pixels_sizes:
- seed = seed + 1
- video_writer = cv2.VideoWriter(os.path.join(vid_path, f"videox{pixel}.mp4"), 1, fps, (pixel, pixel))
- #logfile = open(os.path.join(vid_path, f"videox{pixel}.log"),"w")
- for i in tqdm(range(n_frames), desc="Creating Video"):
- #print(stepsize)
- #stepsize =stepsize + 1 # how much do we increase
- weight =0.5
- weight2 =0.3
- images = _t2i.prompt2image(prompt,
- strength=strength,
- seed=fixed_seed,
- variation_amount=weight2,
- width=pixel,
- height=pixel,
- steps=stepsize,
- iterations=many_iterations,
- with_variations=[ ( math.pi * x * seed ,weight) for x in [
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
- 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191,
- 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293,
- 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421,
- 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541
- ]]
- #cfg_scale=cfg_scale
- )
- for (j,image) in enumerate(images):
- next_frame_filename = os.path.join(frames_path, f"s{i}c{j}x{pixel}.png")
- print(j,image)
- image[0].save(next_frame_filename)
- #for x in range(4):# write the same frame again
- #logfile.write(json.dumps() + "\n")
- video_writer.write(cv2.imread(next_frame_filename))
- logfile2 = open(os.path.join(frames_path, f"s{i}c{j}x{pixel}.json"),"w")
- logfile2.write(json.dumps(
- dict(
- fn=next_frame_filename,
- prompt=prompt,
- strength=strength,
- seed=seed,
- variation_amount=weight,
- width=pixel,
- height=pixel,
- steps=stepsize,
- iterations=many_iterations,
- with_variations=[ (x * seed ,weight) for x in [
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ]]
- ) )+ "\n")
- logfile2.close()
- #logfile.close()
- #cv2.destroyAllWindows()
- video_writer.release()
- prompt2vid(
- prompt="the royal english prince charles as shapeshifting reptilian lizard demon in hyper realistic and detailed stone statue",
- n_frames=60
- # cfg_scale=7.5,
- # zoom_speed=2,
- # fps=30,
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement