TDN-M commited on
Commit
7cbd43f
·
verified ·
1 Parent(s): 9f1fd6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -10,7 +10,6 @@ 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
16
  client_openai = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))
@@ -59,8 +58,15 @@ def create_video(audio_file, custom_text, text_color, output_video="output.mp4")
59
  """
60
  Tạo video với văn bản tùy chỉnh.
61
  """
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 = {
@@ -83,7 +89,7 @@ def create_video(audio_file, custom_text, text_color, output_video="output.mp4")
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
 
@@ -92,7 +98,7 @@ def create_video(audio_file, custom_text, text_color, output_video="output.mp4")
92
  return output_video
93
 
94
  def interface():
95
- with gr.Blocks() as app:
96
  gr.Markdown("# Ứng dụng Tạo Nội dung và Video")
97
  with gr.Tab("Tạo Nội dung"):
98
  with gr.Row():
 
10
  from openai import OpenAI
11
  import edge_tts
12
  from moviepy.editor import VideoFileClip, AudioFileClip, CompositeVideoClip, TextClip
 
13
 
14
  # Khởi tạo client OpenAI với API key từ biến môi trường
15
  client_openai = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))
 
58
  """
59
  Tạo video với văn bản tùy chỉnh.
60
  """
61
+ # Kiểm tra file video nền
62
+ background_video = "default_background.mp4"
63
+ if not os.path.exists(background_video):
64
+ raise FileNotFoundError(f"File video nền không tồn tại: {background_video}")
65
+
66
+ # Kiểm tra file font
67
+ font_file = "/LHanoienne.otf"
68
+ if not os.path.exists(font_file):
69
+ raise FileNotFoundError(f"File font không tồn tại: {font_file}")
70
 
71
  # Định nghĩa màu sắc chữ
72
  color_map = {
 
89
 
90
  # Tạo text clip nếu có văn bản tùy chỉnh
91
  if custom_text:
92
+ txt_clip = TextClip(custom_text, fontsize=50, color=font_color, font=font_file)
93
  txt_clip = txt_clip.set_position(('left', 'top')).set_duration(final_video.duration)
94
  final_video = CompositeVideoClip([final_video, txt_clip])
95
 
 
98
  return output_video
99
 
100
  def interface():
101
+ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Roboto Mono")])) as app:
102
  gr.Markdown("# Ứng dụng Tạo Nội dung và Video")
103
  with gr.Tab("Tạo Nội dung"):
104
  with gr.Row():