Kilka poprawek
This commit is contained in:
parent
301abf1b7e
commit
060f40001e
|
@ -5,35 +5,56 @@ import urllib.request
|
||||||
import zipfile
|
import zipfile
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
VENV_DIR = "venv"
|
# Katalog nadrzędny względem projektu
|
||||||
REQUIREMENTS_FILE = "requirements.txt"
|
BASE_DIR = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
|
||||||
|
VENV_DIR = os.path.join(BASE_DIR, "venv")
|
||||||
|
REQUIREMENTS_SRC = os.path.join(os.getcwd(), "requirements.txt")
|
||||||
|
REQUIREMENTS_DEST = os.path.join(VENV_DIR, "requirements.txt")
|
||||||
|
|
||||||
MODEL_URL = "https://alphacephei.com/vosk/models/vosk-model-small-pl-0.22.zip"
|
MODEL_URL = "https://alphacephei.com/vosk/models/vosk-model-small-pl-0.22.zip"
|
||||||
MODEL_ZIP = "vosk-model-small-pl-0.22.zip"
|
MODEL_ZIP = os.path.join(VENV_DIR, "vosk-model-small-pl-0.22.zip")
|
||||||
MODEL_DIR = "vosk-model-small-pl-0.22"
|
MODEL_DIR = os.path.join(VENV_DIR, "vosk-model-small-pl-0.22")
|
||||||
|
|
||||||
|
VOSKPL_SRC = os.path.join(os.getcwd(), "voskpl.py")
|
||||||
|
VOSKPL_DEST = os.path.join(VENV_DIR, "voskpl.py")
|
||||||
|
|
||||||
|
|
||||||
|
def copy_voskpl():
|
||||||
|
print("[+] Kopiowanie voskpl.py do venv...")
|
||||||
|
shutil.copy(VOSKPL_SRC, VOSKPL_DEST)
|
||||||
|
|
||||||
|
|
||||||
def create_virtualenv():
|
def create_virtualenv():
|
||||||
print("[+] Tworzenie środowiska wirtualnego...")
|
print(f"[+] Tworzenie środowiska wirtualnego w: {VENV_DIR}")
|
||||||
subprocess.check_call([sys.executable, "-m", "venv", VENV_DIR])
|
subprocess.check_call([sys.executable, "-m", "venv", VENV_DIR])
|
||||||
|
|
||||||
|
|
||||||
|
def copy_requirements():
|
||||||
|
print("[+] Kopiowanie requirements.txt do venv...")
|
||||||
|
shutil.copy(REQUIREMENTS_SRC, REQUIREMENTS_DEST)
|
||||||
|
|
||||||
|
|
||||||
def install_requirements():
|
def install_requirements():
|
||||||
print("[+] Instalacja pakietów z requirements.txt...")
|
print("[+] Instalacja pakietów z requirements.txt...")
|
||||||
pip_path = os.path.join(VENV_DIR, "bin", "pip") if os.name != "nt" else os.path.join(VENV_DIR, "Scripts", "pip.exe")
|
pip_path = (
|
||||||
subprocess.check_call([pip_path, "install", "-r", REQUIREMENTS_FILE])
|
os.path.join(VENV_DIR, "bin", "pip")
|
||||||
|
if os.name != "nt"
|
||||||
|
else os.path.join(VENV_DIR, "Scripts", "pip.exe")
|
||||||
|
)
|
||||||
|
subprocess.check_call([pip_path, "install", "-r", REQUIREMENTS_DEST])
|
||||||
|
|
||||||
|
|
||||||
def download_model():
|
def download_model():
|
||||||
if os.path.exists(MODEL_DIR):
|
if os.path.exists(MODEL_DIR):
|
||||||
print("[i] Model już istnieje, pomijam pobieranie.")
|
print("[i] Model już istnieje w venv, pomijam pobieranie.")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"[+] Pobieranie modelu z {MODEL_URL}...")
|
print(f"[+] Pobieranie modelu do: {MODEL_ZIP}")
|
||||||
urllib.request.urlretrieve(MODEL_URL, MODEL_ZIP)
|
urllib.request.urlretrieve(MODEL_URL, MODEL_ZIP)
|
||||||
|
|
||||||
print("[+] Rozpakowywanie modelu...")
|
print("[+] Rozpakowywanie modelu...")
|
||||||
with zipfile.ZipFile(MODEL_ZIP, 'r') as zip_ref:
|
with zipfile.ZipFile(MODEL_ZIP, "r") as zip_ref:
|
||||||
zip_ref.extractall(".")
|
zip_ref.extractall(VENV_DIR)
|
||||||
|
|
||||||
print("[+] Usuwanie archiwum ZIP...")
|
print("[+] Usuwanie archiwum ZIP...")
|
||||||
os.remove(MODEL_ZIP)
|
os.remove(MODEL_ZIP)
|
||||||
|
@ -41,8 +62,10 @@ def download_model():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
create_virtualenv()
|
create_virtualenv()
|
||||||
|
copy_requirements()
|
||||||
install_requirements()
|
install_requirements()
|
||||||
download_model()
|
download_model()
|
||||||
|
copy_voskpl()
|
||||||
print("[✓] Gotowe!")
|
print("[✓] Gotowe!")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue