-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
executable file
·89 lines (80 loc) · 2.2 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React,{Component} from 'react';
import './App.css';
import Navigation from './component/Navigation/Navigation';
import Logo from './component/Logo/Logo';
import ImageLinkForm from './component/ImageLinkForm/ImageLinkForm';
import Rank from './component/Rank/Rank';
import Particles from 'react-particles-js';
import FaceRecognition from './component/FaceRecognition/FaceRecognition';
import Clarifai from 'clarifai';
const app = new Clarifai.App({
apiKey: '87b5eb01a1b44f60aa27702bed42544d'
});
const particlesOptions ={
particles: {
number:{
value:40,
density:{
enable:true,
value_area:300
}
}
}
}
class App extends Component {
constructor(){
super()
this.state ={
input:'',
imageUrl:'',
box:{}
}
}
calculateFaceLocation=(data)=>{
const clarafaiFace = data.outputs[0].data.regions[0].region_info.bounding_box ;
const image= document.getElementById('inputimage');
const width = Number(image.width);
const height = Number(image.height);
return{
leftCol:clarafaiFace.left_col*width,
topRow:clarafaiFace.top_row*height ,
rightCol:width - (clarafaiFace.right_col*width),
bottomRow:height - (clarafaiFace.bottom_row*height),
}
}
displayFaceBox=(box)=>{
console.log(box)
this.setState({box:box});
}
onInputChange= (event) =>{
this.setState({input:event.target.value});
}
onSubmitButton =() =>{
this.setState({imageUrl:this.state.input});
app.models
.predict(
Clarifai.FACE_DETECT_MODEL,
this.state.input)
.then(response=>this.displayFaceBox(this.calculateFaceLocation(response)))
.catch(err=> console.log(err))
}
render(){
return (
<div className="App">
<Particles
className='particles'
params={particlesOptions}
/>
<Navigation/>
<Logo/>
<Rank/>
<ImageLinkForm
onInputChange={this.onInputChange}
onSubmitButton={this.onSubmitButton}
/>
<FaceRecognition box={this.state.box} imageUrl={this.state.imageUrl}/>
</div>
);
}
}
export default App;