A possible approach is the sandwich technique.
Here's one way to adapt it.
Hey John! Good to see you!
I hope you don't mind if I don't talk much today, I've got this work to finish.
Oh, no need to leave, it's good to have company, I just can't talk right now.
You've got a couple things going on; I'll try to separate them.
First of all is your desire to be left alone. Second is your desire to not be rude or to offend people.
I'll start with the non-offensive part first. Part of the challenge here is: what do you normally portray yourself as? Are you always trying to be left alone? Do you only want to interact ...
I realize this answer may cover things you didn't ask about - but bear with me - they may be connected.
I read your question as a request for having some quiet time on your own, without being unnessecarily rude. There is nothing wrong with that at all, but it makes me wonder if you've given a thought to how you want your relationship with your co-workers to ...