I have used the following methods:
1) watering with mosquito dunks
2) watering with hydrogen peroxide and water
3) putting up small containers with apple cider vinegar, it attracts the gnats a lot! Just remember to poke holes on the cover of the container.
Since the numbers have reduced a lot after watering with either no.1 or no. 2, I kept the containers with vinegar beside the plants, just in case there were adult stragglers left.