input: Write a function to generate a Machine Learning model in Python that can recognize handwritten digits from 0 to 9. The function should load the MNIST dataset, define a neural network model with an input layer, a hidden layer (with dropout), and an output layer, compile the model, preprocess the data (reshape, normalize, and one-hot encode), and fit the model to the training data. The function should return the trained model. 
  assert generate_model().history['accuracy'][-1] > 0.9
output: 
  from tensorflow.keras.datasets import mnist
  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Dense, Dropout, Flatten
  from tensorflow.keras.utils import to_categorical
  from tensorflow.keras.optimizers import Adam
  
  def generate_model():
      (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, 10)
      y_test = to_categorical(y_test, 10)
      
      model = Sequential()
      model.add(Flatten(input_shape=(28, 28, 1)))
      model.add(Dense(128, activation='relu'))
      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=32, validation_data=(x_test, y_test))
      
      return model
  