code: def create_app(init_flag: bool = False, configs: dict = None):
      """
      Start one flask instance and ready for HTTP requests.
  
      Args:
           init_flag(bool): Whether the instance need to be initialized with
                            `configs` or not
           configs(dict): Module configs for initializing.
  
      Returns:
          One flask instance.
  
      Examples:
          .. code-block:: python
  
              create_app(init_flag=False, configs=None)
      """
      if init_flag is False:
          if configs is None:
              raise RuntimeError("Lack of necessary configs.")
          config_with_file(configs)
  
      app_instance = Flask(__name__)
      app_instance.config["JSON_AS_ASCII"] = False
      app_instance.logger = log.get_file_logger(filename)
  
      @app_instance.route("/", methods=["GET", "POST"])
      def index():
          """
          Provide index page.
          """
          return (
              "暂不提供可视化界面，请直接使用脚本进行请求。<br/>No visual "
              "interface is provided for the time being, please use the"
              " python script to make a request directly."
          )
  
      @app_instance.before_request
      def before_request():
          """
          Add id info to `request.data` before request.
          """
          request.data = {
              "id": utils.md5(request.remote_addr + str(time.time()))
          }
  
      @app_instance.route("/predict/<module_name>", methods=["POST"])
      def predict_serving_v2(module_name: str):
          """
          Http api for predicting.
  
          Args:
              module_name(str): Module name for predicting.
  
          Returns:
              Result of predicting after packaging.
          """
          if module_name in v2_module_info.modules:
              module_info = v2_module_info.get_module_info(module_name)
          else:
              msg = "Module {} is not available.".format(module_name)
              return package_result("111", msg, "")
          inputs = request.json
          if inputs is None:
              results = (
                  "This usage is out of date, please use 'application/json' as content-type to post to /predict/%s. See 'https://github.com/PaddlePaddle/PaddleHub/blob/release/v1.6/docs/tutorial/serving.md' for more details."
                  % (module_name)
              )
              return package_result("112", results, "")
  
          results = predict_v2(module_info, inputs)
          return results
  
      @app_instance.route(
          "/gradio/<module_name>", methods=["GET", "POST"]
      )
      def gradio_app(module_name: str):
          if module_name in v2_module_info.modules:
              module_info = v2_module_info.get_module_info(module_name)
              module_info["module_name"] = module_name
          else:
              msg = "Module {} is not supported for gradio app.".format(
                  module_name
              )
              return package_result("111", msg, "")
          create_gradio_app(module_info)
          return redirect(
              "/gradio/{}/app".format(module_name), code=302
          )
  
      @app_instance.route(
          "/gradio/<module_name>/<path:path>", methods=["GET", "POST"]
      )
      def request_gradio_app(module_name: str, path: str):
          """
          Gradio app server url interface. We route urls for gradio app to gradio server.
  
          Args:
              module_name(str): Module name for gradio app.
              path(str): All resource path from gradio server.
  
          Returns:
              Any thing from gradio server.
          """
          port = _gradio_apps[module_name]
          if path == "app":
              proxy_url = request.url.replace(
                  request.host_url
                  + "gradio/{}/app".format(module_name),
                  "http://localhost:{}/".format(port),
              )
          else:
              proxy_url = request.url.replace(
                  request.host_url + "gradio/{}/".format(module_name),
                  "http://localhost:{}/".format(port),
              )
          resp = requests.request(
              method=request.method,
              url=proxy_url,
              headers={
                  key: value
                  for (key, value) in request.headers
                  if key != "Host"
              },
              data=request.get_data(),
              cookies=request.cookies,
              allow_redirects=False,
          )
          headers = [
              (name, value)
              for (name, value) in resp.raw.headers.items()
          ]
          response = Response(resp.content, resp.status_code, headers)
          return response
  
      return app_instance
  
imports: import socket
  import threading
  import time
  import traceback
  from multiprocessing import Process
  from threading import Lock
  import requests
  from flask import Flask
  from flask import redirect
  from flask import request
  from flask import Response
  from paddlehub.serving.model_service.base_model_service import cv_module_info
  from paddlehub.serving.model_service.base_model_service import nlp_module_info
  from paddlehub.serving.model_service.base_model_service import v2_module_info
  from paddlehub.utils import log
  from paddlehub.utils import utils
label_desc: Use image node_id 4 for calling a global function with example usage: create_app(init_flag, configs) and returns: app_instance, str, results, redirect, response, package_result, package_result, package_result