ishworrsubedii's picture
feat: add complete pipeline and Streamlit code This commit introduces a complete pipeline for both single and real-time inferences using cameras. It includes the implementation of Streamlit code to facilitate the process.
c640bc9 verified
import os
import sys
import logging
def configure_logger(logger_name, log_filename, log_dir="logs"):
"""
Configures a logger with specified parameters.
:param logger_name: Name of the logger.
:param log_filename: Name of the log file.
:param log_dir: Directory where logs will be stored. Defaults to "logs".
:return: Configured logger.
"""
logging_str = "[%(asctime)s:%(levelname)s:%(module)s:%(message)s]"
log_path = os.path.join(log_dir, log_filename)
os.makedirs(log_dir, exist_ok=True)
logger = logging.getLogger(logger_name)
logger.setLevel(logging.INFO)
formatter = logging.Formatter(logging_str)
file_handler = logging.FileHandler(log_path)
file_handler.setFormatter(formatter)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
return logger
def main_sys_logger(log_dir="logs"):
"""
Configures and returns the main system logger.
:param log_dir: Directory where logs will be stored. Defaults to "logs".
:return: Main system logger.
"""
return configure_logger("main_sys_logger", "gun_det.log", log_dir)
def ipcam_logger(log_dir="logs"):
"""
Configures and returns the IP camera logger.
:param log_dir: Directory where logs will be stored. Defaults to "logs".
:return: IP camera logger.
"""
return configure_logger("ipcam_logger", "ipcam.log", log_dir)
def detection_logger(log_dir="logs"):
"""
Configures and returns the detection logger.
:param log_dir: Directory where logs will be stored. Defaults to "logs".
:return: Detection logger.
"""
return configure_logger("detection_logger", "detection.log", log_dir)