Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,6 @@ import tempfile
|
|
8 |
import os
|
9 |
import threading
|
10 |
import traceback
|
11 |
-
import cv2
|
12 |
-
import numpy as np
|
13 |
|
14 |
app = Flask(__name__)
|
15 |
CORS(app)
|
@@ -35,26 +33,6 @@ def download_pipeline():
|
|
35 |
print(f"Error downloading pipeline: {e}")
|
36 |
return False
|
37 |
|
38 |
-
def export_video(frames_list, temp_video_path):
|
39 |
-
# Convert PIL images to numpy arrays
|
40 |
-
frames_np = [np.array(frame) for frame in frames_list]
|
41 |
-
|
42 |
-
# Determine the dimensions (height, width) of the frames
|
43 |
-
height, width, _ = frames_np[0].shape
|
44 |
-
|
45 |
-
# Create a VideoWriter object to write the frames to a video file
|
46 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for MP4 format
|
47 |
-
out = cv2.VideoWriter(temp_video_path, fourcc, 12, (width, height)) # Adjust fps as needed
|
48 |
-
|
49 |
-
# Write each frame to the video file
|
50 |
-
for frame_np in frames_np:
|
51 |
-
# Convert RGB image (numpy array) to BGR (OpenCV format) for writing
|
52 |
-
frame_bgr = cv2.cvtColor(frame_np, cv2.COLOR_RGB2BGR)
|
53 |
-
out.write(frame_bgr)
|
54 |
-
|
55 |
-
# Release the VideoWriter object
|
56 |
-
out.release()
|
57 |
-
|
58 |
def generate_and_export_animation(prompt):
|
59 |
global pipe
|
60 |
|
@@ -79,8 +57,7 @@ def generate_and_export_animation(prompt):
|
|
79 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_file:
|
80 |
temp_video_path = temp_file.name
|
81 |
print('temp_video_path', temp_video_path)
|
82 |
-
|
83 |
-
export_video(output.frames[0], temp_video_path)
|
84 |
|
85 |
with open(temp_video_path, 'rb') as video_file:
|
86 |
video_binary = video_file.read()
|
|
|
8 |
import os
|
9 |
import threading
|
10 |
import traceback
|
|
|
|
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
CORS(app)
|
|
|
33 |
print(f"Error downloading pipeline: {e}")
|
34 |
return False
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
def generate_and_export_animation(prompt):
|
37 |
global pipe
|
38 |
|
|
|
57 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_file:
|
58 |
temp_video_path = temp_file.name
|
59 |
print('temp_video_path', temp_video_path)
|
60 |
+
export_to_video(output.frames[0], temp_video_path)
|
|
|
61 |
|
62 |
with open(temp_video_path, 'rb') as video_file:
|
63 |
video_binary = video_file.read()
|