input: Write a function to generate a REST API with Python and Flask that allows users to create, read, update, and delete records from a database. The function should return the Flask app and the database model. If the input is invalid, return an error message.
  
  assert generate_rest_api() == (Flask App Object, SQLAlchemy Model Object)
output: from flask import Flask, request, jsonify
  from flask_sqlalchemy import SQLAlchemy
  
  def generate_rest_api():
      app = Flask(__name__)
      app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
      db = SQLAlchemy(app)
  
      class Record(db.Model):
          id = db.Column(db.Integer, primary_key=True)
          name = db.Column(db.String(80), nullable=False)
          value = db.Column(db.String(120), nullable=False)
  
          def to_dict(self):
              return {
                  'id': self.id,
                  'name': self.name,
                  'value': self.value
              }
  
      @app.route('/records', methods=['POST'])
      def create_record():
          data = request.get_json()
          if not data or not 'name' in data or not 'value' in data:
              return jsonify({'error': 'Invalid input'}), 400
          new_record = Record(name=data['name'], value=data['value'])
          db.session.add(new_record)
          db.session.commit()
          return jsonify(new_record.to_dict()), 201
  
      @app.route('/records/<int:id>', methods=['GET'])
      def read_record(id):
          record = Record.query.get(id)
          if record is None:
              return jsonify({'error': 'Record not found'}), 404
          return jsonify(record.to_dict())
  
      @app.route('/records/<int:id>', methods=['PUT'])
      def update_record(id):
          data = request.get_json()
          if not data or not 'name' in data or not 'value' in data:
              return jsonify({'error': 'Invalid input'}), 400
          record = Record.query.get(id)
          if record is None:
              return jsonify({'error': 'Record not found'}), 404
          record.name = data['name']
          record.value = data['value']
          db.session.commit()
          return jsonify(record.to_dict())
  
      @app.route('/records/<int:id>', methods=['DELETE'])
      def delete_record(id):
          record = Record.query.get(id)
          if record is None:
              return jsonify({'error': 'Record not found'}), 404
          db.session.delete(record)
          db.session.commit()
          return jsonify({'result': 'Record deleted'})
  
      return app, Record