Add dotenv, fixed requirements.txt

This commit is contained in:
Reza Behzadan 2023-12-11 02:56:31 +03:30
parent 5add45c71c
commit 32a9ab07ac
3 changed files with 23 additions and 14 deletions

2
.env.sample Normal file
View File

@ -0,0 +1,2 @@
MODEL="m3hrdadfi/wav2vec2-large-xlsr-persian"
LOG_LEVEL="INFO"

25
main.py
View File

@ -1,20 +1,27 @@
import logging import logging
import os
import warnings
import librosa import librosa
import transformers
import torch import torch
from dotenv import load_dotenv
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor 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): def initLogger():
if name[:2] == '__' and name[-2:] == '__': logger = logging.getLogger("speech2text-fa")
name = name[2:-2] level = getattr(logging, LOG_LEVEL.upper())
logger = logging.getLogger(name)
fmt = '%(asctime)s | %(levelname)-8s | %(name)s | %(message)s' fmt = "%(asctime)s | %(levelname)-8s | %(message)s"
datefmt = '%Y-%m-%d %H:%M:%S' datefmt = "%Y-%m-%d %H:%M:%S"
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt, datefmt) formatter = logging.Formatter(fmt, datefmt)
@ -49,7 +56,7 @@ def mp3_to_text(mp3_file_path):
if __name__ == "__main__": if __name__ == "__main__":
logger = initLogger('speech2text_fa', level=logging.INFO) logger = initLogger()
text = mp3_to_text("samples/sample1.wav") text = mp3_to_text("samples/sample1.wav")
print() print()
print(text) print(text)

View File

@ -1,6 +1,6 @@
torch==2.1.1+cpu https://download.pytorch.org/whl/cpu/torch-2.1.1%2Bcpu-cp311-cp311-linux_x86_64.whl#sha256=d83b13cb17544f9851cc31fed197865eae0c0f5d32df9d8d6d8535df7d2e5109
torchaudio==2.1.1+cpu https://download.pytorch.org/whl/cpu/torchaudio-2.1.1%2Bcpu-cp311-cp311-linux_x86_64.whl#sha256=e0eb276958fcbd7c88f5daf761823e36ce5e41332d40f9e01fb49d80d7cc1bb1
transformers==4.35.2
librosa==0.10.1 librosa==0.10.1
python-dotenv==1.0.0
--find-links https://download.pytorch.org/whl/cpu tokenizers>=0.10.1,<0.11
transformers>=4.16.2,<4.17.0