docstr: The PythonServer Class enables to easily get your machine learning server up and running.
  
  Arguments:
      input_type: Optional `input_type` to be provided. This needs to be a pydantic BaseModel class.
          The default data type is good enough for the basic usecases and it expects the data
          to be a json object that has one key called `payload`
  
          .. code-block:: python
  
              input_data = {"payload": "some data"}
  
          and this can be accessed as `request.payload` in the `predict` method.
  
          .. code-block:: python
  
              def predict(self, request):
                  data = request.payload
  
      output_type: Optional `output_type` to be provided. This needs to be a pydantic BaseModel class.
          The default data type is good enough for the basic usecases. It expects the return value of
          the `predict` method to be a dictionary with one key called `prediction`.
  
          .. code-block:: python
  
              def predict(self, request):
                  # some code
                  return {"prediction": "some data"}
  
          and this can be accessed as `response.json()["prediction"]` in the client if
          you are using requests library
  
  Example:
  
      >>> from lightning.app.components.serve.python_server import PythonServer
      >>> from lightning.app import LightningApp
      ...
      >>> class SimpleServer(PythonServer):
      ...
      ...     def setup(self):
      ...         self._model = lambda x: x + " " + x
      ...
      ...     def predict(self, request):
      ...         return {"prediction": self._model(request.image)}
      ...
      >>> app = LightningApp(SimpleServer())
docstr_tok: ["The","PythonServer","Class","enables","to","easily","get","your","machine","learning","server","up","and","running",".","Arguments",":","input_type",":","Optional","`","input_type","`","to","be","provided",".","This","needs","to","be","a","pydantic","BaseModel","class",".","The","default","data","type","is","good","enough","for","the","basic","usecases","and","it","expects","the","data","to","be","a","json","object","that","has","one","key","called","`","payload","`","..","code-block",":",":","python","input_data","=","{","``","payload","''",":","``","some","data","''","}","and","this","can","be","accessed","as","`","request.payload","`","in","the","`","predict","`","method",".","..","code-block",":",":","python","def","predict","(","self",",","request",")",":","data","=","request.payload","output_type",":","Optional","`","output_type","`","to","be","provided",".","This","needs","to","be","a","pydantic","BaseModel","class",".","The","default","data","type","is","good","enough","for","the","basic","usecases",".","It","expects","the","return","value","of","the","`","predict","`","method","to","be","a","dictionary","with","one","key","called","`","prediction","`",".","..","code-block",":",":","python","def","predict","(","self",",","request",")",":","#","some","code","return","{","``","prediction","''",":","``","some","data","''","}","and","this","can","be","accessed","as","`","response.json","(",")","[","``","prediction","''","]","`","in","the","client","if","you","are","using","requests","library","Example",":",">",">",">","from","lightning.app.components.serve.python_server","import","PythonServer",">",">",">","from","lightning.app","import","LightningApp","...",">",">",">","class","SimpleServer","(","PythonServer",")",":","...","...","def","setup","(","self",")",":","...","self._model","=","lambda","x",":","x","+","``","``","+","x","...","...","def","predict","(","self",",","request",")",":","...","return","{","``","prediction","''",":","self._model","(","request.image",")","}","...",">",">",">","app","=","LightningApp","(","SimpleServer","(",")",")"]
code: def __init__(  # type: ignore
      self,
      input_type: type = _DefaultInputData,
      output_type: type = _DefaultOutputData,
      **kwargs: Any,
  ):
      """The PythonServer Class enables to easily get your machine learning server up and running.
  
      Arguments:
          input_type: Optional `input_type` to be provided. This needs to be a pydantic BaseModel class.
              The default data type is good enough for the basic usecases and it expects the data
              to be a json object that has one key called `payload`
  
              .. code-block:: python
  
                  input_data = {"payload": "some data"}
  
              and this can be accessed as `request.payload` in the `predict` method.
  
              .. code-block:: python
  
                  def predict(self, request):
                      data = request.payload
  
          output_type: Optional `output_type` to be provided. This needs to be a pydantic BaseModel class.
              The default data type is good enough for the basic usecases. It expects the return value of
              the `predict` method to be a dictionary with one key called `prediction`.
  
              .. code-block:: python
  
                  def predict(self, request):
                      # some code
                      return {"prediction": "some data"}
  
              and this can be accessed as `response.json()["prediction"]` in the client if
              you are using requests library
  
      Example:
  
          >>> from lightning.app.components.serve.python_server import PythonServer
          >>> from lightning.app import LightningApp
          ...
          >>> class SimpleServer(PythonServer):
          ...
          ...     def setup(self):
          ...         self._model = lambda x: x + " " + x
          ...
          ...     def predict(self, request):
          ...         return {"prediction": self._model(request.image)}
          ...
          >>> app = LightningApp(SimpleServer())
  
      """
      super().__init__(parallel=True, **kwargs)
      if not issubclass(input_type, BaseModel):
          raise TypeError(
              "input_type must be a pydantic BaseModel class"
          )
      if not issubclass(output_type, BaseModel):
          raise TypeError(
              "output_type must be a pydantic BaseModel class"
          )
      self._input_type = input_type
      self._output_type = output_type
  
      self.ready = False
  
imports: import abc
  import asyncio
  import base64
  import os
  import platform
  from typing import TYPE_CHECKING, Any, Dict, Optional
  import requests
  import uvicorn
  from fastapi import FastAPI
  from lightning_utilities.core.imports import compare_version, module_available
  from pydantic import BaseModel
  from lightning.app.core.work import LightningWork
  from lightning.app.utilities.app_helpers import Logger
  from lightning.app.utilities.imports import _is_torch_available, requires
label_desc: Use image node_id 1 to create a new PythonServer object from inherited base classes: LightningWork, abc with example: obj = PythonServer(input_type, output_type)