Update model/download_model.py
Browse files- model/download_model.py +27 -20
model/download_model.py
CHANGED
|
@@ -1,29 +1,36 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
MODEL_URL = "https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
if not os.path.exists(MODEL_PATH):
|
| 10 |
-
os.makedirs(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
else:
|
| 29 |
-
print("✅ Model đã có sẵn, bỏ qua tải về.")
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
|
|
|
|
| 4 |
|
| 5 |
+
MODEL_PATH = "model"
|
| 6 |
+
MODEL_URL = "https://huggingface.co/vosk-models/vosk-small-en-us/resolve/main"
|
| 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(MODEL_PATH)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
|
|
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
for file in files:
|
| 27 |
+
file_url = f"{MODEL_URL}/{file}.zip"
|
| 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("Tải model thành công!")
|
|
|
|
|
|