Update app.py

Moved object initialization outside try/except for better graceful exits.