TEXT_TO_VIDEO / app.py
akthangdz's picture
main
dcc3501
raw
history blame
1.07 kB
import gradio as gr
import subprocess
import os
def run_ttv():
try:
result = subprocess.run(['python', 'ttv.py'], capture_output=True, text=True)
# Lấy danh sách file mp3 trong thư mục temp
mp3_files = [f for f in os.listdir('temp') if f.endswith('.mp3')]
if mp3_files:
# Trả về đường dẫn đến file mp3 mới nhất
latest_mp3 = os.path.join('temp', mp3_files[-1])
return result.stdout, latest_mp3
return result.stdout, None
except Exception as e:
return f"Có lỗi xảy ra: {str(e)}", None
# Tạo giao diện
with gr.Blocks() as demo:
gr.Markdown("# Ứng dụng Text-to-Voice")
with gr.Row():
run_button = gr.Button("Chạy Text-to-Voice")
output = gr.Textbox(label="Kết quả")
# Thêm audio player
audio_output = gr.Audio(label="File âm thanh đã tạo")
run_button.click(fn=run_ttv, outputs=[output, audio_output])
# Chạy ứng dụng
if __name__ == "__main__":
demo.launch()