def build_service(pipelines: Union[Tuple['RuntimPipeline', str], List[Tuple['RuntimPipeline', str]]],
                  desc: str = 'Welcome to use towhee pipeline service'):
    """
    Convert multiple pipelines into an APIService

    Examples:

    .. code-block:: python

        from towhee import AutoPipes
        from towhee import api_service

        stn = AutoPipes.pipeline('sentence_embedding')
        img = AutoPipes.pipeline('image-embedding')
        service = api_service.build_service([(stn, '/embedding/text'), (img, '/embedding/image')])

        if __name__ == '__main__':
            from towhee.serve.http.server import HTTPServer
            HTTPServer(service).run('0.0.0.0', 8000)
    """

    service = APIService(desc=desc)

    def pipe_caller(p: Callable, params: Any):
        ret = p(params)
        if hasattr(ret, 'to_list'):
            ret = ret.to_list()
        return ret

    def batch(p: Callable, params: List[Any]):
        ret_data = []
        rets = p.batch(params)
        for ret in rets:
            if hasattr(ret, 'to_list'):
                ret_data.append(ret.to_list())
            else:
                ret_data.append(ret)
        return ret_data

    if not isinstance(pipelines, list):
        pipelines = [pipelines]

    for p in pipelines:
        caller = partial(pipe_caller, p[0])
        caller.__name__ = caller.func.__name__
        caller.__doc__ = caller.func.__doc__
        caller.__code__ = caller.func.__code__
        service.add_api(caller, path=p[1])
        if hasattr(p[0], 'batch'):
            batch_caller = partial(batch, p[0])
            batch_caller.__name__ = batch_caller.func.__name__
            batch_caller.__doc__ = batch_caller.func.__doc__
            batch_caller.__code__ = batch_caller.func.__code__
            service.add_api(batch_caller, path=p[1] + '/batch')

    return service
Convert multiple pipelines into an APIService

Examples:

.. code-block:: python

from towhee import AutoPipes
from towhee import api_service

stn = AutoPipes.pipeline('sentence_embedding')
img = AutoPipes.pipeline('image-embedding')
service = api_service.build_service([(stn, '/embedding/text'), (img, '/embedding/image')])

if __name__ == '__main__':
from towhee.serve.http.server import HTTPServer
HTTPServer(service).run('0.0.0.0', 8000)
towhee/serve/api_service.py