Skip to content

Commit 35be2da

Browse files
FEAT: Adding the play_sound function to main.py
1 parent 27d0282 commit 35be2da

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,21 @@ def explain_with_multiple_methods(model, X_train, X_test, feature_names, model_n
707707

708708
explain_predictions_with_lime(model, X_train, X_test, feature_names, model_name=model_name) # Explain predictions using LIME, as it works with any model
709709

710+
def play_sound():
711+
"""
712+
Plays a sound when the program finishes.
713+
714+
:return: None
715+
"""
716+
717+
if verify_filepath_exists(SOUND_FILE): # If the sound file exists
718+
if platform.system() in SOUND_COMMANDS: # If the platform.system() is in the SOUND_COMMANDS dictionary
719+
os.system(f"{SOUND_COMMANDS[platform.system()]} {SOUND_FILE}") # Play the sound
720+
else: # If the platform.system() is not in the SOUND_COMMANDS dictionary
721+
print(f"{BackgroundColors.RED}The {BackgroundColors.CYAN}platform.system(){BackgroundColors.RED} is not in the {BackgroundColors.CYAN}SOUND_COMMANDS dictionary{BackgroundColors.RED}. Please add it!{Style.RESET_ALL}")
722+
else: # If the sound file does not exist
723+
print(f"{BackgroundColors.RED}Sound file {BackgroundColors.CYAN}{SOUND_FILE}{BackgroundColors.RED} not found. Make sure the file exists.{Style.RESET_ALL}")
724+
710725
def main():
711726
"""
712727
Main function to run the machine learning pipeline on multiple datasets.
@@ -747,6 +762,8 @@ def main():
747762

748763
print(f"{BackgroundColors.BOLD}{BackgroundColors.GREEN}All datasets processed. Overall analysis finished.{Style.RESET_ALL}")
749764

765+
atexit.register(play_sound) if RUN_FUNCTIONS["Play Sound"] else None # Register the play_sound function to be called at exit if enabled
766+
750767
if __name__ == "__main__":
751768
"""
752769
This is the standard boilerplate that calls the main() function.

0 commit comments

Comments
 (0)