code: """FastAPI app creation, logger configuration and main API routes."""
  
  import logging
  
  from fastapi import Depends, FastAPI, Request
  from fastapi.middleware.cors import CORSMiddleware
  from injector import Injector
  from llama_index.core.callbacks import CallbackManager
  from llama_index.core.callbacks.global_handlers import create_global_handler
  from llama_index.core.settings import Settings as LlamaIndexSettings
  
  from private_gpt.server.chat.chat_router import chat_router
  from private_gpt.server.chunks.chunks_router import chunks_router
  from private_gpt.server.completions.completions_router import completions_router
  from private_gpt.server.embeddings.embeddings_router import embeddings_router
  from private_gpt.server.health.health_router import health_router
  from private_gpt.server.ingest.ingest_router import ingest_router
  from private_gpt.settings.settings import Settings
  
  logger = logging.getLogger(__name__)
  
  
  def create_app(root_injector: Injector) -> FastAPI:
  
      # Start the API
      async def bind_injector_to_request(request: Request) -> None:
          request.state.injector = root_injector
  
      app = FastAPI(dependencies=[Depends(bind_injector_to_request)])
  
      app.include_router(completions_router)
      app.include_router(chat_router)
      app.include_router(chunks_router)
      app.include_router(ingest_router)
      app.include_router(embeddings_router)
      app.include_router(health_router)
  
      # Add LlamaIndex simple observability
      global_handler = create_global_handler("simple")
      LlamaIndexSettings.callback_manager = CallbackManager([global_handler])
  
      settings = root_injector.get(Settings)
      if settings.server.cors.enabled:
          logger.debug("Setting up CORS middleware")
          app.add_middleware(
              CORSMiddleware,
              allow_credentials=settings.server.cors.allow_credentials,
              allow_origins=settings.server.cors.allow_origins,
              allow_origin_regex=settings.server.cors.allow_origin_regex,
              allow_methods=settings.server.cors.allow_methods,
              allow_headers=settings.server.cors.allow_headers,
          )
  
      if settings.ui.enabled:
          logger.debug("Importing the UI module")
          try:
              from private_gpt.ui.ui import PrivateGptUi
          except ImportError as e:
              raise ImportError(
                  "UI dependencies not found, install with `poetry install --extras ui`"
              ) from e
  
          ui = root_injector.get(PrivateGptUi)
          ui.mount_in_app(app, settings.ui.path)
  
      return app
  
apis: llama_index.core.callbacks.CallbackManager llama_index.core.callbacks.global_handlers.create_global_handler
extract_api: [((894, 921), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (911, 921), False, 'import logging\n'), ((1479, 1510), 'llama_index.core.callbacks.global_handlers.create_global_handler', 'create_global_handler', (['"""simple"""'], {}), "('simple')\n", (1500, 1510), False, 'from llama_index.core.callbacks.global_handlers import create_global_handler\n'), ((1553, 1586), 'llama_index.core.callbacks.CallbackManager', 'CallbackManager', (['[global_handler]'], {}), '([global_handler])\n', (1568, 1586), False, 'from llama_index.core.callbacks import CallbackManager\n'), ((1143, 1176), 'fastapi.Depends', 'Depends', (['bind_injector_to_request'], {}), '(bind_injector_to_request)\n', (1150, 1176), False, 'from fastapi import Depends, FastAPI, Request\n')]