input: Write a function to generate a Machine Learning model in Python which can recognize handwritten digits from 0 to 9. The function should load the MNIST dataset, define the neural network model, preprocess the data, and fit the model. The function should return the trained model. The model should have an input layer, a hidden layer with a dropout layer, and an output layer. The MNIST dataset should be loaded using Keras' mnist dataset and preprocessed by reshaping, normalizing, and one-hot encoding the labels.
  assert isinstance(handwritten_digit_recognizer(), Model) == True
output: def handwritten_digit_recognizer():
      from tensorflow.keras.datasets import mnist
      from tensorflow.keras.models import Sequential
      from tensorflow.keras.layers import Dense, Dropout
      from tensorflow.keras.utils import to_categorical
      from tensorflow.keras.optimizers import Adam
  
      (x_train, y_train), (x_test, y_test) = mnist.load_data()
      x_train = x_train.reshape(x_train.shape[0], 28 * 28).astype('float32') / 255
      x_test = x_test.reshape(x_test.shape[0], 28 * 28).astype('float32') / 255
      y_train = to_categorical(y_train, 10)
      y_test = to_categorical(y_test, 10)
  
      model = Sequential()
      model.add(Dense(512, activation='relu', input_shape=(28 * 28,)))
      model.add(Dropout(0.2))
      model.add(Dense(10, activation='softmax'))
  
      model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])
      model.fit(x_train, y_train, epochs=10, batch_size=128, validation_data=(x_test, y_test))
  
      return model