Best Answer - Chosen by Voters
I have heard that if you keep some basil growing in your kitchen, that the smell will drive away the flies. I don't know if this works on gnats as well or not, and I haven't tried it myself, either.
Keep your house clean of food and other smelly garbage, and make sure your yard is clean as well. The flies and gnats follow the scents of rotting things (esp vegetables and meat), as it is their "job" in the world to help them decay. Remove their prospects of food, and they will go away as well.
You can also try hanging up some dryer sheets (Downy or etc.); supposedly the smell drives away insects. If you already have them sitting around the house, why not try it?