From 32a9ab07accf0447c556685b794a0873f4eb981f Mon Sep 17 00:00:00 2001 From: Reza Behzadan Date: Mon, 11 Dec 2023 02:56:31 +0330 Subject: [PATCH] Add `dotenv`, fixed `requirements.txt` --- .env.sample | 2 ++ main.py | 25 ++++++++++++++++--------- requirements.txt | 10 +++++----- 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..366655b --- /dev/null +++ b/.env.sample @@ -0,0 +1,2 @@ +MODEL="m3hrdadfi/wav2vec2-large-xlsr-persian" +LOG_LEVEL="INFO" diff --git a/main.py b/main.py index 07b30a7..a5fe185 100644 --- a/main.py +++ b/main.py @@ -1,20 +1,27 @@ import logging +import os +import warnings import librosa +import transformers import torch +from dotenv import load_dotenv from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor -# MODEL = "m3hrdadfi/wav2vec2-large-xlsr-persian" -MODEL = "/home/reza/data/huggingface-models/04.wav2vec2-large-xlsr-persian" + +warnings.filterwarnings("ignore") +transformers.logging.set_verbosity_error() +load_dotenv() +MODEL = os.getenv("MODEL", "m3hrdadfi/wav2vec2-large-xlsr-persian") +LOG_LEVEL = os.getenv("LOG_LEVEL", "DEBUG") -def initLogger(name=__name__, level=logging.DEBUG): - if name[:2] == '__' and name[-2:] == '__': - name = name[2:-2] - logger = logging.getLogger(name) +def initLogger(): + logger = logging.getLogger("speech2text-fa") + level = getattr(logging, LOG_LEVEL.upper()) - fmt = '%(asctime)s | %(levelname)-8s | %(name)s | %(message)s' - datefmt = '%Y-%m-%d %H:%M:%S' + fmt = "%(asctime)s | %(levelname)-8s | %(message)s" + datefmt = "%Y-%m-%d %H:%M:%S" ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter(fmt, datefmt) @@ -49,7 +56,7 @@ def mp3_to_text(mp3_file_path): if __name__ == "__main__": - logger = initLogger('speech2text_fa', level=logging.INFO) + logger = initLogger() text = mp3_to_text("samples/sample1.wav") print() print(text) diff --git a/requirements.txt b/requirements.txt index a9bc1e2..9db6291 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -torch==2.1.1+cpu -torchaudio==2.1.1+cpu -transformers==4.35.2 +https://download.pytorch.org/whl/cpu/torch-2.1.1%2Bcpu-cp311-cp311-linux_x86_64.whl#sha256=d83b13cb17544f9851cc31fed197865eae0c0f5d32df9d8d6d8535df7d2e5109 +https://download.pytorch.org/whl/cpu/torchaudio-2.1.1%2Bcpu-cp311-cp311-linux_x86_64.whl#sha256=e0eb276958fcbd7c88f5daf761823e36ce5e41332d40f9e01fb49d80d7cc1bb1 librosa==0.10.1 - ---find-links https://download.pytorch.org/whl/cpu +python-dotenv==1.0.0 +tokenizers>=0.10.1,<0.11 +transformers>=4.16.2,<4.17.0