コード例 #1
0
ファイル: grpc_client.py プロジェクト: zouxiaoshi/QDServing
 def process_response(call_future):
     try:
         list_result = str_2_list_by_json(call_future.result().data)
         results.extend(list_result)
         tags.append(1)
         logging.info("--------------end_call_grpc-------------")
     except:
         logging.error("--------------fail_call_grpc-------------")
コード例 #2
0
ファイル: grpc_run.py プロジェクト: zouxiaoshi/QDServing
    def SendData(self, request, context):
        logging.info("start_get_data, url: {}".format( request.name) )
        start = time.time()
        code, audios_data = inference(request.name)
        end = time.time()

        if code == 0:
            logging.info("success_get_data, time: {}s, data_size: {}, url: {}".format( (end - start), len(audios_data), request.name) )
        else:
            logging.error("fail_get_data, time: {}s, data_size: {}, url: {}".format( (end - start), len(audios_data), request.name) )

        return call_ant_pb2.AntReply(code=code, data=audios_data)
コード例 #3
0
ファイル: grpc_run.py プロジェクト: zouxiaoshi/QDServing
def serve(port):
    host = "[::1]:"
    host += str(port)
    logging.info(host)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
    call_ant_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    server.add_insecure_port(host)
    server.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
コード例 #4
0
ファイル: grpc_server.py プロジェクト: mukangt/FRServing
def serve(port):
    host = '[::]:' + str(port)
    logging.info(host)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    add_PiServiceServicer_to_server(Pi(), server)

    server.add_insecure_port(host)
    server.start()
    try:
        while True:
            time.sleep(60 * 60 * 24)
    except KeyboardInterrupt:
        server.stop(0)
コード例 #5
0
    def post(self):

        if not request.json or 'content' not in request.json :
            res = { "code": "400", "data": [], "message": "request is not json or content not in json" }
            return jsonify ( res )

        else:
            logging.info( "[TTSInference] [post] request.json:{}".format( request.json ) )
            text = request.json["content"]
            logging.info( "[TTSInference] [post] text:{}".format( text ) )
            grpc_host = hash_ring.get_node( str(time.time()) )
            data = get_res_by_grpc( grpc_host,text)
            res = { "code": "200", "data": data, "message": "" }
            return jsonify ( res ) 
コード例 #6
0
    def SendData(self, request, context):
        # logging.info("start_get_data, url: {}".format(request.name) )
        start = time.time()
        code, data = infer(request.image)
        end = time.time()

        if code == 200:
            logging.info(
                "success_get_data, time: {}s, size: {}, url: {}".format(
                    (end - start), len(data), 'test'))
        else:
            logging.error("fail_get_data, time: {}s, size: {}, url: {}".format(
                (end - start), len(data), 'test'))

        return PiReply(code=code, data=data)
コード例 #7
0
 def text_to_pinyin_sequence(self, text):
     # pinyin = self.processor.pinyin_parser(text, style=Style.TONE3, errors="ignore")
     pinyin, text = self.tts_py.get_pyin(text)
     new_pinyin = []
     for x in str(pinyin).split(" "):
         if "#" not in x:
             new_pinyin.append(x)
     phonemes = self.processor.get_phoneme_from_char_and_pinyin(
         text, new_pinyin)
     text = " ".join(phonemes)
     print("phoneme seq: {}".format(text))
     logging.info(
         "[TTSModel] [text_to_pinyin_sequence] phoneme seq:{}".format(text))
     input_ids = self.processor.text_to_sequence(text, inference=False)
     return input_ids
コード例 #8
0
ファイル: grpc_client.py プロジェクト: zouxiaoshi/QDServing
def get_res_by_grpc(grpc_host, text):

    logging.info("start_call_grpc, grpc_host: {}, url: {}".format( grpc_host, text ) )

    start = time.time()
    channel = grpc.insecure_channel(grpc_host)
    stub = call_ant_pb2_grpc.GreeterStub(channel)
    response = stub.SendData(call_ant_pb2.AntRequest(name=text))
    end = time.time()

    if response.code == 200:
        logging.info("success_data_by_grpc, time: {}s, size: {}, url: {}".format( (end-start), len(response.data), text) )
    else:
        logging.error("fail_call_grpc, time: {}s, data_size: {}, url: {}".format( (end-start), len(response.data), text) )

    return response.data
