class_docstr: !
  Integrate multiple model convertion tools, and provide convertion service for users.
  When user uploads a model to this server, convert model and upload the results to VDL Bos.
  When user downloads the model, we get the data from Bos and send it to client.
  Maybe users can download from bos directy if frontend can achieve it.
docstr: Convert onnx model to paddle model.
docstr_tok: ["Convert","onnx","model","to","paddle","model","."]
code: def onnx2paddle_model_convert(
      self, convert_to_lite, lite_valid_places, lite_model_type
  ):  # noqa:C901
      """
      Convert onnx model to paddle model.
      """
      model_handle = request.files["model"]
      data = model_handle.stream.read()
      result = {}
      # Do a simple data verification
      if convert_to_lite in ["true", "True", "yes", "Yes", "y"]:
          convert_to_lite = True
      else:
          convert_to_lite = False
  
      if lite_valid_places not in [
          "arm",
          "opencl",
          "x86",
          "metal",
          "xpu",
          "bm",
          "mlu",
          "intel_fpga",
          "huawei_ascend_npu",
          "imagination_nna",
          "rockchip_npu",
          "mediatek_apu",
          "huawei_kirin_npu",
          "amlogic_npu",
      ]:
          lite_valid_places = "arm"
      if lite_model_type not in ["protobuf", "naive_buffer"]:
          lite_model_type = "naive_buffer"
  
      # call x2paddle to convert models
      hl = hashlib.md5()
      hl.update(data)
      identity = hl.hexdigest()
      result["request_id"] = identity
  
      target_path = os.path.join(
          X2PADDLE_CACHE_PATH, "onnx2paddle", identity
      )
      if not os.path.exists(target_path):
          os.makedirs(target_path, exist_ok=True)
      with tempfile.NamedTemporaryFile() as fp:
          fp.write(data)
          fp.flush()
          try:
              import onnx  # noqa: F401
          except Exception:
              raise RuntimeError(
                  '[ERROR] onnx is not installed, use "pip install onnx>=1.6.0".'
              )
          try:
              if convert_to_lite is False:
                  with paddle.fluid.dygraph.guard():
                      onnx2paddle(
                          fp.name,
                          target_path,
                          convert_to_lite=convert_to_lite,
                      )
              else:
                  with paddle.fluid.dygraph.guard():
                      onnx2paddle(
                          fp.name,
                          target_path,
                          convert_to_lite=convert_to_lite,
                          lite_valid_places=lite_valid_places,
                          lite_model_type=lite_model_type,
                      )
          except Exception as e:
              raise RuntimeError(
                  "[Convertion error] {}.\n Please open an issue at "
                  "https://github.com/PaddlePaddle/X2Paddle/issues to report your problem.".format(
                      e
                  )
              )
  
          origin_dir = os.getcwd()
          os.chdir(os.path.dirname(target_path))
          archive(os.path.basename(target_path))
          os.chdir(origin_dir)
          with open(
              os.path.join(
                  X2PADDLE_CACHE_PATH,
                  "onnx2paddle",
                  "{}.tar".format(identity),
              ),
              "rb",
          ) as f:
              # upload archived transformed model to vdl bos
              data = f.read()
              filename = "bos://{}/onnx2paddle/{}.tar".format(
                  self.bucket_name, identity
              )
              try:
                  self.bos_client.write(filename, data, append=False)
              except Exception as e:
                  print(
                      "Exception: Write file {}.tar to bos failed, due to {}".format(
                          identity, e
                      )
                  )
      with open(
          os.path.join(target_path, "inference_model", "model.pdmodel"),
          "rb",
      ) as model_fp:
          # upload pdmodel file to bos, if some model has been transformed before, we can directly download from bos
          filename = "bos://{}/onnx2paddle/{}/model.pdmodel".format(
              self.bucket_name, identity
          )
          data = model_fp.read()
          try:
              self.bos_client.write(filename, data)
          except Exception as e:
              print(
                  "Exception: Write file {}/model.pdmodel to bos failed, due to {}".format(
                      identity, e
                  )
              )
          # return transformed pdmodel file to frontend to show model structure graph
          model_encoded = base64.b64encode(data).decode("utf-8")
      # delete target_path
      shutil.rmtree(target_path)
      result["model"] = model_encoded
      print(len(model_encoded))
      return result
  
imports: import base64
  import hashlib
  import json
  import os
  import shutil
  import tempfile
  import paddle
  import paddle2onnx
  from flask import request
  from x2paddle.convert import onnx2paddle
  from .xarfile import archive
  from visualdl.io.bfile import BosFileSystem
  from visualdl.server.api import gen_result
  from visualdl.server.api import result
  from visualdl.utils.dir import X2PADDLE_CACHE_PATH
label_desc: Use image node_id 2 for calling the ModelConvertApi obj's underlying member method code with example usage: obj.onnx2paddle_model_convert(convert_to_lite, lite_valid_places, lite_model_type) and returns: result