Constructing variations of Hodge structure using Yang-Mills theory and applications to uniformization