Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,9 @@
|
|
1 |
-
import asyncio
|
2 |
-
import mimetypes
|
3 |
import os
|
4 |
-
import
|
5 |
-
import glob
|
6 |
-
import fitz # PyMuPDF
|
7 |
-
import random
|
8 |
import gradio as gr
|
9 |
from docx import Document
|
10 |
from content_generation import create_content, CONTENT_TYPES
|
11 |
from openai import OpenAI
|
12 |
-
from gradio_client import Client, handle_file # Thêm thư viện để gọi API
|
13 |
from tts import generate_speech
|
14 |
|
15 |
# Khởi tạo client OpenAI với API key từ biến môi trường
|
@@ -51,7 +45,12 @@ def text_to_speech(content, voice_file):
|
|
51 |
Chuyển đổi nội dung thành giọng nói bằng hàm generate_speech từ tts.py.
|
52 |
"""
|
53 |
try:
|
|
|
|
|
|
|
|
|
54 |
output_audio = generate_speech(content, language="vi", speaker_wav=voice_file)
|
|
|
55 |
return output_audio
|
56 |
except Exception as e:
|
57 |
return f"Lỗi khi chuyển đổi văn bản thành giọng nói: {str(e)}"
|
@@ -60,9 +59,10 @@ def convert_content_to_speech(content, voice_file):
|
|
60 |
"""
|
61 |
Chuyển đổi nội dung thành giọng nói.
|
62 |
"""
|
|
|
|
|
63 |
return text_to_speech(content, voice_file)
|
64 |
|
65 |
-
|
66 |
def interface():
|
67 |
with gr.Blocks() as app:
|
68 |
gr.Markdown("# Ứng dụng Tạo Nội dung và Video")
|
@@ -107,6 +107,10 @@ def interface():
|
|
107 |
raise ValueError("Vui lòng chọn một loại nội dung")
|
108 |
|
109 |
script_content = create_content(prompt, content_type, "Tiếng Việt")
|
|
|
|
|
|
|
|
|
110 |
docx_path = "script.docx"
|
111 |
create_docx(script_content, docx_path)
|
112 |
|
@@ -133,4 +137,4 @@ def interface():
|
|
133 |
# Khởi chạy ứng dụng
|
134 |
if __name__ == "__main__":
|
135 |
app = interface()
|
136 |
-
app.launch()
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import mimetypes
|
|
|
|
|
|
|
3 |
import gradio as gr
|
4 |
from docx import Document
|
5 |
from content_generation import create_content, CONTENT_TYPES
|
6 |
from openai import OpenAI
|
|
|
7 |
from tts import generate_speech
|
8 |
|
9 |
# Khởi tạo client OpenAI với API key từ biến môi trường
|
|
|
45 |
Chuyển đổi nội dung thành giọng nói bằng hàm generate_speech từ tts.py.
|
46 |
"""
|
47 |
try:
|
48 |
+
if voice_file is None or not os.path.exists(voice_file):
|
49 |
+
return "Lỗi: File âm thanh mẫu không tồn tại hoặc không hợp lệ."
|
50 |
+
|
51 |
+
print(f"Chuyển đổi nội dung thành giọng nói: {content}") # Log nội dung trước khi chuyển đổi
|
52 |
output_audio = generate_speech(content, language="vi", speaker_wav=voice_file)
|
53 |
+
print(f"File âm thanh đã được tạo: {output_audio}") # Log file âm thanh
|
54 |
return output_audio
|
55 |
except Exception as e:
|
56 |
return f"Lỗi khi chuyển đổi văn bản thành giọng nói: {str(e)}"
|
|
|
59 |
"""
|
60 |
Chuyển đổi nội dung thành giọng nói.
|
61 |
"""
|
62 |
+
if content is None or content.strip() == "":
|
63 |
+
return "Lỗi: Nội dung trống hoặc không hợp lệ."
|
64 |
return text_to_speech(content, voice_file)
|
65 |
|
|
|
66 |
def interface():
|
67 |
with gr.Blocks() as app:
|
68 |
gr.Markdown("# Ứng dụng Tạo Nội dung và Video")
|
|
|
107 |
raise ValueError("Vui lòng chọn một loại nội dung")
|
108 |
|
109 |
script_content = create_content(prompt, content_type, "Tiếng Việt")
|
110 |
+
print(f"Nội dung từ LLM: {script_content}") # Log nội dung từ LLM
|
111 |
+
if script_content is None:
|
112 |
+
raise ValueError("Nội dung từ LLM là None. Vui lòng kiểm tra lại hàm create_content.")
|
113 |
+
|
114 |
docx_path = "script.docx"
|
115 |
create_docx(script_content, docx_path)
|
116 |
|
|
|
137 |
# Khởi chạy ứng dụng
|
138 |
if __name__ == "__main__":
|
139 |
app = interface()
|
140 |
+
app.launch()
|