Last active
January 6, 2019 07:04
-
-
Save supachaic/0e28b2ce3e9eefd097c1ba66aefa1ff5 to your computer and use it in GitHub Desktop.
src/views/ImageInput.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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