My question is: is it better to give up the Internet altogether, which will include giving up the good things that I do on the Internet, or is it better to treat myself and my heart and try to give up the sin altogether? I am confused between the two choices.
The solution may not be to advise you to give up the Internet, because there are also satellite channels and magazines. Yes, you may find in the Internet things that you will not find in the other sources mentioned, but what we are talking about here is the basis for your committing sin and blocking one means will not prevent a person from committing sin.
The solution in a case like this is to increase your fear of Allah and your respect of Allah so that this will prevent you from falling into that which Allah has forbidden.
You have to remember death a great deal, so that this will motivate you to prepare for it.
What you have to do is to treat yourself so that you will stop committing the sin of looking at haraam things wherever the image may be.
One of the most beneficial of remedies is hastening to get married if you can do so. The Prophet (blessings and peace of Allah be upon him) said: “O young men, whoever among you can afford it, let him get married, for it is more effective in lowering the gaze and guarding one’s chastity.” Narrated by al-Bukhaari (5065) and Muslim (1400).
With regard to whether you should stay on the Internet or not, that is subject to further discussion:
(a) If you think it most likely that you will give up the sin of haraam looking altogether by getting off the Internet, then cut off all connection to it, so as to protect yourself and remedy your problem, until you become certain that if you go back to it, you will only take part in what is good in it.
Concern about reforming yourself should take precedence over your concern about reforming others.
(b) If you think it most likely that you will never give up the sin of haraam looking and that you will be distracted by watching garbage on satellite channels, and looking at newspapers and magazines, then our advice to you is to stay on the Internet, on condition that you strive hard to keep away from every haraam thing that can be watched or listened to. We believe that if you limit yourself to visiting helpful and beneficial academic and news websites, and limit yourself to regular appointments in voice chat rooms on Paltalk, where you can offer useful and beneficial material and listen to material that will increase your knowledge and faith, then we believe that you will never find time to go to harmful, bad and haraam sites.
Hasten immediately to repent sincerely from every sin that you have committed, regret your transgressions against Allah, and resolve firmly not to go back to those sins. Turn to Allah with a pure and sound heart, and ask Him for help and guidance, and to purify you of haraam things. And give thanks for the blessings that Allah has bestowed upon you by using them to do things that your Lord loves and will make Him pleased with you.
See also the answer to question number 20229, which contains useful information on means of lowering the gaze.
And Allah knows best.