To keep gnats away seal off the area where you are. They also hate a cold environment and lots of wind. You could even place a bowl of vinegar to draw them to that area. They will then fall into the liquid and eventually drown.
I had a better idea but too late...
How to Keep Deerflies & Gnats Away?