'Tensor' object has no attribute 'lower'
The tensor must be passed to the layer when you are calling it, and not as an argument. Therefore it must be like this:
x = Flatten()(x) # first the layer is constructed and then it is called on x
To make it more clear, it is equivalent to this:
flatten_layer = Flatten() # instantiate the layerx = flatten_layer(x) # call it on the given tensor