From 23f2e371fd69b1dfe3685944cf640d71ca5cbd54 Mon Sep 17 00:00:00 2001 From: Ywa Date: Mon, 18 Nov 2019 22:58:14 +0100 Subject: [PATCH 01/10] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index de52d6a..0fc552b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store *.wav !bird1.wav +.vscode \ No newline at end of file From 0f86c89ea382e21f9134aed316d220ba416fe561 Mon Sep 17 00:00:00 2001 From: Ywa Date: Mon, 18 Nov 2019 23:14:55 +0100 Subject: [PATCH 02/10] add hello world GRPC --- Makefile | 11 ++++ Pipfile | 2 + greeter_client.py | 37 +++++++++++ helloworld_pb2.py | 134 ++++++++++++++++++++++++++++++++++++++++ helloworld_pb2_grpc.py | 46 ++++++++++++++ protos/helloworld.proto | 38 ++++++++++++ 6 files changed, 268 insertions(+) create mode 100644 Makefile create mode 100644 greeter_client.py create mode 100644 helloworld_pb2.py create mode 100644 helloworld_pb2_grpc.py create mode 100644 protos/helloworld.proto diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..60392a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +hello: + echo "plop" + +proto: + python -m grpc_tools.protoc -I protos --python_out=. --grpc_python_out=. protos/helloworld.proto + +server: + python greeter_server.py + +client: + python greeter_client.py diff --git a/Pipfile b/Pipfile index 12fa7b9..40fe378 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,8 @@ librosa = "*" keras = "*" matplotlib = "*" scipy = "*" +grpcio = "*" +grpcio-tools = "*" [requires] python_version = "3.7" diff --git a/greeter_client.py b/greeter_client.py new file mode 100644 index 0000000..ee2032a --- /dev/null +++ b/greeter_client.py @@ -0,0 +1,37 @@ +# Copyright 2015 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""The Python implementation of the GRPC helloworld.Greeter client.""" + +from __future__ import print_function +import logging + +import grpc + +import helloworld_pb2 +import helloworld_pb2_grpc + + +def run(): + # NOTE(gRPC Python Team): .close() is possible on a channel and should be + # used in circumstances in which the with statement does not fit the needs + # of the code. + with grpc.insecure_channel('localhost:50051') as channel: + stub = helloworld_pb2_grpc.GreeterStub(channel) + response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) + print("Greeter client received: " + response.message) + + +if __name__ == '__main__': + logging.basicConfig() + run() diff --git a/helloworld_pb2.py b/helloworld_pb2.py new file mode 100644 index 0000000..951abbb --- /dev/null +++ b/helloworld_pb2.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: helloworld.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='helloworld.proto', + package='helloworld', + syntax='proto3', + serialized_options=_b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW'), + serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2I\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x42\x36\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') +) + + + + +_HELLOREQUEST = _descriptor.Descriptor( + name='HelloRequest', + full_name='helloworld.HelloRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='helloworld.HelloRequest.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=32, + serialized_end=60, +) + + +_HELLOREPLY = _descriptor.Descriptor( + name='HelloReply', + full_name='helloworld.HelloReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='message', full_name='helloworld.HelloReply.message', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=62, + serialized_end=91, +) + +DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST +DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +HelloRequest = _reflection.GeneratedProtocolMessageType('HelloRequest', (_message.Message,), { + 'DESCRIPTOR' : _HELLOREQUEST, + '__module__' : 'helloworld_pb2' + # @@protoc_insertion_point(class_scope:helloworld.HelloRequest) + }) +_sym_db.RegisterMessage(HelloRequest) + +HelloReply = _reflection.GeneratedProtocolMessageType('HelloReply', (_message.Message,), { + 'DESCRIPTOR' : _HELLOREPLY, + '__module__' : 'helloworld_pb2' + # @@protoc_insertion_point(class_scope:helloworld.HelloReply) + }) +_sym_db.RegisterMessage(HelloReply) + + +DESCRIPTOR._options = None + +_GREETER = _descriptor.ServiceDescriptor( + name='Greeter', + full_name='helloworld.Greeter', + file=DESCRIPTOR, + index=0, + serialized_options=None, + serialized_start=93, + serialized_end=166, + methods=[ + _descriptor.MethodDescriptor( + name='SayHello', + full_name='helloworld.Greeter.SayHello', + index=0, + containing_service=None, + input_type=_HELLOREQUEST, + output_type=_HELLOREPLY, + serialized_options=None, + ), +]) +_sym_db.RegisterServiceDescriptor(_GREETER) + +DESCRIPTOR.services_by_name['Greeter'] = _GREETER + +# @@protoc_insertion_point(module_scope) diff --git a/helloworld_pb2_grpc.py b/helloworld_pb2_grpc.py new file mode 100644 index 0000000..18e07d1 --- /dev/null +++ b/helloworld_pb2_grpc.py @@ -0,0 +1,46 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + +import helloworld_pb2 as helloworld__pb2 + + +class GreeterStub(object): + """The greeting service definition. + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.SayHello = channel.unary_unary( + '/helloworld.Greeter/SayHello', + request_serializer=helloworld__pb2.HelloRequest.SerializeToString, + response_deserializer=helloworld__pb2.HelloReply.FromString, + ) + + +class GreeterServicer(object): + """The greeting service definition. + """ + + def SayHello(self, request, context): + """Sends a greeting + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_GreeterServicer_to_server(servicer, server): + rpc_method_handlers = { + 'SayHello': grpc.unary_unary_rpc_method_handler( + servicer.SayHello, + request_deserializer=helloworld__pb2.HelloRequest.FromString, + response_serializer=helloworld__pb2.HelloReply.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'helloworld.Greeter', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) diff --git a/protos/helloworld.proto b/protos/helloworld.proto new file mode 100644 index 0000000..be878ce --- /dev/null +++ b/protos/helloworld.proto @@ -0,0 +1,38 @@ +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} From c38fd0cebd06acd12c7a47017797d7be04384997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ys=C3=A9=20Wanono?= Date: Tue, 19 Nov 2019 11:11:58 +0100 Subject: [PATCH 03/10] add server --- greeter_server.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 greeter_server.py diff --git a/greeter_server.py b/greeter_server.py new file mode 100644 index 0000000..7bc3f2f --- /dev/null +++ b/greeter_server.py @@ -0,0 +1,41 @@ +# Copyright 2015 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""The Python implementation of the GRPC helloworld.Greeter server.""" + +from concurrent import futures +import logging + +import grpc + +import helloworld_pb2 +import helloworld_pb2_grpc + + +class Greeter(helloworld_pb2_grpc.GreeterServicer): + + def SayHello(self, request, context): + return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) + + +def serve(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) + server.add_insecure_port('[::]:50051') + server.start() + server.wait_for_termination() + + +if __name__ == '__main__': + logging.basicConfig() + serve() From dbc4719d2d9140be1356a3f640c837bc4e3b30de Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 11:54:16 +0100 Subject: [PATCH 04/10] backup new proto with getPrediction --- Pipfile | 1 + Pipfile.lock | 154 +++++++++++++++++++++++++++++++++------- greeter_server.py | 6 ++ helloworld_pb2.py | 140 +++++++++++++++++++++++++++++++++++- helloworld_pb2_grpc.py | 17 +++++ protos/helloworld.proto | 16 +++++ 6 files changed, 304 insertions(+), 30 deletions(-) diff --git a/Pipfile b/Pipfile index 40fe378..c4f8318 100644 --- a/Pipfile +++ b/Pipfile @@ -4,6 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] +pylama = "*" [packages] flask = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 25f2ff3..661260f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "43c4a013e8726163cd068c6151cd7e8b6d71d1373d4e79fb5d2f5d52fbd26aac" + "sha256": "80d63da0a5a93935103bc83feb62403115031d7a747ac280232a44463b84fe05" }, "pipfile-spec": 6, "requires": { @@ -175,6 +175,61 @@ "sha256:f6c706866d424ff285b85a02de7bbe5ed0ace227766b2c42cbe12f3d9ea5a8aa", "sha256:f8370ad332b36fbad117440faf0dd4b910e80b9c49db5648afd337abdde9a1b6" ], + "index": "pypi", + "version": "==1.25.0" + }, + "grpcio-tools": { + "hashes": [ + "sha256:007c075eb9611379fa8f520a1865b9afd850469495b0e4a46e1349b2dc1744ce", + "sha256:02ae9708bdd3f329b1abe1ee16b1d768b2dd7a036a8a57e342d08ee8ca054cec", + "sha256:2f10226bfea4f947de355008b14fb4711c85fc1121570833a96f0e2cd8de580f", + "sha256:314354c7321c84a6e176a99afe1945c933b8a38b4f837255c8decfef8d07f24e", + "sha256:406b530c283a2bb804a10ee97928290b0b60788cd114ddfce0faa681cccfe4b8", + "sha256:49e7682e505e6a1d35459dae1d8a616a08d5cfa6f05de00235aff2e15786af14", + "sha256:4a5c2b38078fc4b949e4e70f7e25cb80443d1ee9a648ce4223aa3c040a0d3b9b", + "sha256:4b40291d67a1fecb5170ed9ec32016e2ae07908a8fa143d2d37311b2bcbeb2c5", + "sha256:4b72b04cba6ecd1940d6eda07886f80fe71fb2e669f1095ebab58b1eb17a53fa", + "sha256:4cc95d5fddebb9348fafcc4c0147745882794ded7cfd5282b2aa158596c77a8a", + "sha256:4ce0261bd4426482a96467ed9ad8411417a6932c331a5bb35aa1907f618f34f6", + "sha256:5226371a2b569c62be0d0590ccff7bbb9566762f243933efbd4b695f9f108cd5", + "sha256:52aab4cbab10683f8830420c0b55ccdc6344702b4a0940913d71fe928dd731c9", + "sha256:532a19419535a92a1b621222f70d6da7624151fe69afa4a1063be56e7a2b884a", + "sha256:5a8d44add097e0a3a7c27e66a8ed0aa2fd561cda77381e818cf7862d4ad0f629", + "sha256:64f6027887e32a938f00b2344c337c6d4f7c4cf157ec2e84b1dd6b6fddad8e50", + "sha256:651b0441e8d8f302b44fb50397fe73dcd5e61b790533438e690055abdef3b234", + "sha256:67d12ec4548dd2b1f15c9e3a953c8f48d8c3441c2d8bd143fc3af95a1c041c2b", + "sha256:6c029341132a0e64cbd2dba1dda9a125e06a798b9ec864569afdecce626dd5d5", + "sha256:6e64214709f37b347875ac83cfed4e9cfd287f255dab2836521f591620412c40", + "sha256:6f70fc9a82a0145296358720cf24f83a657a745e8b51ec9564f4c9e678c5b872", + "sha256:6fb4739eb5eef051945b16b3c434d08653ea05f0313cf88495ced5d9db641745", + "sha256:79b5b1c172dafb0e76aa95bf572d4c7afc0bf97a1669b2228a0bc151071c4666", + "sha256:7d02755480cec3c0222f35397e810bfaf4cf9f2bf2e626f7f6efc1d40fffb7fa", + "sha256:818f2b8168760cf16e66fe85894a37afcff5378a64939549663a371216618498", + "sha256:834564c2fba02c31179af081bd80aada8dfdcca52c80e241353f6063b6154bd2", + "sha256:8b17347a90a14386641ffe57743bbb01a16a7149c95905364d3c8091ad377bd8", + "sha256:902e13dbaca9733e4668928967b301526197ecffacb8c7a0acc0c7045de8836f", + "sha256:988014c714ca654b3b7ca9f4dabfe487b00e023bfdd9eaf1bb0fed82bf8c4255", + "sha256:9a83d39e198cbed5d093f43790b92945ab74140357ec00e53ae13b421489ffb7", + "sha256:ac7649cff7354d2f04ebe2872f786a1d07547deded61f3d39036ebb569de91bc", + "sha256:b013d93bc6dc5c7bf3642bf30e673daee46f9a4984fbd9588a9cda1071278414", + "sha256:b02701d40f1ccf16bc8c46f56bdbf89e03110bd8fd570c854e72299ce2920c35", + "sha256:b0ef0da2eec959def8ba508b2a763c492f1fb989446a422d1456ac17dc1b19f4", + "sha256:bb8264ccf8ff904a1a396dc757ac1560b24f270b90e7dabb0ae3f637cb351bb3", + "sha256:bbfb58f5c0aa27b599141bb5eacaf8116b55ad89bc5a2c3afd5e965d840ad341", + "sha256:c1a482fdd8952a7f0098f78161a4deef8a500e54babef302548cd9f1e326d42c", + "sha256:c40efc662fa037898488e31756242af68a8ab5729f939bc8c9ba259bc32e7d6a", + "sha256:c5ad07adae3fe62761bc662c554c2734203f0f700616fc58138b852a7ef5e40e", + "sha256:c765512cb5cb4afaf652837b8cc69229dee14c8e92f15a6ea0f4dfd646902dd2", + "sha256:c871f5a89012ae44d9233305d74dfdd2059a78f0cb0303d38a4b6a562c6f9ba7", + "sha256:cc950fb17c1172d0c0129e8c6e787206e7ef8c24a8e39005f8cc297e9faa4f9a", + "sha256:d3619b43009a5c82cb7ef11847518236140d7ffdcc6600e1a151b8b49350693a", + "sha256:dc17a8a8b39cb37380d927d4669882af4ccc7d3ee298a15a3004f4b18ecd2ac3", + "sha256:eab3684ce9dec3a934a36ba79e8435210d07c50906425ab157eeb4b14503a925", + "sha256:f258b32dffd27ef1eb5f5f01ebb115dfad07677b0510b41f786c511a62ded033", + "sha256:f550c94728b67a7eeddc35b03c99552f2d7aac09c52935ad4b0552d0843fd03c", + "sha256:f7fc690a517c8f3765796ed005bb3273895a985a8593977291bad24568e018e3" + ], + "index": "pypi", "version": "==1.25.0" }, "gunicorn": { @@ -418,30 +473,30 @@ }, "numpy": { "hashes": [ - "sha256:0b0dd8f47fb177d00fa6ef2d58783c4f41ad3126b139c91dd2f7c4b3fdf5e9a5", - "sha256:25ffe71f96878e1da7e014467e19e7db90ae7d4e12affbc73101bcf61785214e", - "sha256:26efd7f7d755e6ca966a5c0ac5a930a87dbbaab1c51716ac26a38f42ecc9bc4b", - "sha256:28b1180c758abf34a5c3fea76fcee66a87def1656724c42bb14a6f9717a5bdf7", - "sha256:2e418f0a59473dac424f888dd57e85f77502a593b207809211c76e5396ae4f5c", - "sha256:30c84e3a62cfcb9e3066f25226e131451312a044f1fe2040e69ce792cb7de418", - "sha256:4650d94bb9c947151737ee022b934b7d9a845a7c76e476f3e460f09a0c8c6f39", - "sha256:4dd830a11e8724c9c9379feed1d1be43113f8bcce55f47ea7186d3946769ce26", - "sha256:4f2a2b279efde194877aff1f76cf61c68e840db242a5c7169f1ff0fd59a2b1e2", - "sha256:62d22566b3e3428dfc9ec972014c38ed9a4db4f8969c78f5414012ccd80a149e", - "sha256:669795516d62f38845c7033679c648903200980d68935baaa17ac5c7ae03ae0c", - "sha256:75fcd60d682db3e1f8fbe2b8b0c6761937ad56d01c1dc73edf4ef2748d5b6bc4", - "sha256:9395b0a41e8b7e9a284e3be7060db9d14ad80273841c952c83a5afc241d2bd98", - "sha256:9e37c35fc4e9410093b04a77d11a34c64bf658565e30df7cbe882056088a91c1", - "sha256:a0678793096205a4d784bd99f32803ba8100f639cf3b932dc63b21621390ea7e", - "sha256:b46554ad4dafb2927f88de5a1d207398c5385edbb5c84d30b3ef187c4a3894d8", - "sha256:c867eeccd934920a800f65c6068acdd6b87e80d45cd8c8beefff783b23cdc462", - "sha256:dd0667f5be56fb1b570154c2c0516a528e02d50da121bbbb2cbb0b6f87f59bc2", - "sha256:de2b1c20494bdf47f0160bd88ed05f5e48ae5dc336b8de7cfade71abcc95c0b9", - "sha256:f1df7b2b7740dd777571c732f98adb5aad5450aee32772f1b39249c8a50386f6", - "sha256:ffca69e29079f7880c5392bf675eb8b4146479d976ae1924d01cd92b04cccbcc" + "sha256:0a7a1dd123aecc9f0076934288ceed7fd9a81ba3919f11a855a7887cbe82a02f", + "sha256:0c0763787133dfeec19904c22c7e358b231c87ba3206b211652f8cbe1241deb6", + "sha256:3d52298d0be333583739f1aec9026f3b09fdfe3ddf7c7028cb16d9d2af1cca7e", + "sha256:43bb4b70585f1c2d153e45323a886839f98af8bfa810f7014b20be714c37c447", + "sha256:475963c5b9e116c38ad7347e154e5651d05a2286d86455671f5b1eebba5feb76", + "sha256:64874913367f18eb3013b16123c9fed113962e75d809fca5b78ebfbb73ed93ba", + "sha256:683828e50c339fc9e68720396f2de14253992c495fdddef77a1e17de55f1decc", + "sha256:6ca4000c4a6f95a78c33c7dadbb9495c10880be9c89316aa536eac359ab820ae", + "sha256:75fd817b7061f6378e4659dd792c84c0b60533e867f83e0d1e52d5d8e53df88c", + "sha256:7d81d784bdbed30137aca242ab307f3e65c8d93f4c7b7d8f322110b2e90177f9", + "sha256:8d0af8d3664f142414fd5b15cabfd3b6cc3ef242a3c7a7493257025be5a6955f", + "sha256:9679831005fb16c6df3dd35d17aa31dc0d4d7573d84f0b44cc481490a65c7725", + "sha256:a8f67ebfae9f575d85fa859b54d3bdecaeece74e3274b0b5c5f804d7ca789fe1", + "sha256:acbf5c52db4adb366c064d0b7c7899e3e778d89db585feadd23b06b587d64761", + "sha256:ada4805ed51f5bcaa3a06d3dd94939351869c095e30a2b54264f5a5004b52170", + "sha256:c7354e8f0eca5c110b7e978034cd86ed98a7a5ffcf69ca97535445a595e07b8e", + "sha256:e2e9d8c87120ba2c591f60e32736b82b67f72c37ba88a4c23c81b5b8fa49c018", + "sha256:e467c57121fe1b78a8f68dd9255fbb3bb3f4f7547c6b9e109f31d14569f490c3", + "sha256:ede47b98de79565fcd7f2decb475e2dcc85ee4097743e551fe26cfc7eb3ff143", + "sha256:f58913e9227400f1395c7b800503ebfdb0772f1c33ff8cb4d6451c06cabdf316", + "sha256:fe39f5fd4103ec4ca3cb8600b19216cd1ff316b4990f4c0b6057ad982c0a34d5" ], "index": "pypi", - "version": "==1.17.3" + "version": "==1.17.4" }, "protobuf": { "hashes": [ @@ -472,10 +527,10 @@ }, "pyparsing": { "hashes": [ - "sha256:4acadc9a2b96c19fe00932a38ca63e601180c39a189a696abce1eaab641447e1", - "sha256:61b5ed888beab19ddccab3478910e2076a6b5a0295dffc43021890e136edf764" + "sha256:20f995ecd72f2a1f4bf6b072b63b22e2eb457836601e76d6e5dfcd75436acc1f", + "sha256:4ca62001be367f01bd3e92ecbb79070272a9d4964dce6a48a82ff0b8bc7e683a" ], - "version": "==2.4.4" + "version": "==2.4.5" }, "python-dateutil": { "hashes": [ @@ -553,6 +608,7 @@ "sha256:f018892621b787b9abf76d51d1f0c21611c71752ebb1891ccf7992e0bf973708", "sha256:f2d5db81d90d14a32d4aff920f52fca5639bcaaaf87b4f61bce83a1d238f49fc" ], + "index": "pypi", "version": "==1.3.2" }, "six": { @@ -634,5 +690,49 @@ "version": "==1.11.2" } }, - "develop": {} + "develop": { + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "pycodestyle": { + "hashes": [ + "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", + "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c" + ], + "version": "==2.5.0" + }, + "pydocstyle": { + "hashes": [ + "sha256:04c84e034ebb56eb6396c820442b8c4499ac5eb94a3bda88951ac3dc519b6058", + "sha256:66aff87ffe34b1e49bff2dd03a88ce6843be2f3346b0c9814410d34987fbab59" + ], + "version": "==4.0.1" + }, + "pyflakes": { + "hashes": [ + "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0", + "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2" + ], + "version": "==2.1.1" + }, + "pylama": { + "hashes": [ + "sha256:9bae53ef9c1a431371d6a8dca406816a60d547147b60a4934721898f553b7d8f", + "sha256:fd61c11872d6256b019ef1235be37b77c922ef37ac9797df6bd489996dddeb15" + ], + "index": "pypi", + "version": "==7.7.1" + }, + "snowballstemmer": { + "hashes": [ + "sha256:209f257d7533fdb3cb73bdbd24f436239ca3b2fa67d56f6ff88e86be08cc5ef0", + "sha256:df3bac3df4c2c01363f3dd2cfa78cce2840a79b9f1c2d2de9ce8d31683992f52" + ], + "version": "==2.0.0" + } + } } diff --git a/greeter_server.py b/greeter_server.py index 7bc3f2f..2a5bc24 100644 --- a/greeter_server.py +++ b/greeter_server.py @@ -27,6 +27,12 @@ class Greeter(helloworld_pb2_grpc.GreeterServicer): def SayHello(self, request, context): return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) + def GetPrediction(self, request, context): + audiofile = request.audiofile + print(audiofile) + prediction_list = ["pred1", "pred2"] + return helloworld_pb2.Prediction(prediction_list=prediction_list) + def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) diff --git a/helloworld_pb2.py b/helloworld_pb2.py index 951abbb..e4ee12a 100644 --- a/helloworld_pb2.py +++ b/helloworld_pb2.py @@ -20,7 +20,7 @@ package='helloworld', syntax='proto3', serialized_options=_b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW'), - serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2I\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x42\x36\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') + serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t\"V\n\tAudioFile\x12\x11\n\taudiofile\x18\x01 \x01(\x0c\x12\x36\n\x11\x61udio_file_config\x18\x02 \x01(\x0b\x32\x1b.helloworld.AudioFileConfig\"#\n\x0f\x41udioFileConfig\x12\x10\n\x08\x66ilename\x18\x01 \x01(\t\"%\n\nPrediction\x12\x17\n\x0fprediction_list\x18\x01 \x03(\t2\x89\x01\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x12>\n\rGetPrediction\x12\x15.helloworld.AudioFile\x1a\x16.helloworld.PredictionB6\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') ) @@ -87,8 +87,112 @@ serialized_end=91, ) + +_AUDIOFILE = _descriptor.Descriptor( + name='AudioFile', + full_name='helloworld.AudioFile', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='audiofile', full_name='helloworld.AudioFile.audiofile', index=0, + number=1, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='audio_file_config', full_name='helloworld.AudioFile.audio_file_config', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=93, + serialized_end=179, +) + + +_AUDIOFILECONFIG = _descriptor.Descriptor( + name='AudioFileConfig', + full_name='helloworld.AudioFileConfig', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='filename', full_name='helloworld.AudioFileConfig.filename', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=181, + serialized_end=216, +) + + +_PREDICTION = _descriptor.Descriptor( + name='Prediction', + full_name='helloworld.Prediction', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='prediction_list', full_name='helloworld.Prediction.prediction_list', index=0, + number=1, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=218, + serialized_end=255, +) + +_AUDIOFILE.fields_by_name['audio_file_config'].message_type = _AUDIOFILECONFIG DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY +DESCRIPTOR.message_types_by_name['AudioFile'] = _AUDIOFILE +DESCRIPTOR.message_types_by_name['AudioFileConfig'] = _AUDIOFILECONFIG +DESCRIPTOR.message_types_by_name['Prediction'] = _PREDICTION _sym_db.RegisterFileDescriptor(DESCRIPTOR) HelloRequest = _reflection.GeneratedProtocolMessageType('HelloRequest', (_message.Message,), { @@ -105,6 +209,27 @@ }) _sym_db.RegisterMessage(HelloReply) +AudioFile = _reflection.GeneratedProtocolMessageType('AudioFile', (_message.Message,), { + 'DESCRIPTOR' : _AUDIOFILE, + '__module__' : 'helloworld_pb2' + # @@protoc_insertion_point(class_scope:helloworld.AudioFile) + }) +_sym_db.RegisterMessage(AudioFile) + +AudioFileConfig = _reflection.GeneratedProtocolMessageType('AudioFileConfig', (_message.Message,), { + 'DESCRIPTOR' : _AUDIOFILECONFIG, + '__module__' : 'helloworld_pb2' + # @@protoc_insertion_point(class_scope:helloworld.AudioFileConfig) + }) +_sym_db.RegisterMessage(AudioFileConfig) + +Prediction = _reflection.GeneratedProtocolMessageType('Prediction', (_message.Message,), { + 'DESCRIPTOR' : _PREDICTION, + '__module__' : 'helloworld_pb2' + # @@protoc_insertion_point(class_scope:helloworld.Prediction) + }) +_sym_db.RegisterMessage(Prediction) + DESCRIPTOR._options = None @@ -114,8 +239,8 @@ file=DESCRIPTOR, index=0, serialized_options=None, - serialized_start=93, - serialized_end=166, + serialized_start=258, + serialized_end=395, methods=[ _descriptor.MethodDescriptor( name='SayHello', @@ -126,6 +251,15 @@ output_type=_HELLOREPLY, serialized_options=None, ), + _descriptor.MethodDescriptor( + name='GetPrediction', + full_name='helloworld.Greeter.GetPrediction', + index=1, + containing_service=None, + input_type=_AUDIOFILE, + output_type=_PREDICTION, + serialized_options=None, + ), ]) _sym_db.RegisterServiceDescriptor(_GREETER) diff --git a/helloworld_pb2_grpc.py b/helloworld_pb2_grpc.py index 18e07d1..bea4704 100644 --- a/helloworld_pb2_grpc.py +++ b/helloworld_pb2_grpc.py @@ -19,6 +19,11 @@ def __init__(self, channel): request_serializer=helloworld__pb2.HelloRequest.SerializeToString, response_deserializer=helloworld__pb2.HelloReply.FromString, ) + self.GetPrediction = channel.unary_unary( + '/helloworld.Greeter/GetPrediction', + request_serializer=helloworld__pb2.AudioFile.SerializeToString, + response_deserializer=helloworld__pb2.Prediction.FromString, + ) class GreeterServicer(object): @@ -32,6 +37,13 @@ def SayHello(self, request, context): context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') + def GetPrediction(self, request, context): + # missing associated documentation comment in .proto file + pass + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + def add_GreeterServicer_to_server(servicer, server): rpc_method_handlers = { @@ -40,6 +52,11 @@ def add_GreeterServicer_to_server(servicer, server): request_deserializer=helloworld__pb2.HelloRequest.FromString, response_serializer=helloworld__pb2.HelloReply.SerializeToString, ), + 'GetPrediction': grpc.unary_unary_rpc_method_handler( + servicer.GetPrediction, + request_deserializer=helloworld__pb2.AudioFile.FromString, + response_serializer=helloworld__pb2.Prediction.SerializeToString, + ), } generic_handler = grpc.method_handlers_generic_handler( 'helloworld.Greeter', rpc_method_handlers) diff --git a/protos/helloworld.proto b/protos/helloworld.proto index be878ce..016d7f7 100644 --- a/protos/helloworld.proto +++ b/protos/helloworld.proto @@ -25,6 +25,7 @@ package helloworld; service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} + rpc GetPrediction (AudioFile) returns (Prediction); } // The request message containing the user's name. @@ -36,3 +37,18 @@ message HelloRequest { message HelloReply { string message = 1; } + +//The request audiofile +message AudioFile { + bytes audiofile = 1; + AudioFileConfig audio_file_config = 2; +} + +message AudioFileConfig { + string filename = 1; +} + +// The prediction from audiofile +message Prediction { + repeated string prediction_list = 1; +} From cb3a59f9658e77949da5a8516e2ed222253d7b85 Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 12:27:39 +0100 Subject: [PATCH 05/10] first client --- greeter_client.py | 26 +++++++++++++++++- helloworld_pb2.py | 58 +++++++---------------------------------- protos/helloworld.proto | 6 +---- 3 files changed, 35 insertions(+), 55 deletions(-) diff --git a/greeter_client.py b/greeter_client.py index ee2032a..c60a5e3 100644 --- a/greeter_client.py +++ b/greeter_client.py @@ -11,16 +11,32 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# TODO: FIX ERROR +# grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with: +# status = StatusCode.RESOURCE_EXHAUSTED +# details = "Received message larger than max (4194305 vs. 4194304)" +# debug_error_string = "{"created":"@1574162543.663157000","description":"Error received from peer ipv6:[::1]:50051","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Received message larger than max (4194305 vs. 4194304)","grpc_status":8} """The Python implementation of the GRPC helloworld.Greeter client.""" from __future__ import print_function import logging import grpc +import os import helloworld_pb2 import helloworld_pb2_grpc +PATH_NAME = "/Users/ysewanono/Downloads/split_data" +AUDIO_FILE_NAME = "SWIFT_20190725_080011_2_4.wav" +AUDIO_PATH = os.path.join(PATH_NAME, AUDIO_FILE_NAME) + + +def get_audio_bytes(path=AUDIO_PATH): + with open(path, "rb") as fd: + contents = fd.read() + return contents + def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be @@ -29,7 +45,15 @@ def run(): with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) - print("Greeter client received: " + response.message) + print("Greeter client received: " + response.message) + + # Route Prediction + audio = get_audio_bytes()[:4194200] + print(len(audio)) + prediction = stub.GetPrediction(helloworld_pb2.AudioFile( + audiofile=audio, + filename=AUDIO_FILE_NAME)) + print(prediction) if __name__ == '__main__': diff --git a/helloworld_pb2.py b/helloworld_pb2.py index e4ee12a..daccd0d 100644 --- a/helloworld_pb2.py +++ b/helloworld_pb2.py @@ -20,7 +20,7 @@ package='helloworld', syntax='proto3', serialized_options=_b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW'), - serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t\"V\n\tAudioFile\x12\x11\n\taudiofile\x18\x01 \x01(\x0c\x12\x36\n\x11\x61udio_file_config\x18\x02 \x01(\x0b\x32\x1b.helloworld.AudioFileConfig\"#\n\x0f\x41udioFileConfig\x12\x10\n\x08\x66ilename\x18\x01 \x01(\t\"%\n\nPrediction\x12\x17\n\x0fprediction_list\x18\x01 \x03(\t2\x89\x01\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x12>\n\rGetPrediction\x12\x15.helloworld.AudioFile\x1a\x16.helloworld.PredictionB6\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') + serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t\"0\n\tAudioFile\x12\x11\n\taudiofile\x18\x01 \x01(\x0c\x12\x10\n\x08\x66ilename\x18\x02 \x01(\t\"%\n\nPrediction\x12\x17\n\x0fprediction_list\x18\x01 \x03(\t2\x89\x01\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x12>\n\rGetPrediction\x12\x15.helloworld.AudioFile\x1a\x16.helloworld.PredictionB6\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') ) @@ -103,39 +103,8 @@ is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='audio_file_config', full_name='helloworld.AudioFile.audio_file_config', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=93, - serialized_end=179, -) - - -_AUDIOFILECONFIG = _descriptor.Descriptor( - name='AudioFileConfig', - full_name='helloworld.AudioFileConfig', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='filename', full_name='helloworld.AudioFileConfig.filename', index=0, - number=1, type=9, cpp_type=9, label=1, + name='filename', full_name='helloworld.AudioFile.filename', index=1, + number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, @@ -152,8 +121,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=181, - serialized_end=216, + serialized_start=93, + serialized_end=141, ) @@ -183,15 +152,13 @@ extension_ranges=[], oneofs=[ ], - serialized_start=218, - serialized_end=255, + serialized_start=143, + serialized_end=180, ) -_AUDIOFILE.fields_by_name['audio_file_config'].message_type = _AUDIOFILECONFIG DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY DESCRIPTOR.message_types_by_name['AudioFile'] = _AUDIOFILE -DESCRIPTOR.message_types_by_name['AudioFileConfig'] = _AUDIOFILECONFIG DESCRIPTOR.message_types_by_name['Prediction'] = _PREDICTION _sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -216,13 +183,6 @@ }) _sym_db.RegisterMessage(AudioFile) -AudioFileConfig = _reflection.GeneratedProtocolMessageType('AudioFileConfig', (_message.Message,), { - 'DESCRIPTOR' : _AUDIOFILECONFIG, - '__module__' : 'helloworld_pb2' - # @@protoc_insertion_point(class_scope:helloworld.AudioFileConfig) - }) -_sym_db.RegisterMessage(AudioFileConfig) - Prediction = _reflection.GeneratedProtocolMessageType('Prediction', (_message.Message,), { 'DESCRIPTOR' : _PREDICTION, '__module__' : 'helloworld_pb2' @@ -239,8 +199,8 @@ file=DESCRIPTOR, index=0, serialized_options=None, - serialized_start=258, - serialized_end=395, + serialized_start=183, + serialized_end=320, methods=[ _descriptor.MethodDescriptor( name='SayHello', diff --git a/protos/helloworld.proto b/protos/helloworld.proto index 016d7f7..7643e05 100644 --- a/protos/helloworld.proto +++ b/protos/helloworld.proto @@ -41,11 +41,7 @@ message HelloReply { //The request audiofile message AudioFile { bytes audiofile = 1; - AudioFileConfig audio_file_config = 2; -} - -message AudioFileConfig { - string filename = 1; + string filename = 2; } // The prediction from audiofile From c2da9183428a43295db2dcd9bf6b917c84ee5f6f Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 17:55:40 +0100 Subject: [PATCH 06/10] fix message limit size --- Pipfile | 1 + Pipfile.lock | 118 +++++++++++++++++++++++++++++++++++++++++++++- greeter_client.py | 7 ++- greeter_server.py | 27 ++++++++++- 4 files changed, 148 insertions(+), 5 deletions(-) diff --git a/Pipfile b/Pipfile index c4f8318..882d3fc 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,7 @@ verify_ssl = true [dev-packages] pylama = "*" +ipdb = "*" [packages] flask = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 661260f..0a9f29c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "80d63da0a5a93935103bc83feb62403115031d7a747ac280232a44463b84fe05" + "sha256": "987b23bf83015f1115ae42969a2da75d80bb76d75aec98bd5487ac50bef77857" }, "pipfile-spec": 6, "requires": { @@ -691,6 +691,57 @@ } }, "develop": { + "appnope": { + "hashes": [ + "sha256:5b26757dc6f79a3b7dc9fab95359328d5747fcb2409d331ea66d0272b90ab2a0", + "sha256:8b995ffe925347a2138d7ac0fe77155e4311a0ea6d6da4f5128fe4b3cbe5ed71" + ], + "markers": "sys_platform == 'darwin'", + "version": "==0.1.0" + }, + "backcall": { + "hashes": [ + "sha256:38ecd85be2c1e78f77fd91700c76e14667dc21e2713b63876c0eb901196e01e4", + "sha256:bbbf4b1e5cd2bdb08f915895b51081c041bac22394fdfcfdfbe9f14b77c08bf2" + ], + "version": "==0.1.0" + }, + "decorator": { + "hashes": [ + "sha256:54c38050039232e1db4ad7375cfce6748d7b41c29e95a081c8a6d2c30364a2ce", + "sha256:5d19b92a3c8f7f101c8dd86afd86b0f061a8ce4540ab8cd401fa2542756bce6d" + ], + "version": "==4.4.1" + }, + "ipdb": { + "hashes": [ + "sha256:473fdd798a099765f093231a8b1fabfa95b0b682fce12de0c74b61a4b4d8ee57" + ], + "index": "pypi", + "version": "==0.12.2" + }, + "ipython": { + "hashes": [ + "sha256:dfd303b270b7b5232b3d08bd30ec6fd685d8a58cabd54055e3d69d8f029f7280", + "sha256:ed7ebe1cba899c1c3ccad6f7f1c2d2369464cc77dba8eebc65e2043e19cda995" + ], + "markers": "python_version >= '3.4'", + "version": "==7.9.0" + }, + "ipython-genutils": { + "hashes": [ + "sha256:72dd37233799e619666c9f639a9da83c34013a73e8bbc79a7a6348d93c61fab8", + "sha256:eb2e116e75ecef9d4d228fdc66af54269afa26ab4463042e33785b887c628ba8" + ], + "version": "==0.2.0" + }, + "jedi": { + "hashes": [ + "sha256:786b6c3d80e2f06fd77162a07fed81b8baa22dde5d62896a790a331d6ac21a27", + "sha256:ba859c74fa3c966a22f2aeebe1b74ee27e2a462f56d3f5f7ca4a59af61bfe42e" + ], + "version": "==0.15.1" + }, "mccabe": { "hashes": [ "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", @@ -698,6 +749,43 @@ ], "version": "==0.6.1" }, + "parso": { + "hashes": [ + "sha256:63854233e1fadb5da97f2744b6b24346d2750b85965e7e399bec1620232797dc", + "sha256:666b0ee4a7a1220f65d367617f2cd3ffddff3e205f3f16a0284df30e774c2a9c" + ], + "version": "==0.5.1" + }, + "pexpect": { + "hashes": [ + "sha256:2094eefdfcf37a1fdbfb9aa090862c1a4878e5c7e0e7e7088bdb511c558e5cd1", + "sha256:9e2c1fd0e6ee3a49b28f95d4b33bc389c89b20af6a1255906e90ff1262ce62eb" + ], + "markers": "sys_platform != 'win32'", + "version": "==4.7.0" + }, + "pickleshare": { + "hashes": [ + "sha256:87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca", + "sha256:9649af414d74d4df115d5d718f82acb59c9d418196b7b4290ed47a12ce62df56" + ], + "version": "==0.7.5" + }, + "prompt-toolkit": { + "hashes": [ + "sha256:46642344ce457641f28fc9d1c9ca939b63dadf8df128b86f1b9860e59c73a5e4", + "sha256:e7f8af9e3d70f514373bf41aa51bc33af12a6db3f71461ea47fea985defb2c31", + "sha256:f15af68f66e664eaa559d4ac8a928111eebd5feda0c11738b5998045224829db" + ], + "version": "==2.0.10" + }, + "ptyprocess": { + "hashes": [ + "sha256:923f299cc5ad920c68f2bc0bc98b75b9f838b93b599941a6b63ddbc2476394c0", + "sha256:d7cc528d76e76342423ca640335bd3633420dc1366f258cb31d05e865ef5ca1f" + ], + "version": "==0.6.0" + }, "pycodestyle": { "hashes": [ "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", @@ -719,6 +807,13 @@ ], "version": "==2.1.1" }, + "pygments": { + "hashes": [ + "sha256:71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127", + "sha256:881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297" + ], + "version": "==2.4.2" + }, "pylama": { "hashes": [ "sha256:9bae53ef9c1a431371d6a8dca406816a60d547147b60a4934721898f553b7d8f", @@ -727,12 +822,33 @@ "index": "pypi", "version": "==7.7.1" }, + "six": { + "hashes": [ + "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", + "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66" + ], + "version": "==1.13.0" + }, "snowballstemmer": { "hashes": [ "sha256:209f257d7533fdb3cb73bdbd24f436239ca3b2fa67d56f6ff88e86be08cc5ef0", "sha256:df3bac3df4c2c01363f3dd2cfa78cce2840a79b9f1c2d2de9ce8d31683992f52" ], "version": "==2.0.0" + }, + "traitlets": { + "hashes": [ + "sha256:70b4c6a1d9019d7b4f6846832288f86998aa3b9207c6821f3578a6a6a467fe44", + "sha256:d023ee369ddd2763310e4c3eae1ff649689440d4ae59d7485eb4cfbbe3e359f7" + ], + "version": "==4.3.3" + }, + "wcwidth": { + "hashes": [ + "sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e", + "sha256:f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c" + ], + "version": "==0.1.7" } } } diff --git a/greeter_client.py b/greeter_client.py index c60a5e3..ad265c3 100644 --- a/greeter_client.py +++ b/greeter_client.py @@ -42,13 +42,16 @@ def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. - with grpc.insecure_channel('localhost:50051') as channel: + options = [ + ('grpc.max_send_message_length', 50 * 1024 * 1024), + ('grpc.max_receive_message_length', 50 * 1024 * 1024)] + with grpc.insecure_channel('localhost:50051', options=options) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) # Route Prediction - audio = get_audio_bytes()[:4194200] + audio = get_audio_bytes() print(len(audio)) prediction = stub.GetPrediction(helloworld_pb2.AudioFile( audiofile=audio, diff --git a/greeter_server.py b/greeter_server.py index 2a5bc24..7ebbea9 100644 --- a/greeter_server.py +++ b/greeter_server.py @@ -15,27 +15,50 @@ from concurrent import futures import logging +import os import grpc import helloworld_pb2 import helloworld_pb2_grpc +from microfaune_package.microfaune.detection import RNNDetector + + +def save_file_in_wave(response, file_name='myfile.wav'): + if os.path.exists(file_name): + os.remove(file_name) + with open(file_name, mode='bx') as f: + f.write(response) class Greeter(helloworld_pb2_grpc.GreeterServicer): + def __init__(self): + self.model = RNNDetector('models/model_weights-20190919_220113.h5') def SayHello(self, request, context): return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) def GetPrediction(self, request, context): audiofile = request.audiofile - print(audiofile) + save_file_in_wave(audiofile, file_name=request.filename) + if os.path.exists(request.filename): + print("FILE EXISTS") + + print(self.model) + # pred = self.model.predict_on_wav(request.filename) + # print(pred) prediction_list = ["pred1", "pred2"] return helloworld_pb2.Prediction(prediction_list=prediction_list) def serve(): - server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + options = [ + ('grpc.max_send_message_length', 50 * 1024 * 1024), + ('grpc.max_receive_message_length', 50 * 1024 * 1024) + ] + server = grpc.server( + futures.ThreadPoolExecutor(max_workers=10), + options=options) helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) server.add_insecure_port('[::]:50051') server.start() From 9479c277452386c051efb2998ea8520aac25bcf2 Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 18:02:11 +0100 Subject: [PATCH 07/10] grpc done --- greeter_client.py | 5 +---- greeter_server.py | 6 +++--- helloworld_pb2.py | 4 ++-- protos/helloworld.proto | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/greeter_client.py b/greeter_client.py index ad265c3..ba4e8e5 100644 --- a/greeter_client.py +++ b/greeter_client.py @@ -42,10 +42,7 @@ def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. - options = [ - ('grpc.max_send_message_length', 50 * 1024 * 1024), - ('grpc.max_receive_message_length', 50 * 1024 * 1024)] - with grpc.insecure_channel('localhost:50051', options=options) as channel: + with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) diff --git a/greeter_server.py b/greeter_server.py index 7ebbea9..5b3b485 100644 --- a/greeter_server.py +++ b/greeter_server.py @@ -45,9 +45,9 @@ def GetPrediction(self, request, context): print("FILE EXISTS") print(self.model) - # pred = self.model.predict_on_wav(request.filename) - # print(pred) - prediction_list = ["pred1", "pred2"] + pred = self.model.predict_on_wav(request.filename) + + prediction_list = pred[1].tolist() return helloworld_pb2.Prediction(prediction_list=prediction_list) diff --git a/helloworld_pb2.py b/helloworld_pb2.py index daccd0d..6f93960 100644 --- a/helloworld_pb2.py +++ b/helloworld_pb2.py @@ -20,7 +20,7 @@ package='helloworld', syntax='proto3', serialized_options=_b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW'), - serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t\"0\n\tAudioFile\x12\x11\n\taudiofile\x18\x01 \x01(\x0c\x12\x10\n\x08\x66ilename\x18\x02 \x01(\t\"%\n\nPrediction\x12\x17\n\x0fprediction_list\x18\x01 \x03(\t2\x89\x01\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x12>\n\rGetPrediction\x12\x15.helloworld.AudioFile\x1a\x16.helloworld.PredictionB6\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') + serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t\"0\n\tAudioFile\x12\x11\n\taudiofile\x18\x01 \x01(\x0c\x12\x10\n\x08\x66ilename\x18\x02 \x01(\t\"%\n\nPrediction\x12\x17\n\x0fprediction_list\x18\x01 \x03(\x02\x32\x89\x01\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x12>\n\rGetPrediction\x12\x15.helloworld.AudioFile\x1a\x16.helloworld.PredictionB6\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') ) @@ -135,7 +135,7 @@ fields=[ _descriptor.FieldDescriptor( name='prediction_list', full_name='helloworld.Prediction.prediction_list', index=0, - number=1, type=9, cpp_type=9, label=3, + number=1, type=2, cpp_type=6, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, diff --git a/protos/helloworld.proto b/protos/helloworld.proto index 7643e05..b99f91b 100644 --- a/protos/helloworld.proto +++ b/protos/helloworld.proto @@ -46,5 +46,5 @@ message AudioFile { // The prediction from audiofile message Prediction { - repeated string prediction_list = 1; + repeated float prediction_list = 1; } From 73bc62d69b312d032757e8c1466b8331b93ebafd Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 18:08:59 +0100 Subject: [PATCH 08/10] add README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..331c746 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# GRPC + +# 1) Run the server +`pipenv run make server` + +# 2) In another terminal, run the client +`pipenv run make client` + +# To update the gRPC code used by our application to use the new service definition. +`pipenv run make proto` + +# To adapt client for web (react) +See (Write JS Client Code Section)[https://grpc.io/docs/tutorials/basic/web/] + +### Fore more informations, see [GRPC offical documentations](https://grpc.io/) From 13782ab40d806360766108ecd997f87946de6250 Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 18:09:20 +0100 Subject: [PATCH 09/10] add README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 331c746..a7944c7 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,5 @@ # To adapt client for web (react) See (Write JS Client Code Section)[https://grpc.io/docs/tutorials/basic/web/] -### Fore more informations, see [GRPC offical documentations](https://grpc.io/) +### Fore more informations +See [GRPC offical documentations](https://grpc.io/) From 961074b6ec29dd9abc170c20438ab25d82c90536 Mon Sep 17 00:00:00 2001 From: ysewa Date: Tue, 19 Nov 2019 18:12:21 +0100 Subject: [PATCH 10/10] udpate client audio file --- README.md | 3 +++ greeter_client.py | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a7944c7..cc6e0b6 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ # 2) In another terminal, run the client `pipenv run make client` +Don't forget to add an audiofile in repository for example. +And update line 30 `AUDIO_FILE_NAME = "SWIFT_20190725_080011_2_4.wav"` in `greeter_client.py` + # To update the gRPC code used by our application to use the new service definition. `pipenv run make proto` diff --git a/greeter_client.py b/greeter_client.py index ba4e8e5..578e19e 100644 --- a/greeter_client.py +++ b/greeter_client.py @@ -27,9 +27,8 @@ import helloworld_pb2 import helloworld_pb2_grpc -PATH_NAME = "/Users/ysewanono/Downloads/split_data" AUDIO_FILE_NAME = "SWIFT_20190725_080011_2_4.wav" -AUDIO_PATH = os.path.join(PATH_NAME, AUDIO_FILE_NAME) +AUDIO_PATH = os.path.join(AUDIO_FILE_NAME) def get_audio_bytes(path=AUDIO_PATH):