Update upgrade.py
Browse files- upgrade.py +37 -0
upgrade.py
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Initialize a text-to-image generation pipeline (for example purposes)
|
| 7 |
+
generator = pipeline('text-to-image', model='CompVis/stable-diffusion-v1-4')
|
| 8 |
+
|
| 9 |
+
# List of prompts for each frame
|
| 10 |
+
prompts = [
|
| 11 |
+
"A spaceship in space, vibrant colors",
|
| 12 |
+
"A spaceship flying past planets",
|
| 13 |
+
"A spaceship approaching a distant galaxy",
|
| 14 |
+
"A spaceship landing on an alien planet"
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
# Folder to save frames
|
| 18 |
+
os.makedirs('frames', exist_ok=True)
|
| 19 |
+
|
| 20 |
+
# Generate images for each prompt
|
| 21 |
+
for idx, prompt in enumerate(prompts):
|
| 22 |
+
image = generator(prompt)[0]['image']
|
| 23 |
+
image.save(f'frames/frame_{idx:03d}.png')
|
| 24 |
+
|
| 25 |
+
# Combine frames into a video
|
| 26 |
+
frame_files = [f'frames/frame_{i:03d}.png' for i in range(len(prompts))]
|
| 27 |
+
frame_width, frame_height = cv2.imread(frame_files[0]).shape[1], cv2.imread(frame_files[0]).shape[0]
|
| 28 |
+
|
| 29 |
+
video_writer = cv2.VideoWriter('space_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 1, (frame_width, frame_height))
|
| 30 |
+
|
| 31 |
+
for file in frame_files:
|
| 32 |
+
img = cv2.imread(file)
|
| 33 |
+
video_writer.write(img)
|
| 34 |
+
|
| 35 |
+
video_writer.release()
|
| 36 |
+
|
| 37 |
+
print("Video created: space_video.mp4")
|