F5-TTS-THAI / prepare_deployment.py
pythonlearnreal's picture
Upload folder using huggingface_hub
106478e verified
#!/usr/bin/env python3
"""
Prepare F5-TTS Thai WebUI for deployment
สคริปต์สำหรับเตรียมการ deploy แอป F5-TTS Thai
"""
import os
import shutil
import sys
import zipfile
from pathlib import Path
def create_deployment_package():
"""สร้าง package สำหรับ deployment"""
print("🚀 กำลังเตรียม F5-TTS Thai WebUI สำหรับ deployment...")
# สร้างโฟลเดอร์ deployment
deploy_dir = Path("deployment")
if deploy_dir.exists():
shutil.rmtree(deploy_dir)
deploy_dir.mkdir()
print("📁 สร้างโฟลเดอร์ deployment...")
# รายการไฟล์ที่ต้องการ
required_files = [
"app.py",
"requirements.txt",
"README_DEPLOYMENT.md",
".gitignore"
]
# รายการโฟลเดอร์ที่ต้องการ
required_dirs = [
"src/f5_tts"
]
# คัดลอกไฟล์
print("📄 คัดลอกไฟล์...")
for file in required_files:
if os.path.exists(file):
shutil.copy2(file, deploy_dir)
print(f"✅ {file}")
else:
print(f"⚠️ ไม่พบไฟล์ {file}")
# คัดลอกโฟลเดอร์
print("📂 คัดลอกโฟลเดอร์...")
for dir_path in required_dirs:
if os.path.exists(dir_path):
dest_path = deploy_dir / dir_path
dest_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copytree(dir_path, dest_path)
print(f"✅ {dir_path}")
else:
print(f"⚠️ ไม่พบโฟลเดอร์ {dir_path}")
# เปลี่ยนชื่อ README
readme_source = deploy_dir / "README_DEPLOYMENT.md"
readme_dest = deploy_dir / "README.md"
if readme_source.exists():
readme_source.rename(readme_dest)
print("✅ เปลี่ยนชื่อ README_DEPLOYMENT.md เป็น README.md")
# สร้างไฟล์ zip
print("📦 สร้างไฟล์ zip...")
zip_path = "f5-tts-thai-deployment.zip"
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(deploy_dir):
for file in files:
file_path = os.path.join(root, file)
arc_path = os.path.relpath(file_path, deploy_dir)
zipf.write(file_path, arc_path)
print(f"✅ สร้าง {zip_path} เรียบร้อย")
return deploy_dir, zip_path
def validate_deployment():
"""ตรวจสอบไฟล์ที่จำเป็นสำหรับ deployment"""
print("\n🔍 ตรวจสอบไฟล์ที่จำเป็น...")
required_files = {
"app.py": "Entry point สำหรับ Gradio",
"requirements.txt": "Dependencies list",
"src/f5_tts/config.py": "Configuration file",
"src/f5_tts/model_manager.py": "Model management",
"src/f5_tts/tts_processor.py": "TTS processing",
"src/f5_tts/multi_speech_processor.py": "Multi-speech processing",
"src/f5_tts/ui_components.py": "UI components"
}
all_good = True
for file_path, description in required_files.items():
if os.path.exists(file_path):
print(f"✅ {file_path} - {description}")
else:
print(f"❌ {file_path} - {description} (ไม่พบไฟล์)")
all_good = False
# ตรวจสอบ dependencies ใน requirements.txt
print("\n🔍 ตรวจสอบ dependencies...")
if os.path.exists("requirements.txt"):
with open("requirements.txt", "r") as f:
deps = f.read().strip().split("\n")
print(f"📦 พบ {len(deps)} dependencies:")
for dep in deps[:5]: # แสดง 5 อันแรก
print(f" - {dep}")
if len(deps) > 5:
print(f" ... และอีก {len(deps) - 5} รายการ")
return all_good
def generate_deploy_commands():
"""สร้างคำสั่งสำหรับ deploy"""
commands = {
"Hugging Face Spaces": [
"# 1. สร้าง Space ใหม่ที่ https://huggingface.co/new-space",
"# 2. Clone repository",
"git clone https://huggingface.co/spaces/YOUR_USERNAME/SPACE_NAME",
"cd SPACE_NAME",
"",
"# 3. คัดลอกไฟล์จาก deployment folder",
"cp -r ../deployment/* .",
"",
"# 4. Commit และ push",
"git add .",
"git commit -m 'Deploy F5-TTS Thai WebUI'",
"git push"
],
"Local Testing": [
"# ทดสอบ local ก่อน deploy",
"cd deployment",
"pip install -r requirements.txt",
"python app.py"
]
}
print("\n📋 คำสั่งสำหรับ deployment:")
for platform, cmds in commands.items():
print(f"\n## {platform}")
for cmd in cmds:
print(cmd)
def main():
"""Main function"""
print("=" * 60)
print(" F5-TTS Thai WebUI - Deployment Preparation")
print("=" * 60)
# ตรวจสอบไฟล์
if not validate_deployment():
print("\n❌ พบปัญหาในการตรวจสอบไฟล์")
print("กรุณาแก้ไขปัญหาก่อนทำการ deploy")
return False
print("\n✅ ตรวจสอบไฟล์เรียบร้อย")
# สร้าง deployment package
deploy_dir, zip_path = create_deployment_package()
# แสดงคำสั่ง deploy
generate_deploy_commands()
print(f"\n🎉 เตรียม deployment เรียบร้อย!")
print(f"📁 ไฟล์อยู่ที่: {deploy_dir}")
print(f"📦 ไฟล์ zip: {zip_path}")
print("\n📝 ขั้นตอนต่อไป:")
print("1. ไปที่ https://huggingface.co/new-space")
print("2. สร้าง Space ใหม่ (เลือก SDK: Gradio)")
print("3. อัปโหลดไฟล์จากโฟลเดอร์ deployment/")
print("4. รอการ build และทดสอบ")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)