Spaces:
Build error
Build error
Hkoradiya123
feat: Initialize frontend with Zustand for state management, Tailwind CSS for styling, and TypeScript for type safety
4854e2b Download backend/init_app.py from jinksQspider/fmproService: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/jinksQspider/fmproService/resolve/main/backend/init_app.py
- Command line
-
hf download hf://spaces/jinksQspider/fmproService/backend/init_app.py
-
curl -L -o init_app.py https://huggingface.co/spaces/jinksQspider/fmproService/resolve/main/backend/init_app.py
2.59 kB
| """Startup and initialization script for the Face Inference Platform.""" | |
| import logging | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).parent)) | |
| from app.core.database import SessionLocal, init_db | |
| from app.core.config import settings | |
| from app.core.security import hash_password | |
| from app.models import Tenant, User, UserRole | |
| from app.services.auth_service import AuthService, TenantService | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def init_application(): | |
| """Create database tables and default development admin.""" | |
| logger.info("Initializing Face Inference Platform...") | |
| logger.info("Initializing database...") | |
| init_db() | |
| db = SessionLocal() | |
| try: | |
| tenant = db.query(Tenant).filter(Tenant.name == "development").first() | |
| if not tenant: | |
| logger.info("Creating default development tenant...") | |
| tenant = TenantService.create_tenant( | |
| db=db, | |
| name="development", | |
| plan="enterprise", | |
| ) | |
| admin_email = settings.ADMIN_DEFAULT_EMAIL | |
| admin_password = settings.ADMIN_DEFAULT_PASSWORD | |
| admin = ( | |
| db.query(User) | |
| .filter( | |
| User.tenant_id == tenant.id, | |
| User.role == UserRole.ADMIN, | |
| ) | |
| .order_by(User.created_at.asc()) | |
| .first() | |
| ) | |
| if not admin: | |
| logger.info("Creating default admin user...") | |
| admin = AuthService.register_user( | |
| db=db, | |
| email=admin_email, | |
| password=admin_password, | |
| full_name="Admin User", | |
| tenant_id=tenant.id, | |
| role=UserRole.ADMIN, | |
| ) | |
| logger.info("Default admin user created: %s", admin.email) | |
| else: | |
| admin.email = admin_email | |
| admin.password_hash = hash_password(admin_password) | |
| admin.role = UserRole.ADMIN | |
| admin.is_active = True | |
| db.commit() | |
| db.refresh(admin) | |
| logger.info("Default admin user reset: %s", admin.email) | |
| logger.info("Default credentials for testing:") | |
| logger.info(" Email: %s", admin_email) | |
| logger.info(" Password: %s", admin_password) | |
| logger.info("Application ready. API docs: http://localhost:8000/docs") | |
| except Exception as exc: | |
| logger.error("Error initializing application: %s", exc) | |
| raise | |
| finally: | |
| db.close() | |
| if __name__ == "__main__": | |
| init_application() | |