input: Write a function to generate a neural network model using TensorFlow and Python for classifying hand-written digits from the MNIST dataset. The model should include parameters for learning rate, training epochs, and batch size, and it should be capable of displaying the training cost per epoch and calculating the model's accuracy on the test data. The function should return the final accuracy of the model.
  assert generate_model() == True
  assert generate_model() == True
  assert generate_model() == True
  assert generate_model() == True
  assert generate_model() == True
output: 
  def generate_model(learning_rate=0.001, epochs=10, batch_size=128):
      import tensorflow as tf
      from tensorflow.keras import layers, models
      from tensorflow.keras.datasets import mnist
      from tensorflow.keras.utils import to_categorical
  
      (x_train, y_train), (x_test, y_test) = mnist.load_data()
      x_train = x_train.reshape((x_train.shape[0], 28, 28, 1)).astype('float32') / 255
      x_test = x_test.reshape((x_test.shape[0], 28, 28, 1)).astype('float32') / 255
      y_train = to_categorical(y_train)
      y_test = to_categorical(y_test)
  
      model = models.Sequential([
          layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
          layers.MaxPooling2D((2, 2)),
          layers.Conv2D(64, (3, 3), activation='relu'),
          layers.MaxPooling2D((2, 2)),
          layers.Conv2D(64, (3, 3), activation='relu'),
          layers.Flatten(),
          layers.Dense(64, activation='relu'),
          layers.Dense(10, activation='softmax')
      ])
  
      model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=learning_rate),
                    loss='categorical_crossentropy',
                    metrics=['accuracy'])
  
      model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, verbose=1)
  
      _, accuracy = model.evaluate(x_test, y_test, verbose=0)
      return accuracy
  