The second is slightly incorrect. If you're going to use a relative clause, then the verb "avoid" should match with the subject "that":
tact is the ability that avoids offending people when dealing with problems.
Otherwise both are adjective phrases that modify "ability" in much the same way, and (in this context) have more or less the same meaning. However, the second example is much less common. "Ability" + infinitive is the usual idiomatic expression:
She has the ability to improve her grades, if she only studies harder.
or, better yet:
She is able to improve her grades ...
I suggest you avoid using a relative clause with "ability". It has an affected nuance that only works in very limited contexts.