Make a gradient map layer, **Layer → New Adjustment Layer → Gradient Map...**.

[![gradient map][1]][1]

**Image 1**: Gradient map applied on image (photo [source](https://www.pexels.com/photo/portrait-of-young-attractive-girl-listening-to-music-with-headphones-6403/))

Obviously this effect can also be done without gradient maps. Here are some ways:

* Make image grayscale, save that as a selection. Fill background color, load selection, make new layer fill foreground color.

* make image grayscale, apply curves on that. This has the benefit of being able to control the interpolation per channel.

But there are more ways..

  [1]: https://i.sstatic.net/RkaYa.png