Hello AnandFromLexington,
I'm sorry to hear you are having issues with your iPhone. I also apologize, I'm a bit unclear on the exact nature of the issue you are describing, or why you feel the gyroscope isn't working. If the issue is limited to incorrect rotation or orientation when using your iPhone, you may find the information and troubleshooting steps outlined in the following article helpful (most of which it sounds like you may have already done):
If the screen doesn't rotate on your iPhone, iPad, or iPod touch - Apple Support
If you are still having issues even with the iPhone restored to factory settings and *without* migrating your data back, you may need to have it serviced. The following page may be helpful:
Apple - Support - Service Answer Center
Sincerely,
- Brenden