The problem of young women (girls) and other groups (minorities) being under-represented in certain educational fields and professions is a deep problem with only complex solutions. There is no magic solution that will make it right.
First some data points.
According to the Guardian, the problem seems to be somewhat localized to the US, Britain, and Canada . There is something about the educational and social systems in these countries that seems to drive some people away.
In the early years of education, young girls outperform boys by a large margin. There is even a worry that the educational system disadvantages boys up to a certain age.
In the US, at least, one of the influences is that elementary teachers are predominantly women, giving young girls positive role models. Many young females want to be teachers since they see how important teachers are in their own lives.
Some solutions are pretty rotten (See the Guardian article, above). I read there that you should emphasize "cooking" as embodying both science and, well..., something.
One possibility that helps explain the discrepancy among high school students is the conflict between smart and cool. For young kids these are aligned - teachers and parents give a lot of positive feedback for being smart to youngsters. But at some point, kids start to differentiate their personalities from others, especially teachers and parents. In some groups smart != cool and since students of that age are spending more time with peers, cool always wins. Boys want to be seen as cool both by other boys and by girls. The same is true for girls. Being smart takes second place. For the overly geeky, poorly socialized, boys it matter less as they won't be seen as cool in general, but only by other geeky guys.
From the above, I suggest two approaches to the problem.
The first is to provide mentors to young women and members of minorities. These mentors should, if at all possible, be similar to the students. Female, Black, Hispanic, Introverted, Poor, whatever. The mentors need to provide both some of the instruction but serve as role-models primarily. Can one or two of your female students visit a female professional at work (Take a student to work day)? Make this mentorship part of your educational process. A group of mentors can also provide a boost to the students later in life if you can make the contacts permanent.
The second approach is to make smart = cool again. My personal approach to this is to emphasize group work in courses over individual work. Make learning a social process, not just an individual one. Let students work together with peers who share characteristics. Groups of girls, for example. Better is groups in which girls are a substantial part, though not completely dominant. Cliquishness isn't likely an improvement and every student needs to learn to work with others who are not just like themselves.
You also, as a teacher need to be aware of dynamics in the classroom. Who asks the questions? Who provides help? Who dominates the conversations? Who do you call on to answer questions? Where do students sit in the room? Who do they sit with? All of these things can be indicators of things that may need addressing.
Make your successful girls and minority students ambassadors for your program.
Try to get girls (and minorities...) to form clubs and study groups in which they can work together, so that the socialization itself is part of the coolness.
On the other hand, treat every student as an individual, no matter what their "characteristics." You may not be a natural mentor for some students but you can show through your respect for them and the way to treat them and answer their concerns, that their learning and future matter to you.
Sorry that this isn't a more complete answer. It is a deep problem without facile solutions.