This is complicated so it's important to speak with an immigration attorney before you take any steps. The better option is to apply from within the U.S. but doing this while in the U.S. as a tourist is problematic. The other path, through a U.S. Consulate abroad, raises no legal concerns but can take a very long time (compared to a U.S. based application).