input: Write a function to implement a Machine Learning model in Python which can recognize handwritten digits from 0 to 9 using the MNIST dataset. The function should preprocess the data, define and compile the neural network model, and then fit the model to the training data. The function should return the trained model.
  
  assert type(handwritten_digit_recognizer()).__name__ == 'Model'
  training_status = handwritten_digit_recognizer().history['val_accuracy'][-1]
  assert training_status > 0.8
output: 
  def handwritten_digit_recognizer():
      from tensorflow.keras.datasets import mnist
      from tensorflow.keras.models import Sequential
      from tensorflow.keras.layers import Dense, Flatten
      from tensorflow.keras.utils import to_categorical
  
      (x_train, y_train), (x_test, y_test) = mnist.load_data()
      x_train = x_train.reshape(-1, 28*28) / 255.0
      x_test = x_test.reshape(-1, 28*28) / 255.0
      y_train = to_categorical(y_train, 10)
      y_test = to_categorical(y_test, 10)
  
      model = Sequential([
          Flatten(input_shape=(28*28,)),
          Dense(128, activation='relu'),
          Dense(64, activation='relu'),
          Dense(10, activation='softmax')
      ])
  
      model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
      model.fit(x_train, y_train, validation_data=(x_test, y_test), epochs=10, batch_size=32)
  
      return model
  