diff --git a/.circleci/config.yml b/.circleci/config.yml index 4f9ae88..14f8b2f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,7 @@ jobs: service-dir: "services/cntk-image-recon" mainnet-port: "7004" testnet-port: "7054" - run-command: "source '/cntk/activate-cntk';python3 run_image_recon_service.py --ssl" + run-command: "source '/cntk/activate-cntk';python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/cntk-image-recon/Dockerfile" docker-no-cache: true @@ -37,7 +37,7 @@ jobs: service-dir: "services/deepfakes-faceswap" mainnet-port: "7060" testnet-port: "7061-7062" - run-command: "python3 run_deepfakes_faceswap_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/deepfakes-faceswap/Dockerfile" docker-no-cache: true @@ -59,7 +59,7 @@ jobs: service-dir: "services/deoldify-colorizer" mainnet-port: "7084" testnet-port: "7085" - run-command: "python3 run_colorize_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/deoldify-colorizer/Dockerfile" docker-no-cache: true @@ -81,7 +81,7 @@ jobs: service-dir: "services/i3d-video-action-recognition" mainnet-port: "7005" testnet-port: "7055" - run-command: "python3 run_video_action_recon_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/i3d-video-action-recognition/Dockerfile" docker-no-cache: true @@ -103,7 +103,7 @@ jobs: service-dir: "services/places365-scene-recognition" mainnet-port: "7019" testnet-port: "7079" - run-command: "python3 run_scene_recognition_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/places365-scene-recognition/Dockerfile" docker-no-cache: true @@ -125,7 +125,7 @@ jobs: service-dir: "services/pneumonia-diagnosis" mainnet-port: "7072" testnet-port: "7062" - run-command: "python3 run_pneumonia_diagnosis_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/pneumonia-diagnosis/Dockerfile" docker-no-cache: true @@ -147,7 +147,7 @@ jobs: service-dir: "services/real-time-voice-cloning" mainnet-port: "7064" testnet-port: "7065" - run-command: "python3 run_voice_cloning_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/real-time-voice-cloning/Dockerfile" docker-no-cache: true @@ -169,7 +169,7 @@ jobs: service-dir: "services/s2vt-video-captioning" mainnet-port: "7006" testnet-port: "7056" - run-command: "python run_video_cap_service.py --ssl" + run-command: "python run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/s2vt-video-captioning/Dockerfile" docker-no-cache: true @@ -191,7 +191,7 @@ jobs: service-dir: "services/sound-spleeter" mainnet-port: "7066" testnet-port: "7067" - run-command: "python3 run_sound_spleeter_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/sound-spleeter/Dockerfile" docker-no-cache: true @@ -213,7 +213,7 @@ jobs: service-dir: "services/yolov3-object-detection" mainnet-port: "7007" testnet-port: "7057" - run-command: "python3 run_object_detection_service.py --ssl" + run-command: "python3 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/yolov3-object-detection/Dockerfile" docker-no-cache: true @@ -235,7 +235,7 @@ jobs: service-dir: "services/zeta36-chess-alpha-zero" mainnet-port: "7008" testnet-port: "7058" - run-command: "python3.6 run_alpha_zero_service.py --ssl" + run-command: "python3.6 run_service.py --ssl" docker-test-files: "Dockerfile, requirements.txt" docker-file-path: "services/zeta36-chess-alpha-zero/Dockerfile" docker-no-cache: true @@ -254,47 +254,47 @@ jobs: - ssh-deployment/test: ssh-host: ${SSH_HOST_CNTK_IMAGE_RECON} ssh-user: ${SSH_USER_CNTK_IMAGE_RECON} - test-command: "sleep 10;source '/cntk/activate-cntk';python3 test_image_recon_service.py auto" + test-command: "sleep 10;source '/cntk/activate-cntk';python3 test_service.py auto" docker-container: "CNTK_IMAGE_RECON" - ssh-deployment/test: ssh-host: ${SSH_HOST_DEOLDIFY_COLORIZER} ssh-user: ${SSH_USER_DEOLDIFY_COLORIZER} - test-command: "sleep 10;python3 test_colorize_service.py auto" + test-command: "sleep 10;python3 test_service.py auto" docker-container: "DEOLDIFY_COLORIZER" - ssh-deployment/test: ssh-host: ${SSH_HOST_I3D_VIDEO_ACTION_RECON} ssh-user: ${SSH_USER_I3D_VIDEO_ACTION_RECON} - test-command: "sleep 10;python3 test_video_action_recon_service.py auto" + test-command: "sleep 10;python3 test_service.py auto" docker-container: "I3D_VIDEO_ACTION_RECON" - ssh-deployment/test: ssh-host: ${SSH_HOST_PLACES365_SCENE_RECOGNITION} ssh-user: ${SSH_USER_PLACES365_SCENE_RECOGNITION} - test-command: "sleep 10;python3 test_scene_recognition_service.py auto" + test-command: "sleep 10;python3 test_service.py auto" docker-container: "PLACES365_SCENE_RECOGNITION" - ssh-deployment/test: ssh-host: ${SSH_HOST_VOICE_CLONING} ssh-user: ${SSH_USER_VOICE_CLONING} - test-command: "sleep 10;python3 test_voice_cloning_service.py auto" + test-command: "sleep 10;python3 test_service.py auto" docker-container: "VOICE_CLONING" - ssh-deployment/test: ssh-host: ${SSH_HOST_S2VT_VIDEO_CAPTIONING} ssh-user: ${SSH_USER_S2VT_VIDEO_CAPTIONING} - test-command: "sleep 10;python test_video_cap_service.py auto" + test-command: "sleep 10;python test_service.py auto" docker-container: "S2VT_VIDEO_CAPTIONING" - ssh-deployment/test: ssh-host: ${SSH_HOST_SOUND_SPLEETER} ssh-user: ${SSH_USER_SOUND_SPLEETER} - test-command: "sleep 10;python3 test_sound_spleeter_service.py auto" + test-command: "sleep 10;python3 test_service.py auto" docker-container: "SOUND_SPLEETER" - ssh-deployment/test: ssh-host: ${SSH_HOST_YOLOv3_OBJECT_DETECTION} ssh-user: ${SSH_USER_YOLOv3_OBJECT_DETECTION} - test-command: "sleep 10;python3 test_object_detection_service.py auto" + test-command: "sleep 10;python3 test_service.py auto" docker-container: "YOLOv3_OBJECT_DETECTION" - ssh-deployment/test: ssh-host: ${SSH_HOST_CHESS_ALPHA_ZERO} ssh-user: ${SSH_USER_CHESS_ALPHA_ZERO} - test-command: "sleep 10;python3.6 test_alpha_zero_service.py auto" + test-command: "sleep 10;python3.6 test_service.py auto" docker-container: "CHESS_ALPHA_ZERO" workflows: diff --git a/services/cntk-image-recon/Dockerfile b/services/cntk-image-recon/Dockerfile index e723dae..e2945f6 100644 --- a/services/cntk-image-recon/Dockerfile +++ b/services/cntk-image-recon/Dockerfile @@ -20,7 +20,7 @@ RUN apt-get update && \ curl # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/cntk-image-recon/README.md b/services/cntk-image-recon/README.md index 59fbdc5..ade253c 100644 --- a/services/cntk-image-recon/README.md +++ b/services/cntk-image-recon/README.md @@ -45,7 +45,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -66,7 +65,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7054", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "cntk-image-recon", @@ -91,7 +89,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_image_recon_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -104,7 +102,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_image_recon_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (flowers|dogs): flowers Model (ResNet152): @@ -112,7 +110,7 @@ Image (Link): https://www.fiftyflowers.com/site_files/FiftyFlowers/Image/Product 1.8751 {1: '98.93%: sunflower', 2: '00.64%: black-eyed susan', 3: '00.16%: barbeton daisy', 4: '00.14%: oxeye daisy', 5: '00.03%: daffodil'} -$ python3 test_image_recon_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (flowers|dogs): dogs Model (ResNet152): diff --git a/services/cntk-image-recon/requirements.txt b/services/cntk-image-recon/requirements.txt index bb59a39..688b788 100644 --- a/services/cntk-image-recon/requirements.txt +++ b/services/cntk-image-recon/requirements.txt @@ -1,5 +1,5 @@ grpcio>=1.14.2 grpcio-tools>=1.14.1 requests==2.20.0 -Pillow==6.2.0 -cntk==2.5 \ No newline at end of file +Pillow==6.2.2 +cntk-gpu==2.7 \ No newline at end of file diff --git a/services/cntk-image-recon/run_image_recon_service.py b/services/cntk-image-recon/run_service.py similarity index 100% rename from services/cntk-image-recon/run_image_recon_service.py rename to services/cntk-image-recon/run_service.py diff --git a/services/cntk-image-recon/service/image_recon.py b/services/cntk-image-recon/service/image_recon.py index 2bcf1c0..89ecb86 100755 --- a/services/cntk-image-recon/service/image_recon.py +++ b/services/cntk-image-recon/service/image_recon.py @@ -87,7 +87,7 @@ def image_recognition(method, model, map_names, img_path, image_dims): except Exception as e: log.error(e) traceback.print_exc() - return {"delta_time": "Fail", "top_5": "Fail"} + return {"delta_time": "Fail", "top_5": "Fail", "error": str(e)} def generate_uid(): diff --git a/services/cntk-image-recon/service/image_recon_service.py b/services/cntk-image-recon/service/image_recon_service.py index 0f9f8db..bc3947c 100644 --- a/services/cntk-image-recon/service/image_recon_service.py +++ b/services/cntk-image-recon/service/image_recon_service.py @@ -38,7 +38,7 @@ def __init__(self): # The method that will be exposed to the snet-cli call command. # request: incoming data # context: object that provides RPC-specific information (timeout, etc). - def flowers(self, request, _): + def flowers(self, request, context): manager = multiprocessing.Manager() return_dict = manager.dict() p = multiprocessing.Process(target=mp_image_recognition, args=("flowers", @@ -50,13 +50,17 @@ def flowers(self, request, _): p.join() response = return_dict.get("response", None) - if not response: - return Output(delta_time="Fail", top_5="Fail") + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) + return Output() log.debug("flowers({},{})=OK".format(self.model, self.img_path)) return Output(delta_time=response["delta_time"], top_5=str(response["top_5"])) - def dogs(self, request, _): + def dogs(self, request, context): manager = multiprocessing.Manager() return_dict = manager.dict() p = multiprocessing.Process(target=mp_image_recognition, args=("dogs", @@ -68,7 +72,11 @@ def dogs(self, request, _): p.join() response = return_dict.get("response", None) - if not response: + if not response or "error" in response: + error_msg = response.get("error", "None") if response else "None" + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) return Output(delta_time="Fail", top_5="Fail") log.debug("flowers({},{})=OK".format(self.model, self.img_path)) diff --git a/services/cntk-image-recon/snetd_configs/snetd.mainnet.json b/services/cntk-image-recon/snetd_configs/snetd.mainnet.json index 325c9fd..b7e675a 100644 --- a/services/cntk-image-recon/snetd_configs/snetd.mainnet.json +++ b/services/cntk-image-recon/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7004", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/cntk-image-recon/snetd_configs/snetd.ropsten b/services/cntk-image-recon/snetd_configs/snetd.ropsten index f25fefd..722abf3 100644 --- a/services/cntk-image-recon/snetd_configs/snetd.ropsten +++ b/services/cntk-image-recon/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7054", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/cntk-image-recon/test_image_recon_service.py b/services/cntk-image-recon/test_service.py similarity index 100% rename from services/cntk-image-recon/test_image_recon_service.py rename to services/cntk-image-recon/test_service.py diff --git a/services/deepfakes-faceswap/Dockerfile b/services/deepfakes-faceswap/Dockerfile index eb568ae..9f34ad1 100644 --- a/services/deepfakes-faceswap/Dockerfile +++ b/services/deepfakes-faceswap/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev RUN apt-get install -y python3 python3-pip ffmpeg # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/deepfakes-faceswap/README.md b/services/deepfakes-faceswap/README.md index fe4b6fc..1cd30cb 100644 --- a/services/deepfakes-faceswap/README.md +++ b/services/deepfakes-faceswap/README.md @@ -36,7 +36,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -57,7 +56,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7005", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "deepfakes-faceswap", @@ -82,7 +80,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_deepfakes_faceswap_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -96,7 +94,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_deepfakes_faceswap_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (faceswap): UID: @@ -108,7 +106,7 @@ uid: "http://52.38.111.172:7006/dashboard?uid=705493e1b8594380e247" ``` ``` -$ python3 test_deepfakes_faceswap_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (faceswap): UID: 705493e1b8594380e247 diff --git a/services/deepfakes-faceswap/run_deepfakes_faceswap_service.py b/services/deepfakes-faceswap/run_service.py similarity index 100% rename from services/deepfakes-faceswap/run_deepfakes_faceswap_service.py rename to services/deepfakes-faceswap/run_service.py diff --git a/services/deepfakes-faceswap/snetd_configs/snetd.mainnet.json b/services/deepfakes-faceswap/snetd_configs/snetd.mainnet.json index 4784d11..da0c038 100644 --- a/services/deepfakes-faceswap/snetd_configs/snetd.mainnet.json +++ b/services/deepfakes-faceswap/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7060", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/deepfakes-faceswap/snetd_configs/snetd.ropsten b/services/deepfakes-faceswap/snetd_configs/snetd.ropsten index cb536e0..cfeb01c 100644 --- a/services/deepfakes-faceswap/snetd_configs/snetd.ropsten +++ b/services/deepfakes-faceswap/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7061", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/deepfakes-faceswap/test_deepfakes_faceswap_service.py b/services/deepfakes-faceswap/test_service.py similarity index 100% rename from services/deepfakes-faceswap/test_deepfakes_faceswap_service.py rename to services/deepfakes-faceswap/test_service.py diff --git a/services/deoldify-colorizer/README.md b/services/deoldify-colorizer/README.md index d8410b3..43b2e2c 100644 --- a/services/deoldify-colorizer/README.md +++ b/services/deoldify-colorizer/README.md @@ -45,7 +45,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -66,7 +65,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7085", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "deoldify-colorizer", @@ -91,7 +89,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_colorize_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -103,7 +101,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_colorize_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (colorize): colorize Image (Link): https://snet-models.s3.amazonaws.com/bh/Colorize/jucelino.jpg diff --git a/services/deoldify-colorizer/run_colorize_service.py b/services/deoldify-colorizer/run_service.py similarity index 100% rename from services/deoldify-colorizer/run_colorize_service.py rename to services/deoldify-colorizer/run_service.py diff --git a/services/deoldify-colorizer/service/colorization.py b/services/deoldify-colorizer/service/colorization.py index 2e9b27f..ba37513 100644 --- a/services/deoldify-colorizer/service/colorization.py +++ b/services/deoldify-colorizer/service/colorization.py @@ -87,5 +87,5 @@ def colorize(self): except Exception as e: log.error(e) traceback.print_exc() - self.response["img_colorized"] = "Fail" + self.response = {"img_colorized": "Fail", "error": str(e)} return self.response diff --git a/services/deoldify-colorizer/service/colorization_service.py b/services/deoldify-colorizer/service/colorization_service.py index 61e980b..186039a 100644 --- a/services/deoldify-colorizer/service/colorization_service.py +++ b/services/deoldify-colorizer/service/colorization_service.py @@ -36,7 +36,8 @@ def __init__(self): # The method that will be exposed to the snet-cli call command. # request: incoming data # context: object that provides RPC-specific information (timeout, etc). - def colorize(self, request, _): + @staticmethod + def colorize(request, context): try: manager = Manager() return_dict = manager.dict() @@ -47,7 +48,11 @@ def colorize(self, request, _): p.join() response = return_dict.get("response", None) - if not response: + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) return Output() log.debug("colorize({})={}".format(request.img_input[:50], response["img_colorized"][:50])) diff --git a/services/deoldify-colorizer/snetd_configs/snetd.mainnet.json b/services/deoldify-colorizer/snetd_configs/snetd.mainnet.json index cf9c1c1..2f4b783 100644 --- a/services/deoldify-colorizer/snetd_configs/snetd.mainnet.json +++ b/services/deoldify-colorizer/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7084", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/deoldify-colorizer/snetd_configs/snetd.ropsten b/services/deoldify-colorizer/snetd_configs/snetd.ropsten index 06a1e46..87a8ba1 100644 --- a/services/deoldify-colorizer/snetd_configs/snetd.ropsten +++ b/services/deoldify-colorizer/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7085", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/deoldify-colorizer/test_colorize_service.py b/services/deoldify-colorizer/test_service.py similarity index 100% rename from services/deoldify-colorizer/test_colorize_service.py rename to services/deoldify-colorizer/test_service.py diff --git a/services/i3d-video-action-recognition/Dockerfile b/services/i3d-video-action-recognition/Dockerfile index 2e373fd..2a293cf 100644 --- a/services/i3d-video-action-recognition/Dockerfile +++ b/services/i3d-video-action-recognition/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev RUN apt-get install -y python3 python3-pip # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/i3d-video-action-recognition/README.md b/services/i3d-video-action-recognition/README.md index 9aa6f38..0512780 100644 --- a/services/i3d-video-action-recognition/README.md +++ b/services/i3d-video-action-recognition/README.md @@ -36,7 +36,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -57,7 +56,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7055", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "i3d-video-action-recognition", @@ -82,7 +80,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_video_action_recon_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -94,14 +92,14 @@ Inputs: Local (testing purpose): ``` -$ python3 test_call_video_action_recon_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (video_action_recon): Model: 400 Url: http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_MoppingFloor_g25_c01.avi {'Action': 'mopping floor\t56.66%\ncleaning floor\t31.83%\nsweeping floor\t11.39%\nsanding floor\t0.02%\nshoveling snow\t0.01%\n'} -$ python3 test_call_video_action_recon_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (video_action_recon): Model: 600 diff --git a/services/i3d-video-action-recognition/run_video_action_recon_service.py b/services/i3d-video-action-recognition/run_service.py similarity index 100% rename from services/i3d-video-action-recognition/run_video_action_recon_service.py rename to services/i3d-video-action-recognition/run_service.py diff --git a/services/i3d-video-action-recognition/service/video_action_recon.py b/services/i3d-video-action-recognition/service/video_action_recon.py index 11691a2..18298c8 100644 --- a/services/i3d-video-action-recognition/service/video_action_recon.py +++ b/services/i3d-video-action-recognition/service/video_action_recon.py @@ -158,11 +158,11 @@ def video_action_recon(self): log.debug("{}\t{:.2f}%".format(labels[i], ps[i] * 100)) self.response["Top5Actions"] += "[{:05.2f}%] {}\n".format(ps[i] * 100, labels[i]) else: - self.response["Top5Actions"] = self.error if self.error else "[Fail] Unexpected error!" + self.response["error"] = self.error if self.error else "[Fail] Unexpected error!" except Exception as e: log.error(e) - self.response["Top5Actions"] = "Fail" + self.response = {"Top5Actions": "Fail", "error": str(e)} # Deletes video folder. if os.path.exists(self.video_folder): diff --git a/services/i3d-video-action-recognition/service/video_action_recon_service.py b/services/i3d-video-action-recognition/service/video_action_recon_service.py index 959268b..447a9f8 100644 --- a/services/i3d-video-action-recognition/service/video_action_recon_service.py +++ b/services/i3d-video-action-recognition/service/video_action_recon_service.py @@ -37,7 +37,7 @@ def __init__(self): # The method that will be exposed to the snet-cli call command. # request: incoming data # context: object that provides RPC-specific information (timeout, etc). - def video_action_recon(self, request, _): + def video_action_recon(self, request, context): self.uid = generate_uid() self.model = request.model self.url = request.url @@ -53,8 +53,12 @@ def video_action_recon(self, request, _): p.join() response = return_dict.get("response", None) - if not response: - return Output(value="Fail") + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) + return Output() log.debug("video_action_recon({},{})=OK".format(self.model, self.url)) return Output(value=response["Top5Actions"]) diff --git a/services/i3d-video-action-recognition/snetd_configs/snetd.mainnet.json b/services/i3d-video-action-recognition/snetd_configs/snetd.mainnet.json index 3b48729..7d408f7 100644 --- a/services/i3d-video-action-recognition/snetd_configs/snetd.mainnet.json +++ b/services/i3d-video-action-recognition/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7005", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/i3d-video-action-recognition/snetd_configs/snetd.ropsten b/services/i3d-video-action-recognition/snetd_configs/snetd.ropsten index 1458027..edf34ad 100644 --- a/services/i3d-video-action-recognition/snetd_configs/snetd.ropsten +++ b/services/i3d-video-action-recognition/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7055", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/i3d-video-action-recognition/test_video_action_recon_service.py b/services/i3d-video-action-recognition/test_service.py similarity index 100% rename from services/i3d-video-action-recognition/test_video_action_recon_service.py rename to services/i3d-video-action-recognition/test_service.py diff --git a/services/places365-scene-recognition/Dockerfile b/services/places365-scene-recognition/Dockerfile index 74839af..77826d4 100755 --- a/services/places365-scene-recognition/Dockerfile +++ b/services/places365-scene-recognition/Dockerfile @@ -26,7 +26,7 @@ RUN apt-get update && \ pip install --upgrade pip # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/places365-scene-recognition/README.md b/services/places365-scene-recognition/README.md index 5b985e4..ec5b271 100644 --- a/services/places365-scene-recognition/README.md +++ b/services/places365-scene-recognition/README.md @@ -36,7 +36,6 @@ Create `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_NAME": "ORGANIZATION_NAME", "SERVICE_NAME": "SERVICE_NAME", @@ -65,7 +64,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "http://54.203.198.53:7019", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7018", "ORGANIZATION_NAME": "snet", "SERVICE_NAME": "places365-scene-recognition", @@ -87,7 +85,7 @@ $ sh buildproto.sh ``` Start the service and its respective instance of `SNET Daemon` at the ports specified above: ``` -$ python3 run_object_detection_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -105,7 +103,7 @@ $ python3 run_object_detection_service.py Run the test script provided. You can input the gRPC request fields manually or use the flag `auto` to automatically fill them in using default values. ``` -$ python3 test_scene_recognition_service.py auto +$ python3 test_service.py auto ... TEST RESULT: io: outdoor diff --git a/services/places365-scene-recognition/requirements.txt b/services/places365-scene-recognition/requirements.txt index 2fa0601..288682a 100644 --- a/services/places365-scene-recognition/requirements.txt +++ b/services/places365-scene-recognition/requirements.txt @@ -1,6 +1,6 @@ grpcio==1.14.2 grpcio-tools==1.14.1 opencv-python==3.4.4.19 -Pillow==6.2.0 +Pillow==6.2.2 scipy==1.1.0 numpy==1.15.1 \ No newline at end of file diff --git a/services/places365-scene-recognition/run_scene_recognition_service.py b/services/places365-scene-recognition/run_service.py similarity index 100% rename from services/places365-scene-recognition/run_scene_recognition_service.py rename to services/places365-scene-recognition/run_service.py diff --git a/services/places365-scene-recognition/service/scene_recognition.py b/services/places365-scene-recognition/service/scene_recognition.py index e9a1133..43c1abd 100644 --- a/services/places365-scene-recognition/service/scene_recognition.py +++ b/services/places365-scene-recognition/service/scene_recognition.py @@ -13,7 +13,6 @@ from PIL import Image import logging import service -from service.serviceUtils import jpg_to_base64 from service import wideresnet as wideresnet logging.basicConfig( @@ -149,57 +148,61 @@ def recognize(self, input_image_path, predict, cam_path): """ Performs scene recognition: predicts scene attributes, category, indoor/outdoor and class activation mappings. """ log.debug("Input image path : {}".format(input_image_path)) - result = {} - - # load the test image - img = Image.open(input_image_path) - input_img = V(self.tf(img).unsqueeze(0)) - - # forward pass - logit = self.model.forward(input_img) - h_x = F.softmax(logit, 1).data.squeeze() - probs, idx = h_x.sort(0, True) - probs = probs.numpy() - idx = idx.numpy() - - log.debug('RESULT ON ' + input_image_path) - - # Output the IO prediction - if "io" in predict: - io_image = np.mean(self.labels_io[idx[:10]]) # vote for the indoor or outdoor - if io_image < 0.5: - result["io"] = "indoor" - log.debug('--TYPE OF ENVIRONMENT: indoor') - else: - result["io"] = "outdoor" - log.debug('--TYPE OF ENVIRONMENT: outdoor') - - # Output the prediction of scene category - if "categories" in predict: - result["categories"] = "" - log.debug('--SCENE CATEGORIES:') - for i in range(0, 5): - category = ' {:.3f} -> {},'.format(probs[i], self.classes[idx[i]]) - result["categories"] += category - log.debug(category) - - # output the scene attributes - if "attributes" in predict: - responses_attribute = self.w_attribute.dot(self.features_blobs[1]) - idx_a = np.argsort(responses_attribute) - log.debug('--SCENE ATTRIBUTES:') - attributes = ', '.join([self.labels_attribute[idx_a[i]] for i in range(-1, -10, -1)]) - result["attributes"] = attributes - log.debug(attributes) - - # generate class activation mapping - if "cam" in predict: - cams = self.return_cam(self.features_blobs[0], self.weight_softmax, [idx[0]]) - img = cv2.imread(input_image_path) - height, width, _ = img.shape - heatmap = cv2.applyColorMap(cv2.resize(cams[0], (width, height)), cv2.COLORMAP_JET) - cam_result = heatmap * 0.4 + img * 0.5 - cv2.imwrite(cam_path, cam_result) - log.debug('Class activation mapping is saved at {}'.format(cam_path)) - result["cam"] = service.serviceUtils.jpg_to_base64(cam_path, open_file=True).decode("utf-8") - return result + result = dict() + try: + # load the test image + img = Image.open(input_image_path) + input_img = V(self.tf(img).unsqueeze(0)) + + # forward pass + logit = self.model.forward(input_img) + h_x = F.softmax(logit, 1).data.squeeze() + probs, idx = h_x.sort(0, True) + probs = probs.numpy() + idx = idx.numpy() + + log.debug('RESULT ON ' + input_image_path) + + # Output the IO prediction + if "io" in predict: + io_image = np.mean(self.labels_io[idx[:10]]) # vote for the indoor or outdoor + if io_image < 0.5: + result["io"] = "indoor" + log.debug('--TYPE OF ENVIRONMENT: indoor') + else: + result["io"] = "outdoor" + log.debug('--TYPE OF ENVIRONMENT: outdoor') + + # Output the prediction of scene category + if "categories" in predict: + result["categories"] = "" + log.debug('--SCENE CATEGORIES:') + for i in range(0, 5): + category = ' {:.3f} -> {},'.format(probs[i], self.classes[idx[i]]) + result["categories"] += category + log.debug(category) + + # output the scene attributes + if "attributes" in predict: + responses_attribute = self.w_attribute.dot(self.features_blobs[1]) + idx_a = np.argsort(responses_attribute) + log.debug('--SCENE ATTRIBUTES:') + attributes = ', '.join([self.labels_attribute[idx_a[i]] for i in range(-1, -10, -1)]) + result["attributes"] = attributes + log.debug(attributes) + + # generate class activation mapping + if "cam" in predict: + cams = self.return_cam(self.features_blobs[0], self.weight_softmax, [idx[0]]) + img = cv2.imread(input_image_path) + height, width, _ = img.shape + heatmap = cv2.applyColorMap(cv2.resize(cams[0], (width, height)), cv2.COLORMAP_JET) + cam_result = heatmap * 0.4 + img * 0.5 + cv2.imwrite(cam_path, cam_result) + log.debug('Class activation mapping is saved at {}'.format(cam_path)) + result["cam"] = service.serviceUtils.jpg_to_base64(cam_path, open_file=True).decode("utf-8") + return result + except Exception as e: + log.error(e) + result["error"] = str(e) + return result diff --git a/services/places365-scene-recognition/service/scene_recognition_service.py b/services/places365-scene-recognition/service/scene_recognition_service.py index 7410eec..5fd7729 100644 --- a/services/places365-scene-recognition/service/scene_recognition_service.py +++ b/services/places365-scene-recognition/service/scene_recognition_service.py @@ -90,7 +90,7 @@ def treat_inputs(self, request, arguments, created_images): return image_path, predict, file_index_str - def recognize_scene(self, request, _): + def recognize_scene(self, request, context): """Wraps the scene recognition model to make sure inputs and outputs match the service requirements.""" # Store the names of the images to delete them afterwards @@ -104,13 +104,17 @@ def recognize_scene(self, request, _): try: image_path, predict, file_index_str = self.treat_inputs(request, arguments, created_images) except HTTPError as e: - error_message = "Error downloading the input image \n" + e.read() + error_message = "Error downloading the input image \n" + str(e) log.error(error_message) self.result.data = error_message + context.set_details(error_message) + context.set_code(grpc.StatusCode.INTERNAL) return self.result except Exception as e: log.error(e) self.result.data = e + context.set_details(str(e)) + context.set_code(grpc.StatusCode.INTERNAL) return self.result # Get cam (color activation mappings) file path @@ -130,7 +134,11 @@ def recognize_scene(self, request, _): p.join() response = return_dict.get("response", None) - if not response: + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) return SceneRecognitionResult() # Prepare gRPC output message diff --git a/services/places365-scene-recognition/snetd_configs/snetd.mainnet.json b/services/places365-scene-recognition/snetd_configs/snetd.mainnet.json index e6de179..4a987df 100644 --- a/services/places365-scene-recognition/snetd_configs/snetd.mainnet.json +++ b/services/places365-scene-recognition/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7019", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/places365-scene-recognition/snetd_configs/snetd.ropsten b/services/places365-scene-recognition/snetd_configs/snetd.ropsten index a62a1cc..ea3faed 100644 --- a/services/places365-scene-recognition/snetd_configs/snetd.ropsten +++ b/services/places365-scene-recognition/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7079", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/places365-scene-recognition/test_scene_recognition_service.py b/services/places365-scene-recognition/test_service.py similarity index 100% rename from services/places365-scene-recognition/test_scene_recognition_service.py rename to services/places365-scene-recognition/test_service.py diff --git a/services/pneumonia-diagnosis/Dockerfile b/services/pneumonia-diagnosis/Dockerfile index da0adcb..bf643ec 100644 --- a/services/pneumonia-diagnosis/Dockerfile +++ b/services/pneumonia-diagnosis/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get install -y libsm6 libxext6 libxrender-dev RUN apt-get install -y python3 python3-pip # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/pneumonia-diagnosis/README.md b/services/pneumonia-diagnosis/README.md index 7b0b404..8530bb2 100644 --- a/services/pneumonia-diagnosis/README.md +++ b/services/pneumonia-diagnosis/README.md @@ -47,7 +47,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -68,7 +67,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7062", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "pneumonia-diagnosis", @@ -93,7 +91,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_pneumonia_diagnosis_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -104,7 +102,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_pneumonia_diagnosis_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (check): Image (Link): https://snet-models.s3.amazonaws.com/bh/PneumoniaDiagnosis/diagnosis_normal_1.jpg @@ -112,7 +110,7 @@ Image (Link): https://snet-models.s3.amazonaws.com/bh/PneumoniaDiagnosis/diagnos Normal -$ python3 test_pneumonia_diagnosis_service.py +$ python3 test_service.py Endpoint (localhost:7003): Method (check): Image (Link): https://snet-models.s3.amazonaws.com/bh/PneumoniaDiagnosis/diagnosis_pneumonia.jpg diff --git a/services/pneumonia-diagnosis/run_pneumonia_diagnosis_service.py b/services/pneumonia-diagnosis/run_service.py similarity index 100% rename from services/pneumonia-diagnosis/run_pneumonia_diagnosis_service.py rename to services/pneumonia-diagnosis/run_service.py diff --git a/services/pneumonia-diagnosis/snetd_configs/snetd.mainnet.json b/services/pneumonia-diagnosis/snetd_configs/snetd.mainnet.json index 3b3048c..3292a8f 100644 --- a/services/pneumonia-diagnosis/snetd_configs/snetd.mainnet.json +++ b/services/pneumonia-diagnosis/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7072", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/pneumonia-diagnosis/snetd_configs/snetd.ropsten b/services/pneumonia-diagnosis/snetd_configs/snetd.ropsten index 3f1c872..305b729 100644 --- a/services/pneumonia-diagnosis/snetd_configs/snetd.ropsten +++ b/services/pneumonia-diagnosis/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7062", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/pneumonia-diagnosis/test_pneumonia_diagnosis_service.py b/services/pneumonia-diagnosis/test_service.py similarity index 100% rename from services/pneumonia-diagnosis/test_pneumonia_diagnosis_service.py rename to services/pneumonia-diagnosis/test_service.py diff --git a/services/real-time-voice-cloning/Dockerfile b/services/real-time-voice-cloning/Dockerfile index bb885a9..dddef80 100644 --- a/services/real-time-voice-cloning/Dockerfile +++ b/services/real-time-voice-cloning/Dockerfile @@ -26,7 +26,7 @@ RUN apt-get clean && \ apt-get -y autoremove # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/real-time-voice-cloning/README.md b/services/real-time-voice-cloning/README.md index d1f1bd7..c6ed5bf 100644 --- a/services/real-time-voice-cloning/README.md +++ b/services/real-time-voice-cloning/README.md @@ -39,7 +39,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -60,7 +59,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7065", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "real-time-voice-cloning", @@ -85,7 +83,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_voice_cloning_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -97,7 +95,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_voice_cloning_service.py +$ python3 test_service.py Endpoint (localhost:7003): Audio (link): https://raw.githubusercontent.com/singnet/dnn-model-services/master/docs/assets/users_guide/ben_websumit19.mp3 Sentence (~20 words): I am an artificial intelligence researcher and I would like to make the world a better place! diff --git a/services/real-time-voice-cloning/run_voice_cloning_service.py b/services/real-time-voice-cloning/run_service.py similarity index 100% rename from services/real-time-voice-cloning/run_voice_cloning_service.py rename to services/real-time-voice-cloning/run_service.py diff --git a/services/real-time-voice-cloning/service/voice_cloning.py b/services/real-time-voice-cloning/service/voice_cloning.py index 65d7be3..974de0a 100755 --- a/services/real-time-voice-cloning/service/voice_cloning.py +++ b/services/real-time-voice-cloning/service/voice_cloning.py @@ -21,7 +21,7 @@ def clone(audio=None, audio_url=None, sentence=""): try: if not 10 <= len(sentence.split(" ")) <= 30: - return {"audio": b"Sentence is invalid! (length must be 10 to 30 words)"} + return {"error": "Sentence is invalid! (length must be 10 to 30 words)"} audio_data = audio if audio_url: # Link @@ -33,7 +33,7 @@ def clone(audio=None, audio_url=None, sentence=""): size = int(size) / float(1 << 20) log.info("File size: {:.2f} Mb".format(size)) if size > 10: - return {"audio": b"Input audio file is too large! (max 10Mb)"} + return {"error": "Input audio file is too large! (max 10Mb)"} r = requests.get(audio_url, headers=header, allow_redirects=True) audio_data = r.content # Base64 @@ -85,7 +85,7 @@ def clone(audio=None, audio_url=None, sentence=""): except Exception as e: log.error(e) traceback.print_exc() - return {"audio": b"Fail"} + return {"error": "Fail"} def generate_uid(): diff --git a/services/real-time-voice-cloning/service/voice_cloning_service.py b/services/real-time-voice-cloning/service/voice_cloning_service.py index 1dee04b..b4508e1 100644 --- a/services/real-time-voice-cloning/service/voice_cloning_service.py +++ b/services/real-time-voice-cloning/service/voice_cloning_service.py @@ -32,7 +32,7 @@ def __init__(self): # request: incoming data # context: object that provides RPC-specific information (timeout, etc). @staticmethod - def clone(request, _): + def clone(request, context): manager = multiprocessing.Manager() return_dict = manager.dict() worker = multiprocessing.Process( @@ -42,6 +42,13 @@ def clone(request, _): worker.join() response = return_dict.get("response", None) + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) + return Output() + log.debug("clone({},{})={}".format(request.audio_url[:10], request.sentence[:10], len(response["audio"]))) diff --git a/services/real-time-voice-cloning/snetd_configs/snetd.mainnet.json b/services/real-time-voice-cloning/snetd_configs/snetd.mainnet.json index bdfa0eb..d5137e4 100644 --- a/services/real-time-voice-cloning/snetd_configs/snetd.mainnet.json +++ b/services/real-time-voice-cloning/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7064", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/real-time-voice-cloning/snetd_configs/snetd.ropsten b/services/real-time-voice-cloning/snetd_configs/snetd.ropsten index 627fb6b..c0488e6 100644 --- a/services/real-time-voice-cloning/snetd_configs/snetd.ropsten +++ b/services/real-time-voice-cloning/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7065", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/real-time-voice-cloning/test_voice_cloning_service.py b/services/real-time-voice-cloning/test_service.py similarity index 100% rename from services/real-time-voice-cloning/test_voice_cloning_service.py rename to services/real-time-voice-cloning/test_service.py diff --git a/services/s2vt-video-captioning/Dockerfile b/services/s2vt-video-captioning/Dockerfile index 9b823a7..78c4ecc 100644 --- a/services/s2vt-video-captioning/Dockerfile +++ b/services/s2vt-video-captioning/Dockerfile @@ -24,7 +24,7 @@ RUN apt-get update && \ RUN apt-get install -y libsm6 libxext6 libxrender-dev # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/s2vt-video-captioning/README.md b/services/s2vt-video-captioning/README.md index 91de58f..743355b 100644 --- a/services/s2vt-video-captioning/README.md +++ b/services/s2vt-video-captioning/README.md @@ -67,7 +67,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -88,7 +87,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7056", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "s2vt-video-captioning", @@ -113,7 +111,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python2 run_video_cap_service.py +$ python2 run_service.py ``` ### Calling the service: @@ -127,7 +125,7 @@ Inputs: Local (testing purpose): ``` -$ python2 test_call_video_cap_service.py +$ python2 test_service.py Endpoint (localhost:7003): Method (video_cap): Url: http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_PlayingGuitar_g05_c01.avi diff --git a/services/s2vt-video-captioning/run_video_cap_service.py b/services/s2vt-video-captioning/run_service.py similarity index 100% rename from services/s2vt-video-captioning/run_video_cap_service.py rename to services/s2vt-video-captioning/run_service.py diff --git a/services/s2vt-video-captioning/service/video_cap_service.py b/services/s2vt-video-captioning/service/video_cap_service.py index c2686f7..418ea10 100644 --- a/services/s2vt-video-captioning/service/video_cap_service.py +++ b/services/s2vt-video-captioning/service/video_cap_service.py @@ -39,7 +39,7 @@ def __init__(self): # The method that will be exposed to the snet-cli call command. # request: incoming data # context: object that provides RPC-specific information (timeout, etc). - def video_cap(self, request, _): + def video_cap(self, request, context): self.url = request.url self.start_time_sec = request.start_time_sec self.stop_time_sec = request.stop_time_sec @@ -54,8 +54,12 @@ def video_cap(self, request, _): worker.join() response = return_dict.get("response", None) - if not response: - return Output(value="Fail") + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) + return Output() log.debug("video_cap({},{},{})={}".format(self.url, self.start_time_sec, diff --git a/services/s2vt-video-captioning/service/video_captioner.py b/services/s2vt-video-captioning/service/video_captioner.py index 43d4e92..6f06780 100644 --- a/services/s2vt-video-captioning/service/video_captioner.py +++ b/services/s2vt-video-captioning/service/video_captioner.py @@ -136,11 +136,11 @@ def get_video_captions(self): result = f.readlines() self.response["Caption"] = self._create_srt(result) else: - self.response["Caption"] = self.error if self.error else "[Fail] Unexpected error!" + self.response["error"] = self.error if self.error else "[Fail] Unexpected error!" except Exception as e: log.error(e) - self.response["Caption"] = "Fail" + self.response["error"] = str(e) # Deletes video folder. if os.path.exists(self.video_folder): diff --git a/services/s2vt-video-captioning/snetd_configs/snetd.mainnet.json b/services/s2vt-video-captioning/snetd_configs/snetd.mainnet.json index d0a191a..d25f986 100644 --- a/services/s2vt-video-captioning/snetd_configs/snetd.mainnet.json +++ b/services/s2vt-video-captioning/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7006", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/s2vt-video-captioning/snetd_configs/snetd.ropsten b/services/s2vt-video-captioning/snetd_configs/snetd.ropsten index 56622be..dc3065a 100644 --- a/services/s2vt-video-captioning/snetd_configs/snetd.ropsten +++ b/services/s2vt-video-captioning/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7056", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/s2vt-video-captioning/test_video_cap_service.py b/services/s2vt-video-captioning/test_service.py similarity index 100% rename from services/s2vt-video-captioning/test_video_cap_service.py rename to services/s2vt-video-captioning/test_service.py diff --git a/services/sound-spleeter/Dockerfile b/services/sound-spleeter/Dockerfile index 07001d5..07b468e 100644 --- a/services/sound-spleeter/Dockerfile +++ b/services/sound-spleeter/Dockerfile @@ -27,7 +27,7 @@ RUN apt-get clean && \ apt-get -y autoremove # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/sound-spleeter/README.md b/services/sound-spleeter/README.md index 1fdf51c..d73b830 100644 --- a/services/sound-spleeter/README.md +++ b/services/sound-spleeter/README.md @@ -36,7 +36,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -57,7 +56,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7055", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "sound-spleeter", @@ -82,7 +80,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_sound_spleeter_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -93,7 +91,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_sound_spleeter_service.py +$ python3 test_service.py Endpoint (localhost:7003): Audio (URL): http://54.203.198.53:7000/Resources/audio_example.mp3 {'vocals': '...', 'accomp': '...'} diff --git a/services/sound-spleeter/run_sound_spleeter_service.py b/services/sound-spleeter/run_service.py similarity index 100% rename from services/sound-spleeter/run_sound_spleeter_service.py rename to services/sound-spleeter/run_service.py diff --git a/services/sound-spleeter/service/sound_spleeter.py b/services/sound-spleeter/service/sound_spleeter.py index 8cd82d9..b3174e2 100644 --- a/services/sound-spleeter/service/sound_spleeter.py +++ b/services/sound-spleeter/service/sound_spleeter.py @@ -17,11 +17,6 @@ def spleeter(audio_url=None, audio=None): try: - response = { - "vocals": b"Fail", - "accomp": b"Fail" - } - audio_data = audio if audio_url: # Link @@ -33,9 +28,7 @@ def spleeter(audio_url=None, audio=None): size = int(size) / float(1 << 20) log.info("File size: {:.2f} Mb".format(size)) if size > 10: - response["vocals"] = b"Input audio file is too large! (max 10Mb)" - response["accomp"] = b"Fail" - return response + return {"error": "Input audio file is too large! (max 10Mb)"} r = requests.get(audio_url, headers=header, allow_redirects=True) audio_data = r.content # Base64 @@ -72,15 +65,12 @@ def spleeter(audio_url=None, audio=None): # Deleting the files output directory shutil.rmtree(tmp_dir) - - response["vocals"] = vocals - response["accomp"] = accomp - return response + return {"vocals": vocals, "accomp": accomp} except Exception as e: log.error(e) traceback.print_exc() - return response + return {"error": str(e)} def generate_uid(): diff --git a/services/sound-spleeter/service/sound_spleeter_service.py b/services/sound-spleeter/service/sound_spleeter_service.py index 079562d..7fe138c 100644 --- a/services/sound-spleeter/service/sound_spleeter_service.py +++ b/services/sound-spleeter/service/sound_spleeter_service.py @@ -31,7 +31,7 @@ def __init__(self): log.debug("SoundSpleeterServicer created") @staticmethod - def spleeter(request, _): + def spleeter(request, context): manager = multiprocessing.Manager() return_dict = manager.dict() worker = multiprocessing.Process( @@ -41,6 +41,13 @@ def spleeter(request, _): worker.join() response = return_dict.get("response", None) + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) + return Output() + log.debug("clone({},{})={},{}".format(request.audio_url[:10], len(request.audio), len(response["vocals"]), diff --git a/services/sound-spleeter/snetd_configs/snetd.mainnet.json b/services/sound-spleeter/snetd_configs/snetd.mainnet.json index acd1a0a..2067c5b 100644 --- a/services/sound-spleeter/snetd_configs/snetd.mainnet.json +++ b/services/sound-spleeter/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7066", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/sound-spleeter/snetd_configs/snetd.ropsten b/services/sound-spleeter/snetd_configs/snetd.ropsten index fe19921..a82f8c0 100644 --- a/services/sound-spleeter/snetd_configs/snetd.ropsten +++ b/services/sound-spleeter/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7067", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/sound-spleeter/test_sound_spleeter_service.py b/services/sound-spleeter/test_service.py similarity index 100% rename from services/sound-spleeter/test_sound_spleeter_service.py rename to services/sound-spleeter/test_service.py diff --git a/services/yolov3-object-detection/Dockerfile b/services/yolov3-object-detection/Dockerfile index bf7a320..3ba70f6 100644 --- a/services/yolov3-object-detection/Dockerfile +++ b/services/yolov3-object-detection/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get install -y libsm6 libxext6 libxrender-dev RUN apt-get install -y python3 python3-pip # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/yolov3-object-detection/README.md b/services/yolov3-object-detection/README.md index dca367b..2cf46c7 100644 --- a/services/yolov3-object-detection/README.md +++ b/services/yolov3-object-detection/README.md @@ -44,7 +44,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -65,7 +64,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7057", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "yolov3-object-detection", @@ -90,7 +88,7 @@ $ sh buildproto.sh ``` Start the service and `SNET Daemon`: ``` -$ python3 run_object_detection_service.py +$ python3 run_service.py ``` ### Calling the service: @@ -103,7 +101,7 @@ Inputs: Local (testing purpose): ``` -$ python3 test_object_detection_service.py +$ python3 test_service.py Endpoint (localhost:7003): Confidence (0.7): Image (Link): http://www.reidsitaly.com/images/planning/sightseeing/calcio.jpg diff --git a/services/yolov3-object-detection/run_object_detection_service.py b/services/yolov3-object-detection/run_service.py similarity index 100% rename from services/yolov3-object-detection/run_object_detection_service.py rename to services/yolov3-object-detection/run_service.py diff --git a/services/yolov3-object-detection/service/object_detection.py b/services/yolov3-object-detection/service/object_detection.py index 527048e..00f2500 100755 --- a/services/yolov3-object-detection/service/object_detection.py +++ b/services/yolov3-object-detection/service/object_detection.py @@ -153,6 +153,7 @@ def detect(self): "class_ids": [], "confidences": [], "img_base64": b"Fail", + "error": "Fail" } except Exception as e: @@ -166,6 +167,7 @@ def detect(self): "class_ids": [], "confidences": [], "img_base64": b"Fail", + "error": str(e) } diff --git a/services/yolov3-object-detection/service/object_detection_service.py b/services/yolov3-object-detection/service/object_detection_service.py index 968effc..00e1409 100644 --- a/services/yolov3-object-detection/service/object_detection_service.py +++ b/services/yolov3-object-detection/service/object_detection_service.py @@ -31,7 +31,7 @@ def __init__(self): self.confidence = "0.7" log.debug("ObjectDetectorServicer created") - def detect(self, request, _): + def detect(self, request, context): self.img_path = request.img_path self.model = request.model self.confidence = request.confidence @@ -45,16 +45,20 @@ def detect(self, request, _): p.start() p.join() - json_result = return_dict.get("response", None) - if not json_result: + response = return_dict.get("response", None) + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) return Output() log.debug("detect({},{})".format(self.model, self.img_path[:50])) - return Output(delta_time=json_result["delta_time"], - boxes=json_result["boxes"], - class_ids=json_result["class_ids"], - confidences=json_result["confidences"], - img_base64=json_result["img_base64"]) + return Output(delta_time=response["delta_time"], + boxes=response["boxes"], + class_ids=response["class_ids"], + confidences=response["confidences"], + img_base64=response["img_base64"]) # The gRPC serve function. diff --git a/services/yolov3-object-detection/snetd_configs/snetd.mainnet.json b/services/yolov3-object-detection/snetd_configs/snetd.mainnet.json index 9afe424..79f5a20 100644 --- a/services/yolov3-object-detection/snetd_configs/snetd.mainnet.json +++ b/services/yolov3-object-detection/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7007", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/yolov3-object-detection/snetd_configs/snetd.ropsten b/services/yolov3-object-detection/snetd_configs/snetd.ropsten index 1125cd0..ff6954d 100644 --- a/services/yolov3-object-detection/snetd_configs/snetd.ropsten +++ b/services/yolov3-object-detection/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7057", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/yolov3-object-detection/test_object_detection_service.py b/services/yolov3-object-detection/test_service.py similarity index 100% rename from services/yolov3-object-detection/test_object_detection_service.py rename to services/yolov3-object-detection/test_service.py diff --git a/services/zeta36-chess-alpha-zero/Dockerfile b/services/zeta36-chess-alpha-zero/Dockerfile index 58d6857..fdd088a 100644 --- a/services/zeta36-chess-alpha-zero/Dockerfile +++ b/services/zeta36-chess-alpha-zero/Dockerfile @@ -31,7 +31,7 @@ RUN cd ${SINGNET_REPOS} && \ rm -f get-pip.py # Installing SNET Daemon -RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \ +RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.6"` && \ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \ cd /tmp && \ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \ diff --git a/services/zeta36-chess-alpha-zero/README.md b/services/zeta36-chess-alpha-zero/README.md index 2212859..acc8023 100644 --- a/services/zeta36-chess-alpha-zero/README.md +++ b/services/zeta36-chess-alpha-zero/README.md @@ -37,7 +37,6 @@ Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "BLOCKCHAIN_NETWORK", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", "ORGANIZATION_ID": "ORGANIZATION_ID", "SERVICE_ID": "SERVICE_ID", @@ -58,7 +57,6 @@ $ cat snetd.config.json "DAEMON_END_POINT": "0.0.0.0:7058", "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", "BLOCKCHAIN_NETWORK_SELECTED": "ropsten", - "PASSTHROUGH_ENABLED": true, "PASSTHROUGH_ENDPOINT": "http://localhost:7003", "ORGANIZATION_ID": "snet", "SERVICE_ID": "zeta36-chess-alpha-zero", @@ -90,7 +88,7 @@ $ git clone https://github.com/Zeta36/chess-alpha-zero.git Start the service and `SNET Daemon`: ``` -$ python3.6 run_alpha_zero_service.py +$ python3.6 run_service.py ``` ### Calling the service: @@ -137,7 +135,7 @@ Inputs: Local (testing purpose): ``` -$ python3.6 test_alpha_zero_service.py +$ python3.6 test_service.py Endpoint (localhost:7003): Method (play): UID (empty): human_player diff --git a/services/zeta36-chess-alpha-zero/run_alpha_zero_service.py b/services/zeta36-chess-alpha-zero/run_service.py similarity index 100% rename from services/zeta36-chess-alpha-zero/run_alpha_zero_service.py rename to services/zeta36-chess-alpha-zero/run_service.py diff --git a/services/zeta36-chess-alpha-zero/service/alpha_zero.py b/services/zeta36-chess-alpha-zero/service/alpha_zero.py index dcf70b4..0f739e0 100644 --- a/services/zeta36-chess-alpha-zero/service/alpha_zero.py +++ b/services/zeta36-chess-alpha-zero/service/alpha_zero.py @@ -49,7 +49,7 @@ def play(self): try: self.alpha_player = self.create() if not self.alpha_player: - return None, None + return None, {"error": "Error while creating player."} # User move self.chess_env.step(self.move) @@ -75,6 +75,7 @@ def play(self): except Exception as e: self.response["status"] = "move_error" self.response["board"] = pprint_board(self.chess_env.board) + self.response["error"] = str(e) log.error("move_error: {}".format(e)) traceback.print_exc() return self.chess_env, self.response diff --git a/services/zeta36-chess-alpha-zero/service/alpha_zero_service.py b/services/zeta36-chess-alpha-zero/service/alpha_zero_service.py index d90e5bd..1e2bd1f 100644 --- a/services/zeta36-chess-alpha-zero/service/alpha_zero_service.py +++ b/services/zeta36-chess-alpha-zero/service/alpha_zero_service.py @@ -39,12 +39,12 @@ def __init__(self): self.move = "" self.cmd = "" log.debug("AlphaZeroServicer created") - + # The method that will be exposed to the snet-cli call command. # request: incoming data # context: object that provides RPC-specific information (timeout, etc). - def play(self, request, _): - + def play(self, request, context): + try: # In our case, request is a Input() object (from .proto file) self.uid = request.uid @@ -71,7 +71,7 @@ def play(self, request, _): elif self.cmd == "restart": chess_env = ChessEnv().reset() log.debug("CMD [restart]: {}".format(self.uid)) - + self.move = request.move manager = multiprocessing.Manager() @@ -85,9 +85,13 @@ def play(self, request, _): p.join() chess_env, response = return_dict.get("response", (None, None)) - if not response: - return Output(status="Fail") - + if not response or "error" in response: + error_msg = response.get("error", None) if response else None + log.error(error_msg) + context.set_details(error_msg) + context.set_code(grpc.StatusCode.INTERNAL) + return Output() + # Game over if chess_env is None: del CHESS_ENV_DICT[self.uid] @@ -98,7 +102,7 @@ def play(self, request, _): board = "" for idx, line in enumerate(response["board"]): board += "{}\n".format(line) - + log.debug("play({},{}):\n{}\n{}\n{}".format( self.move, self.cmd, @@ -106,7 +110,7 @@ def play(self, request, _): board, response["status"])) return Output(uid=self.uid, board=board, status=response["status"]) - + except Exception as e: traceback.print_exc() log.error(e) diff --git a/services/zeta36-chess-alpha-zero/snetd_configs/snetd.mainnet.json b/services/zeta36-chess-alpha-zero/snetd_configs/snetd.mainnet.json index 5e814be..ab22c70 100644 --- a/services/zeta36-chess-alpha-zero/snetd_configs/snetd.mainnet.json +++ b/services/zeta36-chess-alpha-zero/snetd_configs/snetd.mainnet.json @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7008", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "main", "organization_id": "snet", diff --git a/services/zeta36-chess-alpha-zero/snetd_configs/snetd.ropsten b/services/zeta36-chess-alpha-zero/snetd_configs/snetd.ropsten index 5011721..a3d4065 100644 --- a/services/zeta36-chess-alpha-zero/snetd_configs/snetd.ropsten +++ b/services/zeta36-chess-alpha-zero/snetd_configs/snetd.ropsten @@ -1,7 +1,6 @@ { "daemon_end_point": "0.0.0.0:7058", "ipfs_end_point": "http://ipfs.singularitynet.io:80", - "passthrough_enabled": true, "passthrough_endpoint": "http://localhost:7003", "blockchain_network_selected": "ropsten", "organization_id": "snet", diff --git a/services/zeta36-chess-alpha-zero/test_alpha_zero_service.py b/services/zeta36-chess-alpha-zero/test_service.py similarity index 100% rename from services/zeta36-chess-alpha-zero/test_alpha_zero_service.py rename to services/zeta36-chess-alpha-zero/test_service.py diff --git a/utils/requirements.txt b/utils/requirements.txt index 5c1eae5..27f4896 100644 --- a/utils/requirements.txt +++ b/utils/requirements.txt @@ -1,4 +1,4 @@ cntk==2.6 opencv-python==3.4.3.18 -Pillow==6.2.0 +Pillow==6.2.2 requests==2.20.0 \ No newline at end of file