We show how a fermionic quantum gas in an optical lattice and coupled to the field of an optical cavity can self-organize into a state in which the spontaneously emerging cavity field amplitude induces an artificial magnetic field. The fermions form either a chiral insulator or a chiral liquid carrying edge currents. The feedback mechanism via the cavity field enables robust and fast switching of the edge currents and the cavity output can be employed for non-destructive measurements of the atomic dynamics.