コード例 #9
0
ファイル: grpc_client.py プロジェクト: zouxiaoshi/QDServing
def get_sort_by_grpc(grpc_host, resp_data, list_url):

    logging.info("start_call_grpc, grpc_host: {}, url: {}".format( grpc_host, list_url ) )
    start = time.time()
    channel = grpc.insecure_channel(grpc_host)
    stub = call_ant_pb2_grpc.GreeterStub(channel)
    response = stub.SendData(call_ant_pb2.AntRequest(name=resp_data))
    end = time.time()
    list_result = str_2_list_by_json(response.data)

    if response.code == 200:
        logging.info("success_call_grpc, time: {}s, data_size: {}, url: {}".format( (end-start), len(response.data), list_url) )
    else:
        logging.error("fail_call_grpc, time: {}s, data_size: {}, url: {}".format( (end-start), len(response.data), list_url) )

    return list_result
コード例 #10
0
    def predict(self, input_text):
        input_text = self.tts_pause.add_pause(input_text)
        print("input_text>>>>", input_text)
        logging.info(
            "[TTSModel] [do_synthesis] input_text:{}".format(input_text))
        input_ids = self.processor.text_to_sequence(input_text, inference=True)

        _, mel_outputs, stop_token_prediction, alignment_history = self.tacotron2.inference(
            tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
            tf.convert_to_tensor([len(input_ids)], tf.int32),
            tf.convert_to_tensor([0], dtype=tf.int32))

        remove_end = 1024
        audio = self.mb_melgan.inference(mel_outputs)[0, :-remove_end, 0]

        return mel_outputs.numpy(), alignment_history.numpy(), audio.numpy()
コード例 #11
0
ファイル: grpc_client.py プロジェクト: mukangt/FRServing
def get_res_by_grpc(grpc_host, img_64):
    logging.info("start_call_grpc, grpc_host: {}, url: {}".format(
        grpc_host, 'test'))

    start = time.time()
    channel = grpc.insecure_channel(grpc_host)
    stub = PiServiceStub(channel)
    response = stub.SendData(PiRequest(image=img_64))
    end = time.time()

    if response.code == 200:
        logging.info("success_call_grpc, time: {}s, size: {}, url: {}".format(
            (end - start), len(response.data), 'text'))
    else:
        logging.error("fail_call_grpc, time: {}s, size: {}, url: {}".format(
            (end - start), len(response.data), 'text'))

    return response.code, response.data
コード例 #12
0
ファイル: grpc_client.py プロジェクト: zouxiaoshi/QDServing
def get_sort_by_grpc_async(grpc_host, resp_data, list_url, results = [], tags=[]):

    def process_response(call_future):
        try:
            list_result = str_2_list_by_json(call_future.result().data)
            results.extend(list_result)
            tags.append(1)
            logging.info("--------------end_call_grpc-------------")
        except:
            logging.error("--------------fail_call_grpc-------------")

    ret = True
    try:
        logging.info("start_call_grpc, grpc_host: {}s, url: {}".format( grpc_host, list_url) )
        channel = grpc.insecure_channel(grpc_host)
        stub = call_ant_pb2_grpc.GreeterStub(channel)
        call_future = stub.SendData.future(call_ant_pb2.AntRequest(name=resp_data))
        call_future.add_done_callback(process_response)
    except:
        tags.append(1)
        logging.error("-----fail_get_sort_by_grpc, host: {}".format( grpc_host ) )
        ret = False

    return ret
コード例 #13
0
ファイル: grpc_run.py プロジェクト: zouxiaoshi/QDServing
        end = time.time()

        if code == 0:
            logging.info("success_get_data, time: {}s, data_size: {}, url: {}".format( (end - start), len(audios_data), request.name) )
        else:
            logging.error("fail_get_data, time: {}s, data_size: {}, url: {}".format( (end - start), len(audios_data), request.name) )

        return call_ant_pb2.AntReply(code=code, data=audios_data)

def serve(port):
    host = "[::1]:"
    host += str(port)
    logging.info(host)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
    call_ant_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    server.add_insecure_port(host)
    server.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)


HTTP_PORT = 9959
if len(sys.argv) > 1:
    HTTP_PORT = sys.argv[1]

if __name__ == '__main__':
    logging.info("-------grpc service start--------")
    serve(HTTP_PORT)