class_docstr: An HTTP server implemented based on FastAPI
class_docstr_tok: ["An","HTTP","server","implemented","based","on","FastAPI"]
code: def __init__(self, api_service: "APIService"):
      self._app = fastapi.FastAPI()
  
      @self._app.get("/")
      def index():
          return api_service.desc
  
      def func_wrapper(
          func: Callable,
          input_model: "IOBase",
          output_model: "IOBase",
          request: fastapi.Request,
      ):
          if input_model is None:
              input_model = JSON()
  
          if output_model is None:
              output_model = JSON()
  
          try:
              signature = inspect.signature(func)
              if len(signature.parameters.keys()) == 0:
                  return output_model.to_http(func())
  
              values = input_model.from_http(request)
              if len(signature.parameters.keys()) > 1:
                  if isinstance(values, dict):
                      ret = output_model.to_http(func(**values))
                  else:
                      ret = output_model.to_http(func(*values))
              else:
                  ret = output_model.to_http(func(values))
              return ret
          except Exception as e:
              err = traceback.format_exc()
              engine_log.error(err)
              raise RuntimeError(err) from e
  
      for router in api_service.routers:
          wrapper = partial(
              func_wrapper,
              router.func,
              router.input_model,
              router.output_model,
          )
          wrapper.__name__ = router.func.__name__
          wrapper.__doc__ = router.func.__doc__
          self._app.add_api_route(
              router.path, wrapper, methods=["POST"]
          )
  
file_path: towhee/towhee/serve/http/server.py
imports: from typing import Callable
  import inspect
  from functools import partial
  import traceback
  from towhee.utils.thirdparty.fastapi_utils import fastapi
  from towhee.utils.thirdparty.uvicorn_util import uvicorn
  from towhee.serve.io import JSON
  from towhee.utils.log import engine_log
label_desc: Use image node_id 1 to create a new HTTPServer object  with example: obj = HTTPServer(api_service)