Okay, You are doing right so far,
Just take the components of length, take x axis as the refrence and w.r.t it take out potential energy of system.
so, that would be $m_r(L_r/2) cos\theta $ for the rod above ,
From vertically opposite angles,
and $- m_l(L_l/2)cos\theta $
total energy hence = $P_r +P_l $
$=m_r(L_r/2) cos\theta - m_l(L_l/2)cos\theta $