-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
112 lines (101 loc) · 2.9 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { Component } from "react";
import "./App.css";
import Navigation from "./components/navigation/Navigation";
import Logo from "./components/logo/Logo";
import ImageLinkForm from "./components/imageLinkForm/ImageLinkForm";
import Rank from "./components/rank/Rank";
import Particles from "react-particles-js";
import FaceRecognition from "./components/faceRecognition/FaceRecognition";
import Clarifai from "clarifai";
import SignIn from "./components/signin/SignIn";
import Register from "./components/register/Register";
const app = new Clarifai.App({
apiKey: "8ab675c69c9e4d5bb6a91928641e1076",
});
const particlesOptions = {
particles: {
number: {
value: 50,
density: {
enable: true,
value_area: 800,
},
},
},
};
class App extends Component {
constructor() {
super();
this.state = {
input: "",
imageUrl: "",
box: {},
route: "signin",
isSignedIn: false,
};
}
calculateFaceLocation = (data) => {
const clarifyFace =
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: clarifyFace.left_col * width,
topRow: clarifyFace.top_row * height,
rightCol: width - clarifyFace.right_col * width,
bottomRow: height - clarifyFace.bottom_row * height,
};
};
displayFaceBox = (box) => {
this.setState({ box: box });
};
onInputChange = (e) => {
this.setState({ input: e.target.value });
};
onButtonSubmit = () => {
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));
};
onRouteChange = (route) => {
if (route === "signout") {
this.setState({ isSignedIn: false });
} else if (route === "home") {
this.setState({ isSignedIn: true });
}
this.setState({ route });
};
render() {
const { isSignedIn, imageUrl, route, box } = this.state;
return (
<div className="App">
<Particles className="particles" params={particlesOptions} />
<Navigation
isSignedIn={isSignedIn}
onRouteChange={this.onRouteChange}
/>
{route === "home" ? (
<div>
<Logo />
<Rank />
<ImageLinkForm
onInputChange={this.onInputChange}
onButtonSubmit={this.onButtonSubmit}
/>
<FaceRecognition box={box} imageUrl={imageUrl} />
</div>
) : route === "signin" ? (
<SignIn onRouteChange={this.onRouteChange} />
) : (
<Register onRouteChange={this.onRouteChange} />
)}
</div>
);
}
}
export default App;