Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from docx import Document
|
|
9 |
from content_generation import create_content, CONTENT_TYPES
|
10 |
from openai import OpenAI
|
11 |
import edge_tts
|
12 |
-
import
|
13 |
import time
|
14 |
|
15 |
# Khởi tạo client OpenAI với API key từ biến môi trường
|
@@ -62,9 +62,6 @@ def create_video(audio_file, custom_text, text_color, output_video="output.mp4")
|
|
62 |
# Chọn file video nền mặc định
|
63 |
background_video = "default_background.mp4" # Đặt tên file video nền mặc định
|
64 |
|
65 |
-
# Định nghĩa văn bản trên video
|
66 |
-
text_on_video = custom_text if custom_text else ""
|
67 |
-
|
68 |
# Định nghĩa màu sắc chữ
|
69 |
color_map = {
|
70 |
"Trắng": "white",
|
@@ -75,22 +72,23 @@ def create_video(audio_file, custom_text, text_color, output_video="output.mp4")
|
|
75 |
}
|
76 |
font_color = color_map.get(text_color, "white") # Mặc định là trắng nếu không tìm thấy
|
77 |
|
78 |
-
#
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
94 |
return output_video
|
95 |
|
96 |
def interface():
|
|
|
9 |
from content_generation import create_content, CONTENT_TYPES
|
10 |
from openai import OpenAI
|
11 |
import edge_tts
|
12 |
+
from moviepy.editor import VideoFileClip, AudioFileClip, CompositeVideoClip, TextClip
|
13 |
import time
|
14 |
|
15 |
# Khởi tạo client OpenAI với API key từ biến môi trường
|
|
|
62 |
# Chọn file video nền mặc định
|
63 |
background_video = "default_background.mp4" # Đặt tên file video nền mặc định
|
64 |
|
|
|
|
|
|
|
65 |
# Định nghĩa màu sắc chữ
|
66 |
color_map = {
|
67 |
"Trắng": "white",
|
|
|
72 |
}
|
73 |
font_color = color_map.get(text_color, "white") # Mặc định là trắng nếu không tìm thấy
|
74 |
|
75 |
+
# Tạo video nền
|
76 |
+
video_clip = VideoFileClip(background_video)
|
77 |
+
|
78 |
+
# Tạo audio clip
|
79 |
+
audio_clip = AudioFileClip(audio_file)
|
80 |
+
|
81 |
+
# Tạo video clip với audio
|
82 |
+
final_video = video_clip.set_audio(audio_clip)
|
83 |
+
|
84 |
+
# Tạo text clip nếu có văn bản tùy chỉnh
|
85 |
+
if custom_text:
|
86 |
+
txt_clip = TextClip(custom_text, fontsize=50, color=font_color, font='/LHanoienne.otf')
|
87 |
+
txt_clip = txt_clip.set_position(('left', 'top')).set_duration(final_video.duration)
|
88 |
+
final_video = CompositeVideoClip([final_video, txt_clip])
|
89 |
+
|
90 |
+
# Lưu video cuối cùng
|
91 |
+
final_video.write_videofile(output_video, codec='libx264', audio_codec='aac')
|
92 |
return output_video
|
93 |
|
94 |
def interface():
|