Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ import cv2
|
|
12 |
os.environ["PATH"] += os.pathsep + r"D:\Downloads\ffmpeg-7.1.1-essentials_build\ffmpeg-7.1.1-essentials_build\bin"
|
13 |
|
14 |
# Timeout cho toàn bộ thao tác (giây)
|
15 |
-
TIMEOUT = 300 #
|
16 |
|
17 |
def wrap_text(text, max_width=1060, font_size=20):
|
18 |
words = text.split()
|
@@ -108,12 +108,17 @@ def generate_video(image_files, script_input, duration_input, audio_file, fps=60
|
|
108 |
return None, "❌ Số lượng ảnh, scripts và durations phải bằng nhau!"
|
109 |
|
110 |
images = []
|
111 |
-
for
|
112 |
try:
|
113 |
-
|
|
|
114 |
if not kind or kind.mime not in ['image/png', 'image/jpeg']:
|
115 |
continue
|
116 |
-
|
|
|
|
|
|
|
|
|
117 |
images.append(img)
|
118 |
except Exception as e:
|
119 |
continue
|
|
|
12 |
os.environ["PATH"] += os.pathsep + r"D:\Downloads\ffmpeg-7.1.1-essentials_build\ffmpeg-7.1.1-essentials_build\bin"
|
13 |
|
14 |
# Timeout cho toàn bộ thao tác (giây)
|
15 |
+
TIMEOUT = 300 # giây
|
16 |
|
17 |
def wrap_text(text, max_width=1060, font_size=20):
|
18 |
words = text.split()
|
|
|
108 |
return None, "❌ Số lượng ảnh, scripts và durations phải bằng nhau!"
|
109 |
|
110 |
images = []
|
111 |
+
for img_file in image_files:
|
112 |
try:
|
113 |
+
file_bytes = img_file.read()
|
114 |
+
kind = filetype.guess(file_bytes)
|
115 |
if not kind or kind.mime not in ['image/png', 'image/jpeg']:
|
116 |
continue
|
117 |
+
|
118 |
+
# Đọc ảnh bằng numpy
|
119 |
+
nparr = np.frombuffer(file_bytes, np.uint8)
|
120 |
+
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
121 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
122 |
images.append(img)
|
123 |
except Exception as e:
|
124 |
continue
|