What to do if I have seen an exam before I have taken it?
In a situation in which you would suffer no matter what you do, you can also work to protect yourself.
An anonymous note to the professor that the exam has been compromised and that there are photographs of it circulating comes close to resolving the issue. The person who took the photo likely deserves punishment, of course, so this solution doesn't resolve that. But at least academic integrity is preserved. The professor will need to provide a new exam, of course.
The professor may also announce to the class that there is a problem and ask that whoever sent the anonymous note inform him of their identity. You may have to deal with that.
Also, you may not be the only student struggling with this.
If you are friends with the person who took the photo, you could also confront him/her with a suggestion that they step forward. If they do this before an accusation is made, I would think any punishment would be less than otherwise.
I agree with the advice offered by Buffy. Moreover, you write:
I feel bad and unethical about seeing it, as it seems to be cheating for me
To emphasize, it doesn't just seem to be cheating, it is cheating: it's not just that you are aware of others cheating, but you yourself have already gained illicit knowledge about questions that will be on the exam. As such, if you take no further action to inform the professor of the situation and simply go and take the exam, you have not just helped others to cheat, but in fact have directly participated in cheating yourself.
So, as far as ethical dilemmas go, this one is a complete no-brainer; you simply have no ethical choice other than to let the professor know about the existence of the photo ahead of the exam. Do it anonymously if you wish, and the question of whether to let the professor know who took the photo is a less obvious one (with both options being pretty reasonable in my opinion), but it looks like you understand perfectly well that taking the exam after what you saw would be unethical and quite likely to get you into serious trouble. I commend you for having a moral compass and the good sense to realize you cannot just sit by idly and pretend this never happened. Good luck! Do consider adding an update to your question later on to let us know how things worked out.
In addition to ethics, you should also consider what the implications are if you are found out to have told somebody. What they are, is highly cultural-dependent - if you are unfamiliar with the culture you are in, ask organizations like a student union or add a culture tag. I lived in several countries ("corrupt" ones and countries which were a dictatorship previously involving a Secret Police) where ratting out someone is perceived as much worse than what this student did. (I also know many high school teachers and professors who share the viewpoint that basic solidarity among students dictates not ratting out someone in this situation.) This could make your life bad - in university and also if your future employees would find out about that episode. Unfortunately, ethics and reality are not always the same.
I am not saying you should not tell someone. But find out before what the risks are, how you can protect and be as anonymous as possible.