input: Write a function to generate a Machine Learning model in Python using TensorFlow and Keras that can recognize handwritten digits from 0 to 9. The function should load and preprocess the MNIST dataset, define a neural network model with one hidden layer, compile the model, and fit it to the training data. The function should return the trained model.
  
  
  from tensorflow.keras.datasets import mnist
  from tensorflow.keras.layers import Dense, Input, Dropout
  from tensorflow.keras.models import Model
  from tensorflow.keras.utils import to_categorical
  
  def digit_recognition_model(epochs=5, batch_size=128):
      # Loading data
      (X_train, y_train), (X_test, y_test) = mnist.load_data()
  
      # Reshape inputs from (60000, 28, 28) to (60000, 784)
      X_train = X_train.reshape(60000, 784)
      X_test = X_test.reshape(10000, 784)
  
      # Normalize pixel values
      X_train = X_train.astype('float32')
      X_train /= 255
      X_test = X_test.astype('float32')
      X_test /= 255
  
      # One-hot encode labels
      y_train = to_categorical(y_train, num_classes=10)
      y_test = to_categorical(y_test, num_classes=10)
  
      # Defining the neural network model
      inputs = Input(shape=(784,))
      h1 = Dense(64, activation='relu')(inputs)
      h2 = Dropout(0.5)(h1)
      outputs = Dense(10, activation='softmax')(h2)
  
      model = Model(inputs=inputs, outputs=outputs)
      model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  
      # Fitting the model
      model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=epochs, batch_size=batch_size)
  
      return model
  
  # Test cases
  assert digit_recognition_model().evaluate(X_test.reshape(10000, 784)/255, to_categorical(y_test, num_classes=10))[1] > 0.95
output: def digit_recognition_model(epochs=5, batch_size=128):
      (X_train, y_train), (X_test, y_test) = mnist.load_data()
      X_train = X_train.reshape(60000, 784)
      X_test = X_test.reshape(10000, 784)
      X_train = X_train.astype('float32')
      X_train /= 255
      X_test = X_test.astype('float32')
      X_test /= 255
      y_train = to_categorical(y_train, num_classes=10)
      y_test = to_categorical(y_test, num_classes=10)
      inputs = Input(shape=(784,))
      h1 = Dense(64, activation='relu')(inputs)
      h2 = Dropout(0.5)(h1)
      outputs = Dense(10, activation='softmax')(h2)
      model = Model(inputs=inputs, outputs=outputs)
      model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
      model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=epochs, batch_size=batch_size)
      return model