The girl you are talking to will be much more receptive and less likely to be offended if you explain that you need to leave or that you have to get back to your friends rather than continue the conversation without engaging in it or while looking bored and disinterested.
Give her a legitimate reason.
Women are very perceptive and are likely to see through lies or false reasons. Even if you just really don't want to talk to her anymore, telling her that you have to take a phone call or check on your friends is more decent than telling her your grandmother just broke her hip and you have to rush to the hospital.
There is no reason to be impolite to someone, even if you are trying to end a boring or unappealing conversation with them. Show her respect and you'll have a smoother exit, with less chance of either one of you becoming embarrassed or angry.
Compliment her as you end the conversation.
It's a great way to leave her feeling good about the interaction and to make a smooth exit. Let her know that it was nice talking to her, wish her luck with something she brought up in the conversation (such as earning her degree or a new job) and tell her to have a nice evening.
End the conversation as soon as it becomes apparent that the conversation should stop. Wait until there is a break in the conversation and then politely segue into telling her goodbye. Ceasing the conversation in a timely fashion will help avoid any awkwardness or discomfort for either of you.