Spaces:
Sleeping
Sleeping
File size: 6,762 Bytes
106478e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
#!/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) |