Advertisement
Guest User

create undertale sans movie

a guest
Sep 12th, 2022
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | Science | 0 0
  1. import argparse
  2. import os
  3. import string
  4. import json
  5. import cv2
  6. from datetime import datetime
  7. from tqdm import tqdm
  8. from ldm.simplet2i import T2I
  9. from random import choice
  10. import PIL
  11. from PIL.Image import Resampling
  12. import math
  13. _t2i = T2I()
  14.  
  15. def get_folder_name(prompt = ""):
  16. now = datetime.now()
  17.  
  18. prompt_parts = prompt.split()
  19. first_word = prompt_parts[0] if len(prompt_parts) > 0 else ""
  20.  
  21. h, m, s = (str(t).ljust(2, "0") for t in [now.hour, now.minute, now.second])
  22.  
  23. return f"{first_word}-{now.year}-{now.month}-{now.day}-{h}{m}{s}"
  24.  
  25. def get_vid_path(prompt = ""):
  26. return os.path.join(".", "outputs", "vid-samples", get_folder_name(prompt))
  27.  
  28. def prompt2vid(**config):
  29. prompt = config["prompt"]
  30. n_frames = config["n_frames"]
  31. #initial_image = config["init_img"]
  32. fps = config["fps"] if "fps" in config else 30.0
  33. cfg_scale = config["cfg_scale"] if "cfg_scale" in config else 7.5
  34. strength = config["strength"] if "strength" in config else 0.8
  35. zoom_speed = config["zoom_speed"] if "zoom_speed" in config else 2.0
  36. vid_path = get_vid_path(prompt)
  37. frames_path = os.path.join(vid_path, "frames")
  38. os.makedirs(frames_path, exist_ok=True)
  39.  
  40. pixels_sizes = (
  41. #64,128,
  42. #256,
  43. 512,
  44. )
  45.  
  46.  
  47. stepsize = 55
  48. #stepsize = 35
  49. seed = 666
  50. fixed_seed = 666
  51. many_iterations=16
  52.  
  53. for pixel in pixels_sizes:
  54. #seed = seed + 1
  55. video_writer = cv2.VideoWriter(os.path.join(vid_path, f"videox{pixel}.mp4"), 1, fps, (pixel, pixel))
  56. #logfile = open(os.path.join(vid_path, f"videox{pixel}.log"),"w")
  57. for i in tqdm(range(n_frames), desc="Creating Video"):
  58. #print(stepsize)
  59. #stepsize =stepsize + 1 # how much do we increase
  60. weight =0.5
  61. weight2 =0.3
  62.  
  63. data = dict(
  64. strength=strength,
  65. seed=fixed_seed,
  66. variation_amount=weight2,
  67. width=pixel,
  68. height=pixel,
  69. steps=stepsize,
  70. iterations=many_iterations,
  71. with_variations=[ ( seed ,weight) for x in [
  72. 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
  73. ]]
  74. )
  75. images = _t2i.prompt2image(prompt,
  76. **data
  77.  
  78. )
  79.  
  80. for (j,image) in enumerate(images):
  81. next_frame_filename = os.path.join(frames_path, f"s{i}c{j}x{pixel}.png")
  82. print(j,image)
  83. image[0].save(next_frame_filename)
  84. #for x in range(4):# write the same frame again
  85. #logfile.write(json.dumps() + "\n")
  86. video_writer.write(cv2.imread(next_frame_filename))
  87. logfile2 = open(os.path.join(frames_path, f"s{i}c{j}x{pixel}.json"),"w")
  88. logfile2.write(json.dumps(
  89. dict(
  90. fn=next_frame_filename,
  91. prompt=prompt,
  92. data=data)
  93. )+ "\n")
  94. logfile2.close()
  95.  
  96. #logfile.close()
  97.  
  98. #cv2.destroyAllWindows()
  99. video_writer.release()
  100.  
  101. prompt2vid(
  102.  
  103. #prompt="the character named Frisk from the game named undertale shown in a hyper realistic and detailed 3d printed sculpture",
  104. 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",
  105. n_frames=30
  106. # cfg_scale=7.5,
  107. # zoom_speed=2,
  108.  
  109. # fps=30,
  110. )
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement