If you put window screen over all the openings on your coop it will help keep them out. You can cut a piece of screen slightly larger than your door opening, cut it from the bottom in strips that hang down (don't cut all the way to the top) and attach over your door, birds can still go in and out, will make it harder for the gnats. I have a small fan in the rafters of my coop that blows over the roosts, it helps keep the gnats and mosquitos from being able to land on the birds. I also planted a bunch of rosemary shrubs in my run, the birds tend to hunker down under them, I think the oils from the plants help discourage the gnats also. I make my own non-toxic bug repellant for myself and I put rosemary oil in it, otherwise I get eaten alive too, and it works well. Depending on the type of fly/gnat, it may just be a major irritant, but there are some that can do some harm. Last year there were several posts on here about a particular kind that was killing birds, can't remember what they were called.

Also some flies do not like vanilla, if you can hang some vanilla scented air fresheners around that may help. Some people have made a spray containing vanilla and used it in their coops.