Simple image classification service compatible with the SingularityNET daemon
- Clone the git repository
$ git clone git@github.com:singnet/example-service.git
$ cd example-service
- Install the dependencies
$ pip install -r requirements.txt
- The following default configuration can be overridden by populating configuration/config.json in the source tree with the desired values
{
"SERVER_PORT": 5001,
"MINIMUM_SCORE": 0.20,
"LOG_LEVEL": 10
}
- SERVER_PORT: the port on which the example service will listen for incoming JSON-RPC calls over http
- MINIMUM_SCORE: the minimum confidence score (between 0 and 1 inclusive) required to return a given prediction
- LOG_LEVEL: the logging verbosity
- Invoke the example service directly
$ python image_classification_service
- The following configuration values should be populated in a file (e.g. snetd.config) as described
{
"REGISTRY_ADDRESS_KEY":"",
"DAEMON_END_POINT":"",
"DAEMON_LISTENING_PORT": 5000,
"ORGANIZATION_NAME":"",
"SERVICE_NAME":"",
"IPFS_END_POINT":"",
"AUTO_SSL_DOMAIN": "",
"AUTO_SSL_CACHE_DIR": "",
"BLOCKCHAIN_ENABLED": true,
"CONFIG_PATH": "",
"DB_PATH": "",
"ETHEREUM_JSON_RPC_ENDPOINT": "",
"EXECUTABLE_PATH": "",
"HDWALLET_INDEX": 0,
"HDWALLET_MNEMONIC": "",
"PASSTHROUGH_ENABLED": true,
"PASSTHROUGH_ENDPOINT": "",
"PRIVATE_KEY": "",
"SSL_CERT": "",
"SSL_KEY": "",
"LOG": {
"FORMATTER": {
"TYPE": "text"
},
"HOOKS": [],
"LEVEL": "INFO",
"OUTPUT": {
"CURRENT_LINK": "./snet-daemon.log",
"FILE_PATTERN": "./snet-daemon.%Y%m%d.log",
"MAX_AGE_IN_SEC": 604800,
"ROTATION_COUNT": 0,
"ROTATION_TIME_IN_SEC": 86400,
"TYPE": "file"
},
"TIMEZONE": "UTC"
},
"PAYMENT_CHANNEL_STORAGE_CLIENT": {
"CONNECTION_TIMEOUT": "",
"ENDPOINTS": ["http://127.0.0.1:2379"],
"REQUEST_TIMEOUT": "3s"
},
"PAYMENT_CHANNEL_STORAGE_SERVER": {
"ID": "storage-1",
"SCHEME": "http",
"HOST" : "127.0.0.1",
"CLIENT_PORT": 2379,
"PEER_PORT": 2380,
"TOKEN": "UNIQUE-TOKEN",
"CLUSTER": "storage-1=http://127.0.0.1:2380",
"STARTUP_TIMEOUT": "1m",
"DATA_DIR": "storage-data-dir-1.etcd",
"LOG_LEVEL": "INFO",
"ENABLED": TRUE
}
}
- REGISTRY_ADDRESS: the address of the registry where the service is published
- DAEMON_END_POINT: the end point as specified during service registration
- DAEMON_LISTENING_PORT: the port on which the daemon will listen for incoming JSON-RPC calls over http (must differ from SERVER_PORT in the service configuration). This should match the port number specified in DAEMON_END_POINT
- AUTO_SSL_DOMAIN: domain for which daemon should acquire LetsEncrypt SSL certificates
- AUTO_SSL_CACHE_DIR: directory in which daemon should cache LetsEncrypt SSL certificates
- BLOCKCHAIN_ENABLED: whether the daemon validates and completes calls against the blockchain
- DB_PATH: path at which daemon should maintain local database of blockchain and job state
- ETHEREUM_JSON_RPC_ENDPOINT: the Ethereum node the daemon should run its blockchain client against (i.e. geth, ganache, infura; only applicable if BLOCKCHAIN_ENABLED)
- EXECUTABLE_PATH: not used for example service
- HDWALLET_INDEX: the index of the account that the daemon should use to transact on the blockchain
- HDWALLET_MNEMONIC: the bip39 mnemonic corresponding with the root seed for the bip32 wallet from which the daemon's account should be derived
- PASSTHROUGH_ENABLED: whether the daemon delegates calls to service or echoes requests back to the client (should be true)
- PASSTHROUGH_ENDPOINT: the endpoint on which the service is configured to listen for incoming JSON-RPC calls over http
- PRIVATE_KEY: the hex-encoded private key for the account that the daemon should use to transact on the blockchain (takes precedence if both PRIVATE_KEY and HDWALLET_MNEMONIC are provided)
- SSL_CERT: path to certificate file daemon should use for SSL
- SSL_KEY: path to key file daemon should use for SSL
- PAYMENT_CHANNEL_STORAGE_CLIENT: etcd connection details. Payment channel details are read from this etcd instance when the claim command is run on the daemon
- PAYMENT_CHANNEL_STORAGE_SERVER: etcd connection details. Payment channel details are written to this etcd instance
- Invoke the run-snet-service script which launches both snetd and the example service
$ ./scripts/run-snet-service
- Ensure that PASSTHROUGH_ENDPOINT is configured to be "http://127.0.0.1:5001" in your daemon configuration
- Run the docker image with your daemon configuration (where HOST_PORT is the port you want the daemon bound to on your host)
$ docker run --detach -p HOST_PORT:DAEMON_LISTENING_PORT -v /path/to/config:/snetd.config singularitynet/example-service:latest
- Invoke the test-call script against a running instance of the example service
$ ./scripts/test-call
- Invoke the docker build script
$ ./scripts/build-docker
This project is licensed under the MIT License - see the LICENSE file for details.