We have gnat issues a lot where I live, since I am surrounded by swampland. It is always very humid so they crop up constantly if we don't keep things pristine. Best I can say is to monitor your moisture levels, too wet and they buzz around looking for somewhere nice to lay eggs. I even have gnats attracted to condensation in my buckets, when I am rotting fresh wood. A good seal will help prevent that. With adult beetles, wet food or fruit also obviously attracts flies, with banana being the worst with that in my experience so far. I will have zero gnats and getting fresh fruit from the store will "bring in" gnats, or so it seems to me. Bags of potatoes that are kept in storage can also have gnats if you have storage like that. Apple much less so. Keeping stuff in the fridge obviously helps with it all. Beetle jelly would be near zero for gnats. I hear banana jelly will attract gnats anyway but brown sugar not so much.
I check my larva every other week and I have not had gnats in any of them, even with chunks of apple buried in them... I do not dig out my grubs. I had a small gnat issue with my female ox beetle's egg bucket last week, but removing her food and changing out her wettest substrate completely eliminated that, as they were attracted to the banana scent on her grass on the top layer of her bucket. Fresh grass and buried food, no gnats.
Also check your sinks! If you have a food trap or garbage disposal in your kitchen or pour soups out in there, gnats will go into your drain and breed like crazy, which will spread that way or from your garbage and into your bug areas. Drain flies too. I keep my buckets in my front room, so when I get gnats, I check my kitchen and that's usually the case, not the beetles. I'm a full time college student with roommates, so our sink is sometimes neglected and this happens on very busy weeks. Grubs fed on nothing but flake soil shouldn't attract gnats unless you are mixing in dog food or bran mash, which can attract them if it's too damp and it's left where gnats can get inside. Best I can say is to do a partial change of your substrate and treat new substrate with boiling water to kill off anything that could be in it if your substrate storage and then dry it out somewhere outside away from your lawn and your garbage.
If your holes on your cups are too big and you don't want to change cups or move your grubs, cover it with a strip of thin fabric! Panty hose is really great. It will breathe fine and then nothing can get through the fabric and through the holes. The guys above have given good advice, so I guess check your sinks and food storage areas and maybe try a gnat trap. Sticky stuff works better than bottle traps in my opinion, but maybe I just have very smart gnats... good luck!