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=16
- 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
- data = dict(
- strength=strength,
- seed=fixed_seed,
- variation_amount=weight2,
- width=pixel,
- height=pixel,
- steps=stepsize,
- iterations=many_iterations,
- with_variations=[ ( seed ,weight) for x in [
- 1841148245,1110603383,1051779186,1821062336,2779168033,637937175,253524533,2339735917,18889722,1332606271,4233362073,3727652175,2621123075,3095838456,109931557,3729446516,4282982516,1841148245,14341301,1265144701,109849653,1811064442,116682621,4194855109,1336901599,30739985,2437170710,915601740,1887567325,3503705270,2704117446
- ]]
- )
- images = _t2i.prompt2image(prompt,
- **data
- )
- 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,
- data=data)
- )+ "\n")
- logfile2.close()
- #logfile.close()
- #cv2.destroyAllWindows()
- video_writer.release()
- prompt2vid(
- #prompt="the character named Frisk from the game named undertale shown in a hyper realistic and detailed 3d printed sculpture",
- prompt="the character named sans, he is a scull head, he is smiling and telling a joke, he has a blue jacket, he has one shining blue eye, riding a skateboard, and fighting with magic, from the game named undertale shown in a hyper realistic and detailed 3d printed sculpture",
- n_frames=30
- # cfg_scale=7.5,
- # zoom_speed=2,
- # fps=30,
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement