Gnats are from fruit fly family and are often called vinegar flies. They like warm, moist conditions with decaying vegetation, particularly rotten fruits which of course ferment and smell like vinegar.
You can put down traps, such as a narrow necked bottle, or coffee filter that goes into a container, and put some vinegar or wine in the bottom. This will attract the flying gnats and they will drown as they can't fly out.
It's really better to kill the eggs and larvae if possible. This is easy in houseplants or container plants as you can remove the top layer of soil and put sand or something that is not decaying on the top until you've stopped the cycle of the flies laying eggs and the eggs hatching and so on.
Put a citronella spray or band on when near gnats outside otherwise they will bite you. M.O