A large deviation principle for the free energy of random Gibbs measures with application to the REM