To get rid of gnats and fruit flies here's what I did this spring.
I took a 2 liter bottle and put a few mashed up bananas in the bottle and then added a little water just enough to come up to the bananas.
The gnats and fruit flies then went into the bottle and got drowned in the water and couldn't come back out.
You can also put up fly tapes in your home and the gnats and flies will get stuck on that fly tape and then you can just throw the fly tape away.