The way I was taught to solve boundary value problems with non-homogeneous boundary value conditions is via the introduction of a second term to satisfy the boundary, i.e. set
$$ u(x,t) = \phi(x,t) + v(x,t)$$
where $\phi(x,t)$ satisfies the boundary conditions.
So, we need
$$\phi_x(0,t)=0 \text{ and }\phi(L,t)=\sin^2\frac{t}{2}.$$
The simplest function that satisfies these conditions is
$$\phi(x,t)=\sin^2\frac{t}{2},$$
which means $u$ is of the form
$$u(x,t)=\sin^2\frac{t}{2}+v(x,t).$$
The pde now required to solve, for $v$ after substituting into your equation is
$$v_t=v_{xx}-\cos\frac{t}{2}.$$
Substituting into the boundary conditions also gives
$$v_x(0,t)=0\text{ and } v(L,t)=0$$
and the initial condition condition
$$v(x,0)=0.$$
This transforms the original problem with non-homogeneous boundary conditions into one with homogeneous boundary conditions, but a non-homogeneous pde, which is easier to solve.
Can you continue from this point?