Data preparation for the Inference Pipeline
This module contains functions for data ingestion and preprocessing during the inference phase.
Data Ingestion
mov_to_mp3_audio: Extracts audio from a video file and saves it as an mp3 file.
from emotion_detective.data.inference.data_ingestion import mov_to_mp3_audio
# Example usage
mov_to_mp3_audio('input_video.mp4')
- emotion_detective.data.inference.data_ingestion.mov_to_mp3_audio(input_file: str) str
Extracts audio from a video file and saves it as an mp3 file.
- Parameters:
input_file (str) – Path to the input video file.
- Returns:
Path to the saved mp3 file.
- Return type:
str
- Raises:
ValueError – If the input file does not have a .mp4 extension.
Exception – Any exceptions encountered during the conversion process.
Author: Kacper Janczyk
Troubleshooting
Problem: FileNotFoundError when the input video file is not found. Solution: Ensure the input file path is correct and the file exists.
try: mov_to_mp3_audio('input_video.mp4') except FileNotFoundError: print("The specified video file was not found. Please check the file path.")
Data Preprocessing
transcribe_translate: Transcribes and translates audio files.
from emotion_detective.data.inference.data_preprocessing import transcribe_translate
# Example usage
transcribe_translate('audio_file.mp3')
- emotion_detective.data.inference.data_preprocessing.dataset_loader(df: DataFrame, text_column: str, batch_size=1) DataLoader
Creates a PyTorch DataLoader for a given pandas DataFrame.
Parameters: - df (pandas.DataFrame): The DataFrame containing the dataset. - text_column (str): The name of the column in df containing text data. - batch_size (int): The batch size to be used for loading the data.
Returns: - torch.utils.data.DataLoader: A DataLoader object configured with
the provided DataFrame and batch size.
Author: Kacper Janczyk
- emotion_detective.data.inference.data_preprocessing.transcribe_translate(path: str, language: str = 'en') DataFrame
Transcribes and translates audio files.
Parameters: - path (str): The path to the audio file for transcription. - language (str, optional): The language of the audio and the target
language for translation. Default is ‘en’ (English).
Returns: - pandas.DataFrame: A DataFrame containing transcribed and translated
sentences along with their corresponding start and end times.
Author: Kacper Janczyk
Troubleshooting
Problem: FileNotFoundError when the audio file is not found. Solution: Ensure the input file path is correct and the file exists.
try: transcribe_translate('audio_file.mp3') except FileNotFoundError: print("The specified audio file was not found. Please check the file path.")Problem: UnsupportedFormatError when the audio file format is not supported. Solution: Convert the audio file to a supported format such as Mp3.
try: transcribe_translate('audio_file.wav') except UnsupportedFormatError: print("The audio file format is not supported. Please convert it to Mp3 and try again.")dataset_loader: Creates a PyTorch DataLoader for a given DataFrame.
from emotion_detective.data.inference.data_preprocessing import dataset_loader # Example usage loader = dataset_loader(df, 'text_column', batch_size=32)
Troubleshooting
Problem: KeyError when the specified text column is not found in the DataFrame. Solution: Verify that the DataFrame contains the specified text column.
try: loader = dataset_loader(df, 'text_column', batch_size=32) except KeyError: print("The specified text column was not found in the DataFrame. Please check the column name.")Problem: ValueError when the batch size is invalid. Solution: Ensure that the batch size is a positive integer.
try: loader = dataset_loader(df, 'text_column', batch_size=32) except ValueError: print("Invalid batch size. Please ensure the batch size is a positive integer.")