diff --git a/Todo App/dev.js b/Todo App/dev.js new file mode 100644 index 0000000..a27b856 --- /dev/null +++ b/Todo App/dev.js @@ -0,0 +1,147 @@ +import React, { Component } from 'react'; +import Particles from 'react-particles-js'; +import Clarifai from 'clarifai'; +import FaceRecognition from './components/FaceRecognition/FaceRecognition'; +import Navigation from './components/Navigation/Navigation'; +import Signin from './components/Signin/Signin'; +import Register from './components/Register/Register'; +import Logo from './components/Logo/Logo'; +import ImageLinkForm from './components/ImageLinkForm/ImageLinkForm'; +import Rank from './components/Rank/Rank'; +import './App.css'; + +//You must add your own API key here from Clarifai. +const app = new Clarifai.App({ + apiKey: 'YOUR_API_HERE' +}); + +const particlesOptions = { + particles: { + number: { + value: 30, + density: { + enable: true, + value_area: 800 + } + } + } +} + +class App extends Component { + constructor() { + super(); + this.state = { + input: '', + imageUrl: '', + box: {}, + route: 'signin', + isSignedIn: false, + user: { + id: '', + name: '', + email: '', + entries: 0, + joined: '' + } + } + } + + loadUser = (data) => { + this.setState({user: { + id: data.id, + name: data.name, + email: data.email, + entries: data.entries, + joined: data.joined + }}) + } + + calculateFaceLocation = (data) => { + const clarifaiFace = 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: clarifaiFace.left_col * width, + topRow: clarifaiFace.top_row * height, + rightCol: width - (clarifaiFace.right_col * width), + bottomRow: height - (clarifaiFace.bottom_row * height) + } + } + + displayFaceBox = (box) => { + this.setState({box: box}); + } + + onInputChange = (event) => { + this.setState({input: event.target.value}); + } + + onButtonSubmit = () => { + this.setState({imageUrl: this.state.input}); + app.models + .predict( + Clarifai.FACE_DETECT_MODEL, + this.state.input) + .then(response => { + if (response) { + fetch('http://localhost:3000/image', { + method: 'put', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + id: this.state.user.id + }) + }) + .then(response => response.json()) + .then(count => { + this.setState(Object.assign(this.state.user, { entries: count})) + }) + + } + 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: route}); + } + + render() { + const { isSignedIn, imageUrl, route, box } = this.state; + return ( +