[demo] Store name and description in contract (#70)
* demo: Set name and other important to main entrypoint contract. * demo: Support starting with server not enabled. * demo/README: Clarify server setup. * demo/migrations: Add to DB and fail if certain flags are enabled.
This commit is contained in:
Родитель
57b489b004
Коммит
c81c3cc83f
|
@ -77,6 +77,17 @@ Do once:
|
|||
* Copy the first private key output.
|
||||
* Use that private key to create a new account in MetaMask.
|
||||
|
||||
## Server (Optional)
|
||||
If you want to store meta-data in a local database file instead of just within the browser, then start the server in one terminal.
|
||||
This step allows you to see models listed when you open the dashboard for the first time.
|
||||
|
||||
If you do want to use the database file then you should have `REACT_APP_ENABLE_SERVICE_DATA_STORE=true` in your `client/.env.development` file.
|
||||
|
||||
Run:
|
||||
```bash
|
||||
yarn server
|
||||
```
|
||||
|
||||
## Client
|
||||
Then in another terminal.
|
||||
Run:
|
||||
|
@ -84,13 +95,6 @@ Run:
|
|||
yarn client
|
||||
```
|
||||
|
||||
## Server (Optional)
|
||||
If you want to store meta-data in a local database instead of within the browser, then start the server in one terminal.
|
||||
Run:
|
||||
```bash
|
||||
yarn server
|
||||
```
|
||||
|
||||
## Troubleshooting Deployment
|
||||
### Blockchain Issues
|
||||
Run `yarn clean` to delete your local blockchain and cached contracts. This will delete any transactions done but should make everything work again.
|
||||
|
|
|
@ -5,6 +5,24 @@ import "./libs/SafeMath.sol";
|
|||
import {Classifier64} from "./classification/Classifier.sol";
|
||||
import {DataHandler64} from "./data/DataHandler.sol";
|
||||
import {IncentiveMechanism64} from "./incentive/IncentiveMechanism.sol";
|
||||
/**
|
||||
* The main interface to sharing updatable models on the blockchain.
|
||||
*/
|
||||
contract CollaborativeTrainer {
|
||||
string public name;
|
||||
string public description;
|
||||
string public encoder;
|
||||
|
||||
constructor (
|
||||
string memory _name,
|
||||
string memory _description,
|
||||
string memory _encoder
|
||||
) public {
|
||||
name = _name;
|
||||
description = _description;
|
||||
encoder = _encoder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main interface to Decentralized & Collaborative AI on the Blockchain.
|
||||
|
@ -13,7 +31,7 @@ import {IncentiveMechanism64} from "./incentive/IncentiveMechanism.sol";
|
|||
// Using IoC even though it's more expensive, it's easier to work with.
|
||||
// Those wishing to optimize can change the code to use inheritance and do other optimizations before deploying.
|
||||
// We can also make a script that generates the required files based on several parameters.
|
||||
contract CollaborativeTrainer64 {
|
||||
contract CollaborativeTrainer64 is CollaborativeTrainer {
|
||||
|
||||
using SafeMath for uint256;
|
||||
|
||||
|
@ -43,10 +61,13 @@ contract CollaborativeTrainer64 {
|
|||
Classifier64 public classifier;
|
||||
|
||||
constructor(
|
||||
string memory _name,
|
||||
string memory _description,
|
||||
string memory _encoder,
|
||||
DataHandler64 _dataHandler,
|
||||
IncentiveMechanism64 _incentiveMechanism,
|
||||
Classifier64 _classifier
|
||||
) public {
|
||||
) CollaborativeTrainer(_name, _description, _encoder) public {
|
||||
dataHandler = _dataHandler;
|
||||
incentiveMechanism = _incentiveMechanism;
|
||||
classifier = _classifier;
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
set -e
|
||||
|
||||
# Default to development environment.
|
||||
export NODE_ENVIRONMENT=${NODE_ENVIRONMENT:-development}
|
||||
|
||||
truffle compile
|
||||
truffle migrate
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
const pjson = require('../package.json');
|
||||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
|
||||
const { convertData, convertNum } = require('../src/float-utils-node.js');
|
||||
const pjson = require('../package.json')
|
||||
const { convertData, convertNum } = require('../src/float-utils-node.js')
|
||||
|
||||
const CollaborativeTrainer64 = artifacts.require("./CollaborativeTrainer64");
|
||||
const DataHandler64 = artifacts.require("./data/DataHandler64");
|
||||
|
@ -14,12 +14,15 @@ module.exports = async function (deployer) {
|
|||
return;
|
||||
}
|
||||
// Information to persist to the DB.
|
||||
const name = "IMDB Review Sentiment Classifier"
|
||||
const description = "A simple IMDB sentiment analysis model."
|
||||
const encoder = 'IMDB vocab'
|
||||
const modelInfo = {
|
||||
name: "IMDB Review Sentiment Classifier",
|
||||
description: "A simple IMDB sentiment analysis model.",
|
||||
name,
|
||||
description,
|
||||
accuracy: '0.829',
|
||||
modelType: 'Classifier64',
|
||||
encoder: 'IMDB vocab',
|
||||
encoder,
|
||||
};
|
||||
|
||||
const toFloat = 1E9;
|
||||
|
@ -65,6 +68,7 @@ module.exports = async function (deployer) {
|
|||
|
||||
console.log(`Deploying collaborative trainer contract.`);
|
||||
return deployer.deploy(CollaborativeTrainer64,
|
||||
name, description, encoder,
|
||||
dataHandler.address,
|
||||
incentiveMechanism.address,
|
||||
classifier.address
|
||||
|
@ -79,7 +83,8 @@ module.exports = async function (deployer) {
|
|||
return axios.post(`${pjson.proxy}api/models`, modelInfo).then(() => {
|
||||
console.log("Added model to DB.");
|
||||
}).catch(err => {
|
||||
if (process.env.CI !== "true") {
|
||||
if (process.env.CI !== "true" && process.env.REACT_APP_ENABLE_SERVICE_DATA_STORE === 'true') {
|
||||
// It is okay to fail adding the model in CI but otherwise it should work.
|
||||
console.error("Error adding model to DB.");
|
||||
console.error(err);
|
||||
throw err;
|
||||
|
|
|
@ -14,12 +14,15 @@ module.exports = function (deployer) {
|
|||
return;
|
||||
}
|
||||
// Information to persist to the DB.
|
||||
const name = "VPA Classifier"
|
||||
const description = "Supports multiple domains."
|
||||
const encoder = 'universal sentence encoder'
|
||||
const modelInfo = {
|
||||
name: "VPA Classifier",
|
||||
description: "Supports multiple domains.",
|
||||
name,
|
||||
description,
|
||||
accuracy: '0.88',
|
||||
modelType: 'Classifier64',
|
||||
encoder: 'universal sentence encoder',
|
||||
encoder,
|
||||
};
|
||||
|
||||
const toFloat = 1E9;
|
||||
|
@ -67,6 +70,7 @@ module.exports = function (deployer) {
|
|||
}
|
||||
console.log(`Deploying main entry point.`);
|
||||
return deployer.deploy(CollaborativeTrainer64,
|
||||
name, description, encoder,
|
||||
dataHandler.address,
|
||||
incentiveMechanism.address,
|
||||
classifier.address
|
||||
|
@ -81,7 +85,7 @@ module.exports = function (deployer) {
|
|||
return axios.post(`${pjson.proxy}api/models`, modelInfo).then(() => {
|
||||
console.log("Added model to DB.");
|
||||
}).catch(err => {
|
||||
if (process.env.CI !== "true") {
|
||||
if (process.env.CI !== "true" && process.env.REACT_APP_ENABLE_SERVICE_DATA_STORE === 'true') {
|
||||
console.error("Error adding model to DB.");
|
||||
console.error(err);
|
||||
throw err;
|
||||
|
|
|
@ -16,12 +16,15 @@ module.exports = function (deployer) {
|
|||
const toFloat = 1E9;
|
||||
|
||||
// Information to persist to the DB.
|
||||
const name = "Hot Dog Classifier"
|
||||
const description = "Classifies pictures as hot dog or not hot dog."
|
||||
const encoder = 'MobileNetv2'
|
||||
const modelInfo = {
|
||||
name: "Hot Dog Classifier",
|
||||
description: "Classifies pictures as hot dog or not hot dog.",
|
||||
name,
|
||||
description,
|
||||
accuracy: '0.63',
|
||||
modelType: 'Classifier64',
|
||||
encoder: 'MobileNetv2',
|
||||
encoder,
|
||||
};
|
||||
|
||||
// Low default times for testing.
|
||||
|
@ -79,6 +82,7 @@ module.exports = function (deployer) {
|
|||
|
||||
console.log(`Deploying main entry point.`);
|
||||
const instance = await deployer.deploy(CollaborativeTrainer64,
|
||||
name, description, encoder,
|
||||
dataHandler.address,
|
||||
incentiveMechanism.address,
|
||||
classifier.address
|
||||
|
@ -89,11 +93,10 @@ module.exports = function (deployer) {
|
|||
await classifier.transferOwnership(instance.address);
|
||||
|
||||
modelInfo.address = instance.address;
|
||||
|
||||
return axios.post(`${pjson.proxy}api/models`, modelInfo).then(() => {
|
||||
console.log("Added model to DB.");
|
||||
}).catch(err => {
|
||||
if (process.env.CI !== "true") {
|
||||
if (process.env.CI !== "true" && process.env.REACT_APP_ENABLE_SERVICE_DATA_STORE === 'true') {
|
||||
console.error("Error adding model to DB.");
|
||||
console.error(err);
|
||||
throw err;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"axios": "^0.19.0",
|
||||
"blueimp-load-image": "^2.24.0",
|
||||
"canvas": "^2.6.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"immutability-helper": "^3.0.1",
|
||||
"moment": "^2.24.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
|
|
|
@ -575,7 +575,10 @@ class AddModel extends React.Component {
|
|||
});
|
||||
return collaborativeTrainer64Contract.deploy({
|
||||
data: CollaborativeTrainer64.bytecode,
|
||||
arguments: [dataHandler.options.address, incentiveMechanism.options.address, model.options.address],
|
||||
arguments: [
|
||||
this.state.name, this.state.description, this.state.encoder,
|
||||
dataHandler.options.address, incentiveMechanism.options.address, model.options.address
|
||||
],
|
||||
}).send({
|
||||
}).on('transactionHash', transactionHash => {
|
||||
this.dismissNotification(pleaseAcceptKey);
|
||||
|
|
|
@ -629,7 +629,7 @@ class Model extends React.Component {
|
|||
.then(parseInt)
|
||||
.then(refundWaitTimeS => {
|
||||
this.setState({ refundWaitTimeS });
|
||||
})
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ cleanup() {
|
|||
}
|
||||
|
||||
# The `set -e` at the top doesn't seem to help with getting these exit on failure.
|
||||
# Default to development environment.
|
||||
export NODE_ENVIRONMENT=${NODE_ENVIRONMENT:-development}
|
||||
truffle compile || cleanup exit
|
||||
CI=true truffle migrate || cleanup exit
|
||||
CI=true truffle test test/contracts/*.js test/contracts/**/*.js || cleanup exit
|
||||
|
|
|
@ -56,6 +56,7 @@ contract('CollaborativeTrainer with Perceptron', function (accounts) {
|
|||
console.log(` Deployed classifier to ${classifier.address}.`);
|
||||
console.log(`Deploying collaborative trainer.`);
|
||||
return CollaborativeTrainer64.new(
|
||||
"name", "description", "encoder",
|
||||
dataHandler.address,
|
||||
incentiveMechanism.address,
|
||||
classifier.address
|
||||
|
|
|
@ -90,6 +90,7 @@ contract('VpaClassifier', function (accounts) {
|
|||
}
|
||||
console.log(` Deploying main entry point.`);
|
||||
instance = await CollaborativeTrainer64.new(
|
||||
"name", "description", "encoder",
|
||||
dataHandler.address,
|
||||
incentiveMechanism.address,
|
||||
classifier.address
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
const path = require("path");
|
||||
const path = require('path')
|
||||
|
||||
// Use NODE_ENVIRONMENT if set but remove . before it if production.
|
||||
const env = process.env.NODE_ENVIRONMENT;
|
||||
let suffix = '.development';
|
||||
if (env === 'production') {
|
||||
suffix = ''
|
||||
} else if (env !== undefined) {
|
||||
suffix = `.${env}`
|
||||
}
|
||||
require('dotenv').config({ path: path.resolve(__dirname, `.env${suffix}`) })
|
||||
|
||||
module.exports = {
|
||||
// See <https://truffleframework.com/docs/truffle/reference/configuration>
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче