Skip to content

Commit

Permalink
logging doesn't work (wrong implementation)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanshin committed Jul 5, 2023
1 parent d7f5de6 commit 1944d16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
11 changes: 5 additions & 6 deletions components/logs_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import logging

def configure_loger(APP_CONFIGS) -> logging.Logger:
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

attributes_list = ['asctime', 'levelname', 'message']
formatter = logging.Formatter('%(' + ((')s' + db_logs_handler.DEFAULT_SEPARATOR + '%(').join(attributes_list)) + ')s')

if APP_CONFIGS['logs_to_db'] == True:
database = os.path.join(APP_CONFIGS['logs_db_path'], 'LOGS.db')
Expand All @@ -17,12 +22,6 @@ def configure_loger(APP_CONFIGS) -> logging.Logger:
sql_handler.setFormatter(formatter)
logger.addHandler(sql_handler)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

attributes_list = ['asctime', 'levelname', 'message']
formatter = logging.Formatter('%(' + ((')s' + db_logs_handler.DEFAULT_SEPARATOR + '%(').join(attributes_list)) + ')s')

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(formatter)
Expand Down
4 changes: 3 additions & 1 deletion components/noisereducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ def reduce_noise(path_to_audio_file: Union[Text,Path], output_dir: Union[Text,Pa
wavfile.write(os.path.join(output_dir, ts + "_" + file_name), rate, reduced_noise)
return None

def cleaner_worker(configs_dict, queue) -> None:
def cleaner_worker(configs_dict, queue, logger) -> None:
""" Daemon cleaner worker """
while True:
if not queue.empty():
f_path = queue.get()
logger.info(f'{f_path} Clean start')
reduce_noise(f_path, configs_dict['clean_audio_dir'])
logger.info(f'{f_path} Clean end')
os.remove(f_path)
pass
4 changes: 3 additions & 1 deletion components/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ def transcribe_audio(
json.dump(transcription, out_file, ensure_ascii= False)
return None

def transcriber_worker(configs_dict, queue) -> None:
def transcriber_worker(configs_dict, queue, logger) -> None:
""" Daemon cleaner worker """
model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-russian")
while True:
if not queue.empty():
f_path = queue.get()
logger.info(f'{f_path} Transcribe start')
transcribe_audio(f_path, configs_dict['output_dir'], model)
logger.info(f'{f_path} Transcribe end')
os.remove(f_path)
pass
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#YAML
working_dir: D:\\WAV2VEC_ASR_WD\
output_dir: D:\\WAV2VEC_ASR_OUPUT\
logs_to_db: False # False
logs_to_db: True # False
logs_db_path: D:\\WAV2VEC_ASR_DB\ # set path where to store SQLite DB if logs_to_db = True| else None
6 changes: 4 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from components.logs_writer import configure_loger
import multiprocessing as mp

#TODO: Create correct multiprocessing logging mechanism
# (https://stackoverflow.com/questions/641420/how-should-i-log-while-using-multiprocessing-in-python)
APP_CONFIGS = read_configs() # read and validate configuration file

if __name__ == '__main__':
Expand All @@ -20,15 +22,15 @@
watchdog_cleaner_proc.start()
#watchdog_proc.join()
# 2) cleaner
cleaner = mp.Process(target= cleaner_worker, args= (APP_CONFIGS, queue_to_cleaning))
cleaner = mp.Process(target= cleaner_worker, args= (APP_CONFIGS, queue_to_cleaning, logger))
cleaner.daemon= True
cleaner.start()
# 3) watchdog with queue to transcribation
watchdog_transcribe_proc = mp.Process(target= create_observer, args= (APP_CONFIGS['clean_audio_dir'], queue_to_transcribe))
watchdog_transcribe_proc.daemon= True
watchdog_transcribe_proc.start()
# 4) Russian wav2vec implementation
transcriber_proc = mp.Process(target= transcriber_worker, args= (APP_CONFIGS, queue_to_transcribe))
transcriber_proc = mp.Process(target= transcriber_worker, args= (APP_CONFIGS, queue_to_transcribe, logger))
transcriber_proc.daemon= True
transcriber_proc.start()
logger.info('Startup success')
Expand Down

0 comments on commit 1944d16

Please sign in to comment.