Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
add meow service
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos committed Oct 13, 2018
1 parent 2283ae7 commit 43e94e6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

Cloud classification service for weather bot

nodejs and python with tensorflow are required.
rust, nodejs, python with tensorflow are required.

```sh
git clone https://github.com/weather-bot/cloudlady
cd cloudlady
npm install
# download model
wget https://github.com/weather-bot/cloudlady/releases/download/v0.0.0/retrained_graph.pb -P python/model
# download cats images
wget https://github.com/weather-bot/meow/releases/download/v0.0.1/cats.tar.gz
tar zxvf cats.tar.gz
# compile meow
git clone https://github.com/weather-bot/meow.git
cd meow
cargo build --release
cp ./target/release/meow ../meow
cd ..
# run
npm start
```
33 changes: 33 additions & 0 deletions api/meow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const express = require('express');
const app = express.Router();
const logger = require('node-color-log');
const uuidv1 = require('uuid/v1');

app.post('/moew', async (req, res) => {
const uuid = uuidv1();
logger.info(`/api/meow: [${uuid}] new request`);

const info = req.body;

const meow = path.join(__dirname, '../meow');
const outputFile = path.join(__dirname, `../${uuid}.jpg`);
// cats is the images folder, and 27 is quantity.
const command = `${meow} bottom-mode cats/${Math.floor(Math.random()*27)}.jpg '${JSON.stringify(info)}' -o ${outputFile}`;
const {
stdout,
stderr
} = await exec(command);
if (stderr) {
logger.warn(`/api/meow: [${uuid}] return 400`);
return res.status(400).send("meow creates image failed.");
}
logger.info(`/api/meow: [${uuid}] the image created.`)
logger.info(`/api/meow: [${uuid}] return 200`);
return res.status(200).json({
uuid
});
})

module.exports = app;
12 changes: 12 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ app.use(cors());

// ===== API =====
app.use('/api', require('./api/classify'));
app.use('/api', require('./api/meow'));

// ===== Image =====
app.get('/img', (req, res)=> {
const uuid = req.query.uuid;
const file = `${uuid}.jpg`;
res.sendFile(file);
fs.unlink(file, err => {
if (err) logger.error(err);
logger.info(`/img: [${uuid}] the image delete.`)
});
});

// ===== Front End =====
app.get('/', (req, res) => {
Expand Down

0 comments on commit 43e94e6

Please sign in to comment.