Take thiis advice with a grain of salt and lots of logic.
If (and this is a big "if" here) she is anything like me, and she is hurting because you didn't give her the right attention, go after her in a way you never have before.
Think back on all the times she may have been upset with you and try to remember what her words were. What was she asking for? This is where love languages comes in handy because it might be something you never thought of as showing love.
If she is leaving because she thinks you wouldn't care if she did, you need to show her you care.
But desperation is bad because it makes it seem insincere, as if you are only finally putting effort into the relationship because you are close to losing it.
Learn what she needs to feel loved, then show her you know how.