| import os |
| import subprocess |
| import sys |
| import importlib.util |
|
|
| |
| |
| |
|
|
| def run_command(command, message): |
| print(f"⏳ {message}...") |
| try: |
| result = subprocess.run(command, shell=True, capture_output=True, text=True) |
| if result.returncode != 0: |
| print(f"❌ Lỗi (nhưng sẽ thử tiếp tục): {message}") |
| print(f"📝 Chi tiết: {result.stderr}") |
| return False |
| print(f"✅ Xong: {message}") |
| return True |
| except Exception as e: |
| print(f"❌ Exception: {e}") |
| return False |
|
|
| def setup_environment(): |
| |
| run_command("apt-get update -qq && apt-get install -y espeak-ng git build-essential -qq", "System Tools") |
| |
| |
| if not os.path.exists("VieNeu-TTS"): |
| run_command("git clone https://github.com/pnnbao97/VieNeu-TTS.git", "Clone VieNeu-TTS") |
| |
| |
| |
| print("🛠️ Đang cài đặt thư viện (Auto-detect Hardware)...") |
| |
| |
| run_command("pip install torch torchvision torchaudio", "Install PyTorch (Auto)") |
| |
| |
| run_command("pip install neucodec", "Install Neucodec") |
| |
| |
| if os.path.exists("VieNeu-TTS"): |
| os.chdir("VieNeu-TTS") |
| run_command("pip install -e .", "Install VieNeu Local") |
| |
| sys.path.append(os.getcwd()) |
| os.chdir("..") |
|
|
| run_command("pip install --upgrade gradio", "Update Gradio") |
|
|
| |
| if not importlib.util.find_spec("neucodec") or not importlib.util.find_spec("torch"): |
| setup_environment() |
| else: |
| |
| if os.path.exists("VieNeu-TTS"): |
| sys.path.append(os.path.abspath("VieNeu-TTS")) |
|
|
| |
| |
| |
|
|
| import gradio as gr |
| import torch |
|
|
| |
| def tts_wrapper(text, speed): |
| try: |
| |
| import gradio_app |
| |
| if hasattr(gradio_app, 'inference'): |
| return gradio_app.inference(text, speed) |
| elif hasattr(gradio_app, 'tts_inference'): |
| return gradio_app.tts_inference(text, speed) |
| else: |
| |
| if hasattr(gradio_app, 'model'): |
| return gradio_app.model.infer(text, speed) |
| return None, "⚠️ Không tìm thấy hàm inference trong gradio_app.py" |
| except ImportError: |
| return None, "❌ Lỗi: Không thể import module 'gradio_app'. Kiểm tra lại cấu trúc thư mục." |
| except Exception as e: |
| return None, f"❌ Lỗi Runtime: {str(e)}" |
|
|
| |
| |
| |
|
|
| |
| css = """ |
| @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap'); |
| body { font-family: 'Inter', sans-serif; background: #0f172a; } |
| |
| .header-container { |
| background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); |
| padding: 2rem; |
| border-radius: 1rem; |
| margin-bottom: 1.5rem; |
| text-align: center; |
| color: white; |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); |
| } |
| .header-title { font-size: 2.2rem; font-weight: 800; margin: 0; } |
| .header-sub { opacity: 0.9; margin-top: 0.5rem; } |
| |
| /* Thay thế Box cũ bằng custom classes */ |
| .panel-container { |
| background: #1e293b; |
| border: 1px solid #334155; |
| border-radius: 12px; |
| padding: 20px; |
| } |
| |
| #gen-btn { |
| background: linear-gradient(90deg, #059669 0%, #10b981 100%); |
| border: none; |
| color: white; |
| font-size: 1.1rem; |
| font-weight: bold; |
| } |
| """ |
|
|
| |
| with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo: |
| |
| |
| gr.HTML(""" |
| <div class="header-container"> |
| <h1 class="header-title">🇻🇳 VieNeu-TTS Studio</h1> |
| <div class="header-sub">Deep Learning Neural Text-to-Speech | High Fidelity</div> |
| </div> |
| """) |
|
|
| with gr.Row(): |
| |
| with gr.Column(elem_classes="panel-container"): |
| gr.Markdown("### 📝 Nhập liệu") |
| inp_text = gr.Textbox( |
| label="Văn bản", |
| placeholder="Nhập tiếng Việt...", |
| lines=6, |
| value="Xin chào, hệ thống VieNeu TTS đã hoạt động trở lại." |
| ) |
| inp_speed = gr.Slider(0.5, 2.0, value=1.0, step=0.1, label="⚡ Tốc độ") |
| btn_run = gr.Button("▶️ TẠO GIỌNG ĐỌC", elem_id="gen-btn", scale=1) |
|
|
| |
| with gr.Column(elem_classes="panel-container"): |
| gr.Markdown("### 🎧 Kết quả") |
| out_audio = gr.Audio(label="Audio Output", type="filepath") |
| out_msg = gr.Markdown("Sẵn sàng xử lý...") |
|
|
| |
| gr.Markdown("<center style='color: #64748b; margin-top: 20px;'>VieNeu-TTS Community Build</center>") |
|
|
| |
| btn_run.click(fn=tts_wrapper, inputs=[inp_text, inp_speed], outputs=[out_audio, out_msg]) |
|
|
| |
| |
| |
| if __name__ == "__main__": |
| demo.queue().launch(share=True) |