code: def create_gradio_app(module_info: dict):
      """
      Create a gradio app and launch a server for users.
      Args:
          module_info(dict): Module info include module name, method name and
                              other info.
      Return:
          int: port number, if server has been successful.
  
      Exception:
          Raise a exception if server can not been launched.
      """
      module_name = module_info["module_name"]
      port = None
      with _lock:
          if module_name not in _gradio_apps:
              try:
                  serving_method = getattr(
                      module_info["module"], "create_gradio_app"
                  )
              except Exception:
                  raise RuntimeError(
                      "Module {} is not supported for gradio app.".format(
                          module_name
                      )
                  )
  
              def get_free_tcp_port():
                  tcp = socket.socket(
                      socket.AF_INET, socket.SOCK_STREAM
                  )
                  tcp.setsockopt(
                      socket.SOL_SOCKET, socket.SO_REUSEPORT, 1
                  )
                  tcp.bind(("localhost", 0))
                  addr, port = tcp.getsockname()
                  tcp.close()
                  return port
  
              port = get_free_tcp_port()
              app = serving_method()
              process = Process(
                  target=app.launch, kwargs={"server_port": port}
              )
              process.start()
  
              def check_alive():
                  nonlocal port
                  while True:
                      try:
                          requests.get(
                              "http://localhost:{}/".format(port)
                          )
                          break
                      except Exception:
                          time.sleep(1)
  
              check_alive()
              _gradio_apps[module_name] = port
      return port
  
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 2 for calling a global function with example usage: create_gradio_app(module_info) and returns: port, port