Skip to content

Instantly share code, notes, and snippets.

@supachaic
Last active January 6, 2019 07:04
Show Gist options
  • Save supachaic/0e28b2ce3e9eefd097c1ba66aefa1ff5 to your computer and use it in GitHub Desktop.
Save supachaic/0e28b2ce3e9eefd097c1ba66aefa1ff5 to your computer and use it in GitHub Desktop.
src/views/ImageInput.js
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { loadModels, getFullFaceDescription } from '../api/face';
// Import image to test API
const testImg = require('../img/test.jpg');
// Initial State
const INIT_STATE = {
imageURL: testImg,
fullDesc: null
};
class ImageInput extends Component {
constructor(props) {
super(props);
this.state = { ...INIT_STATE };
}
componentWillMount = async () => {
await loadModels();
await this.handleImage(this.state.imageURL);
};
handleImage = async (image = this.state.imageURL) => {
await getFullFaceDescription(image).then(fullDesc => {
console.log(fullDesc);
this.setState({ fullDesc });
});
};
render() {
const { imageURL } = this.state;
return (
<div>
<img src={imageURL} alt="imageURL" />
</div>
);
}
}
export default withRouter(ImageInput);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment