Esempio n. 1
0
    def request(self,
                image,
                println=False,
                value=None,
                model_type=None,
                model_site=None,
                need_color=None):

        import grpc
        import grpc_pb2
        import grpc_pb2_grpc
        channel = grpc.insecure_channel(self._url)
        stub = grpc_pb2_grpc.PredictStub(channel)
        response = stub.predict(
            grpc_pb2.PredictRequest(image=image,
                                    split_char=',',
                                    model_type=model_type,
                                    model_site=model_site,
                                    need_color=need_color))
        if println and value:
            _true = str(response.result).lower() == str(value).lower()
            if _true:
                self.true_count += 1
            print("result: {}, label: {}, flag: {}".format(
                response.result, value, _true))
        return {
            "message": response.result,
            "code": response.code,
            "success": response.success
        }
def rpc_request(image, model_name="", model_type=""):
    channel = grpc.insecure_channel('127.0.0.1:50054')
    stub = grpc_pb2_grpc.PredictStub(channel)
    response = stub.predict(grpc_pb2.PredictRequest(
        image=image,
        split_char=',',
        model_name=model_name,
        model_type=model_type
    ))
    return {"message": response.result, "code": response.code, "success": response.success}
Esempio n. 3
0
 def remote_predict(img_bytes):
     if not System.test_image(img_bytes):
         return None
     channel = grpc.insecure_channel('{}:5449'.format(
         NetworkConfig.CAPTCHA_API))
     stub = grpc_pb2_grpc.PredictStub(channel)
     response = stub.predict(
         grpc_pb2.PredictRequest(image=base64.b64encode(img_bytes).decode(),
                                 split_char=',',
                                 model_type=None,
                                 model_site=None))
     return response.result
Esempio n. 4
0
 def request(self, image):
     import grpc
     import grpc_pb2
     import grpc_pb2_grpc
     channel = grpc.insecure_channel(self._url)
     stub = grpc_pb2_grpc.PredictStub(channel)
     print('G-RPC Request Start--')
     response = stub.predict(grpc_pb2.PredictRequest(captcha_img=image))
     print('G-RPC Request End--')
     return {
         "message": {
             "result": response.result
         },
         "code": response.code,
         "success": response.success
     }