Make a trap. Place a banana peel inside a plastic container. Poke a few holes in the plastic using a toothpick. Make sure the holes are large enough for a fruit fly or gnat to crawl through. Place the trap near problem areas. The flies will be able to enter but won't be able to exit.
Eliminate the things attracting the pests. You can usually find what is attracting the flies or gnats by noticing where they congregate. Compost bins, fruit bowls and potted plants are often the culprits. This is usually the easiest way to get rid of gnats.
Spray an insecticide made for flying insects. These can often be found at grocery and garden supply stores. Follow the instructions on the container, spraying the poison near problem areas but making sure to follow safety precautions.