Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import os
- import string
- 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
- _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)
- stepsize = 1
- pixels_sizes = (
- #64,128,
- 256,512
- )
- for pixel in pixels_sizes:
- video_writer = cv2.VideoWriter(os.path.join(vid_path, f"videox{pixel}.mp4"), 1, fps, (pixel, pixel))
- for i in tqdm(range(n_frames), desc="Creating Video"):
- print(stepsize)
- stepsize =stepsize + 1 # how much do we increase
- weight = 0.01
- images = _t2i.prompt2image(prompt,
- strength=strength,
- seed=2,
- variation_amount=weight,
- width=pixel,
- height=pixel,
- steps=stepsize,
- iterations=32,
- with_variations=[ (x,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
- ]]
- #cfg_scale=cfg_scale
- )
- print(images)
- 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)
- video_writer.write(cv2.imread(next_frame_filename))
- #cv2.destroyAllWindows()
- video_writer.release()
- prompt2vid(
- #strength=1,
- prompt="(lizards|Aphids|Aphididae|Carpet Beetle|Warehouse Beetle|Dermestidae|Armyworms|Cutworms|Earworms|Noctuidae|Longhorned Wood Boring Beetles|Roundheaded Wood Boring Beetles|Cerambycidae|Weevils|Billbugs|Bark Beetles|Curculionidae). highly detailed digital 3d printer sculpture",
- n_frames=3
- # cfg_scale=7.5,
- # zoom_speed=2,
- # fps=30,
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement