Spaces:
Runtime error
Runtime error
Download app.py from neurostack-in/pms_server: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/neurostack-in/pms_server/resolve/main/app.py
- Command line
-
hf download hf://spaces/neurostack-in/pms_server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/neurostack-in/pms_server/resolve/main/app.py
1.45 kB
| import os | |
| import sys | |
| from utils.environment import print_configuration_summary, validate_environment_variables | |
| from utils.test_db import test_database_connection, check_required_variables | |
| # ---- STEP 1: Validate environment configuration | |
| print_configuration_summary() | |
| validation_results = validate_environment_variables() | |
| # ---- STEP 2: Test database connection (only if MySQL is configured) | |
| mysql_vars = ['AIVEN_DB_NAME', 'AIVEN_DB_USER', 'AIVEN_DB_PASSWORD', 'AIVEN_DB_HOST'] | |
| if all(os.getenv(var) for var in mysql_vars): | |
| print("\n" + "=" * 50) | |
| print("Testing Database Connection...") | |
| print("=" * 50) | |
| if not test_database_connection(): | |
| print("\n❌ Database connection failed. Exiting...") | |
| print("Please check your database configuration and try again.") | |
| sys.exit(1) | |
| else: | |
| print("\n⚠️ MySQL not configured, using SQLite fallback for development.") | |
| # ---- STEP 3: Run migrations to initialize database | |
| print("\n" + "=" * 50) | |
| print("Running Database Migrations...") | |
| print("=" * 50) | |
| os.system("python manage.py makemigrations") | |
| os.system("python manage.py migrate") | |
| os.system("python manage.py createsuperadmin --username=Admin --email=admin@gmail.com --password=adminpassword") | |
| # ---- STEP 4: Start Django dev server on required Hugging Face port | |
| print("\n" + "=" * 50) | |
| print("Starting Server...") | |
| print("=" * 50) | |
| os.system("uvicorn pms_server.asgi:application --host 0.0.0.0 --port 7860") |