You can look at the current schedule. It won't change much. The first train goes thru Riomaggiore to La Spezia at 5:13. You change there and at Pisa. The journey takes 2 1/2 hours, arriving at 7:43. But 50 minutes of that is at Pisa waiting for the train to the airport,ma short ride. You could probably do better with a taxi for that part.

Hi Michelle. Yes, 5:13 train in Rio; likely you will be in Pisa by 7am for an easy cab to airport. But a couple of thoughts.. - Do you really want to get up in Rio to be at station by 5am? - In case of train problems, are you OK missing your flight?
Like I say, it would probably worki fine; just depends on how important that last night in Rio is; you could consider going to Pisa and staying there instead. Enjoy your trip!