Update model/download_model.py
Browse files- model/download_model.py +20 -27
model/download_model.py
CHANGED
|
@@ -1,36 +1,29 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Danh sách file cần tải
|
| 9 |
-
files = ["am", "conf", "graph", "ivector", "rescore"]
|
| 10 |
|
| 11 |
if not os.path.exists(MODEL_PATH):
|
| 12 |
-
os.makedirs(
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
|
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
file_path = os.path.join(MODEL_PATH, f"{file}.zip")
|
| 29 |
-
|
| 30 |
-
if not os.path.exists(file_path):
|
| 31 |
-
print(f"Đang tải {file_url} ...")
|
| 32 |
-
subprocess.run(["wget", "-O", file_path, file_url])
|
| 33 |
-
subprocess.run(["unzip", "-o", file_path, "-d", MODEL_PATH])
|
| 34 |
-
os.remove(file_path)
|
| 35 |
|
| 36 |
-
print("
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import zipfile
|
| 3 |
|
| 4 |
+
MODEL_URL = "https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip"
|
| 5 |
|
| 6 |
+
MODEL_DIR = "model"
|
| 7 |
+
MODEL_PATH = os.path.join(MODEL_DIR, "vosk-model")
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
if not os.path.exists(MODEL_PATH):
|
| 10 |
+
os.makedirs(MODEL_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
zip_path = os.path.join(MODEL_DIR, "model.zip")
|
| 13 |
|
| 14 |
+
print("📥 Đang tải model Vosk...")
|
| 15 |
+
response = requests.get(MODEL_URL, stream=True)
|
| 16 |
+
with open(zip_path, "wb") as f:
|
| 17 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 18 |
+
f.write(chunk)
|
| 19 |
|
| 20 |
+
print("📦 Giải nén model...")
|
| 21 |
+
with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
| 22 |
+
zip_ref.extractall(MODEL_DIR)
|
| 23 |
|
| 24 |
+
os.rename(os.path.join(MODEL_DIR, "vosk-model-small-en-us-0.15"), MODEL_PATH)
|
| 25 |
+
os.remove(zip_path) # Xóa file zip sau khi giải nén
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
print("✅ Model đã tải thành công!")
|
| 28 |
+
else:
|
| 29 |
+
print("✅ Model đã có sẵn, bỏ qua tải về.")
|