Upcoming is a pretty good resource for finding events in SF. You might want to browse through their listings as well as the Guardian and Chronice calendar of events.
Last year I spent the Fourth at the Berkeley Marina and had a pretty good time. There was lots of good food and free sailboat rides!
Another resource for finding things to do is Going. Personally, I plan to attend the Fillmore Jazz Festival. Free music, cool vendors, drinking beer and wine outside. I also plan to take my son to the Marin County Fair.