blob: b9555dc6dc73aff39563d73aa06512bb3d4fd04f [file] [log] [blame] [edit]
import os
import urllib.request
MODEL_URL = "https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.zh.300.bin.gz"
MODEL_DIR = "./models"
MODEL_PATH = os.path.join(MODEL_DIR, "cc.zh.300.bin")
COMPRESSED_PATH = MODEL_PATH + ".gz"
def download_model():
if not os.path.exists(MODEL_DIR):
os.makedirs(MODEL_DIR)
if os.path.exists(MODEL_PATH):
print("✅ 模型已存在,跳过下载。")
return
print("⏬ 下载 fastText 中文模型...")
urllib.request.urlretrieve(MODEL_URL, COMPRESSED_PATH)
print("📦 解压模型文件...")
import gzip
import shutil
with gzip.open(COMPRESSED_PATH, 'rb') as f_in:
with open(MODEL_PATH, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
os.remove(COMPRESSED_PATH)
print("✅ 模型下载并解压完成!")
if __name__ == "__main__":
download_model()