code: def createRestfulGatewayApp(
      deployment_name, task, lb_port, server_thread
  ):
      # client must be thread-safe
      client = mii.MIIClient(task, "localhost", lb_port)
  
      class RestfulGatewayService(Resource):
          def __init__(self):
              super().__init__()
  
          def post(self):
              data = request.get_json()
              kwargs = data["kwargs"] if "kwargs" in data else {}
              result = client.query(data["request"], **kwargs)
              return MessageToJson(result)
  
      app = Flask("RestfulGateway")
  
      @app.route("/terminate", methods=["GET"])
      def terminate():
          # Need to shutdown *after* completing the request
          threading.Thread(
              target=shutdown, args=(server_thread,)
          ).start()
          return "Shutting down RESTful API gateway server"
  
      api = Api(app)
      path = "/{}/{}".format(RESTFUL_API_PATH, deployment_name)
      api.add_resource(RestfulGatewayService, path)
  
      return app
  
file_path: deepspeed-mii/mii/legacy/grpc_related/restful_gateway.py
imports: import time
  import threading
  import mii.legacy
  from flask import Flask, request
  from flask_restful import Resource, Api
  from werkzeug.serving import make_server
  from mii.legacy.constants import RESTFUL_GATEWAY_SHUTDOWN_TIMEOUT, RESTFUL_API_PATH
  from google.protobuf.json_format import MessageToJson
label_desc: Use image node_id 2 for calling a global function with example usage: createRestfulGatewayApp(deployment_name, task, lb_port, server_thread) and returns: app, str, MessageToJson