bổ sung tải model luôn
This commit is contained in:
@@ -22,18 +22,45 @@ TEMPLATE_DIR = Path(__file__).parent / "templates"
|
||||
AVAILABLE_MODELS = {
|
||||
"gemma-4-E2B-it": {
|
||||
"file": "gemma-4-E2B-it.litertlm",
|
||||
"repo": "google/gemma-4-E2B-it",
|
||||
"repo": "litert-community/gemma-4-E2B-it-litert-lm",
|
||||
"desc": "Gemma 4 Edge 2B — nhỏ hơn, nhanh hơn",
|
||||
},
|
||||
"gemma-4-E4B-it": {
|
||||
"file": "gemma-4-E4B-it.litertlm",
|
||||
"repo": "google/gemma-4-E4B-it",
|
||||
"repo": "litert-community/gemma-4-E4B-it-litert-lm",
|
||||
"desc": "Gemma 4 Edge 4B — thông minh hơn, chậm hơn",
|
||||
},
|
||||
}
|
||||
|
||||
# ── CLI: chọn model khi khởi động ────────────────────────────────────────────
|
||||
|
||||
def download_model(repo: str, local_dir: Path) -> bool:
|
||||
"""Tải model từ Hugging Face về local."""
|
||||
try:
|
||||
import subprocess
|
||||
print(f"\n Đang tải model từ {repo}...")
|
||||
print(f" Vui lòng đợi, quá trình này có thể mất vài phút...\n")
|
||||
|
||||
cmd = [
|
||||
"huggingface-cli", "download", repo,
|
||||
"--include", "*.litertlm",
|
||||
"--local-dir", str(local_dir)
|
||||
]
|
||||
|
||||
result = subprocess.run(cmd, check=True, capture_output=False, text=True)
|
||||
print(f"\n ✓ Tải model thành công!")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"\n ✗ Lỗi khi tải model: {e}")
|
||||
return False
|
||||
except FileNotFoundError:
|
||||
print(f"\n ✗ Không tìm thấy huggingface-cli.")
|
||||
print(f" Cài đặt bằng lệnh: pip install huggingface-hub")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"\n ✗ Lỗi không xác định: {e}")
|
||||
return False
|
||||
|
||||
def select_model() -> Path:
|
||||
print("\n" + "="*52)
|
||||
print(" LiteRT-LM Server — Chọn model")
|
||||
@@ -58,10 +85,33 @@ def select_model() -> Path:
|
||||
|
||||
if not model_path.exists():
|
||||
print(f"\n Model chưa có trong thư mục models/")
|
||||
print(f" Tải về bằng lệnh:\n")
|
||||
print(f" Lệnh tải thủ công:\n")
|
||||
print(f" huggingface-cli download {info['repo']} \\")
|
||||
print(f" --include '*.litertlm' \\")
|
||||
print(f" --local-dir models/\n")
|
||||
|
||||
download_choice = input(" Bạn muốn tải model ngay bây giờ? (y/n): ").strip().lower()
|
||||
if download_choice == "y":
|
||||
if download_model(info['repo'], MODELS_DIR):
|
||||
# Kiểm tra lại xem file đã tồn tại chưa
|
||||
if model_path.exists():
|
||||
print(f"\n Đã chọn: {key}")
|
||||
print(f" Path: {model_path}\n")
|
||||
return model_path
|
||||
else:
|
||||
print(f"\n ✗ Không tìm thấy file model sau khi tải.")
|
||||
retry = input(" Chọn model khác? (y/n): ").strip().lower()
|
||||
if retry == "y":
|
||||
continue
|
||||
else:
|
||||
sys.exit(0)
|
||||
else:
|
||||
retry = input("\n Chọn model khác? (y/n): ").strip().lower()
|
||||
if retry == "y":
|
||||
continue
|
||||
else:
|
||||
sys.exit(0)
|
||||
else:
|
||||
retry = input(" Chọn model khác? (y/n): ").strip().lower()
|
||||
if retry == "y":
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user