In Keras, if you need to have a custom loss with additional parameters, we can use it like mentioned on https://datascience.stackexchange.com/questions/25029/custom-loss-fun
You can try this:
import keras.losses keras.losses.penalized_loss = penalized_loss
(after defining 'penalized_loss' function in your current 'py' file).