├── public ├── favicon.ico ├── manifest.json └── index.html ├── src ├── components │ ├── Logo │ │ ├── Logo.css │ │ ├── Background-of-success-ideas │ │ │ ├── OIUH890.jpg │ │ │ ├── OIUH891.eps │ │ │ ├── License premium.txt │ │ │ └── License free.txt │ │ └── Logo.js │ ├── FaceRecognition │ │ ├── FaceRecognition.css │ │ └── FaceRecognition.js │ ├── Rank │ │ └── Rank.js │ ├── ImageLinkForm │ │ ├── ImageLinkForm.css │ │ └── ImageLinkForm.js │ ├── Navigation │ │ └── Navigation.js │ ├── Signin │ │ └── Signin.js │ └── Register │ │ └── Register.js ├── index.css ├── App.css ├── App.test.js ├── index.js ├── App.js └── registerServiceWorker.js ├── README.md ├── .gitignore └── package.json /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlr/face-recognition-brain/master/public/favicon.ico -------------------------------------------------------------------------------- /src/components/Logo/Logo.css: -------------------------------------------------------------------------------- 1 | .Tilt { 2 | background: linear-gradient(89deg, #ff5edf 0%, #04c8de 100%); /*w3c*/ 3 | 4 | } -------------------------------------------------------------------------------- /src/components/Logo/Background-of-success-ideas/OIUH890.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlr/face-recognition-brain/master/src/components/Logo/Background-of-success-ideas/OIUH890.jpg -------------------------------------------------------------------------------- /src/components/Logo/Background-of-success-ideas/OIUH891.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlr/face-recognition-brain/master/src/components/Logo/Background-of-success-ideas/OIUH891.eps -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: "Courier New", Courier, monospace; 5 | background: linear-gradient(89deg, #ff5edf 0%, #04c8de 100%); /*w3c*/ 6 | } 7 | 8 | 9 | button { 10 | cursor: pointer; 11 | } -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .center { 6 | display: flex; 7 | justify-content: center; 8 | } 9 | 10 | .particles { 11 | position: fixed; 12 | top: 0; 13 | right: 0; 14 | bottom: 0; 15 | left: 0; 16 | z-index: -1; 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartBrain - v1 2 | Final project for Udemy course 3 | 4 | 1. Clone this repo 5 | 2. Run `npm install` 6 | 3. Run `npm start` 7 | 4. You must add your own API key in the `src/App.js` file to connect to Clarifai. 8 | 9 | You can grab Clarifai API key [here](https://www.clarifai.com/) -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './registerServiceWorker'; 6 | import 'tachyons'; 7 | 8 | ReactDOM.render(, document.getElementById('root')); 9 | registerServiceWorker(); 10 | -------------------------------------------------------------------------------- /src/components/FaceRecognition/FaceRecognition.css: -------------------------------------------------------------------------------- 1 | .bounding-box { 2 | position: absolute; 3 | box-shadow: 0 0 0 3px #149df2 inset; 4 | display: -ms-flexbox; 5 | display: flex; 6 | -ms-flex-wrap: wrap; 7 | flex-wrap: wrap; 8 | -ms-flex-pack: center; 9 | justify-content: center; 10 | cursor: pointer; 11 | } -------------------------------------------------------------------------------- /src/components/Rank/Rank.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Rank = () =>{ 4 | return ( 5 |
6 |
7 | {'James, your current rank is ...'} 8 |
9 |
10 | {'#5'} 11 |
12 |
13 | ); 14 | }; 15 | 16 | 17 | export default Rank; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "facerecognitionbrain", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "clarifai": "^2.6.0", 7 | "react": "^16.2.0", 8 | "react-dom": "^16.2.0", 9 | "react-particles-js": "^2.1.1", 10 | "react-scripts": "1.1.1", 11 | "react-tilt": "^0.1.4", 12 | "tachyons": "^4.9.1" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test --env=jsdom", 18 | "eject": "react-scripts eject" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/components/FaceRecognition/FaceRecognition.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './FaceRecognition.css'; 3 | 4 | const FaceRecognition = ({imageUrl, box}) =>{ 5 | console.log('FaceRecognition', box); 6 | return ( 7 |
8 |
9 | pic 10 |
19 |
20 |
21 |
22 | ); 23 | }; 24 | 25 | 26 | export default FaceRecognition; -------------------------------------------------------------------------------- /src/components/ImageLinkForm/ImageLinkForm.css: -------------------------------------------------------------------------------- 1 | .form { 2 | width: 700px; 3 | background: 4 | radial-gradient(circle farthest-side at 0% 50%,#fb1 23.5%,rgba(240,166,17,0) 0)21px 30px, 5 | radial-gradient(circle farthest-side at 0% 50%,#B71 24%,rgba(240,166,17,0) 0)19px 30px, 6 | linear-gradient(#fb1 14%,rgba(240,166,17,0) 0, rgba(240,166,17,0) 85%,#fb1 0)0 0, 7 | linear-gradient(150deg,#fb1 24%,#B71 0,#B71 26%,rgba(240,166,17,0) 0,rgba(240,166,17,0) 74%,#B71 0,#B71 76%,#fb1 0)0 0, 8 | linear-gradient(30deg,#fb1 24%,#B71 0,#B71 26%,rgba(240,166,17,0) 0,rgba(240,166,17,0) 74%,#B71 0,#B71 76%,#fb1 0)0 0, 9 | linear-gradient(90deg,#B71 2%,#fb1 0,#fb1 98%,#B71 0%)0 0 #fb1; 10 | background-size:40px 60px; 11 | } -------------------------------------------------------------------------------- /src/components/Logo/Logo.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Tilt from 'react-tilt' 3 | import 'tachyons'; 4 | import './Logo.css'; 5 | import brain from './Background-of-success-ideas/OIUH890.jpg'; 6 | 7 | const Logo = () =>{ 8 | // console.log(brain); 9 | return ( 10 |
11 | 12 |
13 | Designed by Freepik 14 | {/*Designed by Freepik*/} 15 |
16 |
17 |
18 | ); 19 | }; 20 | 21 | 22 | export default Logo; -------------------------------------------------------------------------------- /src/components/ImageLinkForm/ImageLinkForm.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './ImageLinkForm.css' 3 | 4 | const ImageLinkForm = ({onInputChange, onButtonSubmit}) =>{ 5 | return ( 6 |
7 |

8 | {'This Magic brain will detect faces in your pictures.'} 9 |

10 |
11 |
12 | 13 | 17 |
18 |
19 |
20 | ); 21 | }; 22 | 23 | 24 | export default ImageLinkForm; -------------------------------------------------------------------------------- /src/components/Navigation/Navigation.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Navigation = ({onRouteChange, isSignedIn}) =>{ 4 | 5 | return isSignedIn ? 6 | ( 7 | 13 | ) 14 | : ( 15 | 25 | ); 26 | }; 27 | 28 | 29 | export default Navigation; -------------------------------------------------------------------------------- /src/components/Logo/Background-of-success-ideas/License premium.txt: -------------------------------------------------------------------------------- 1 | IMPORTANT NOTICE: This license only applies if you downloaded this content as 2 | a subscribed (or "premium") user. If you are an unsubscribed user (or "free" 3 | user) you are bound to the license terms described in the accompanying file 4 | "License free.txt". 5 | 6 | --------------------- 7 | 8 | You can download from your profile in Freepik a personalized license stating 9 | your right to use this content as a "premium" user: 10 | 11 | https://profile.freepik.com/my_downloads 12 | 13 | You are free to use this image: 14 | 15 | - For both personal and commercial projects and to modify it. 16 | - In a website or presentation template or application or as part of your design. 17 | 18 | You are not allowed to: 19 | 20 | - Sub-license, resell or rent it. 21 | - Include it in any online or offline archive or database. 22 | 23 | The full terms of the license are described in sections 7 and 8 of the Freepik 24 | terms of use, available online in the following link: 25 | 26 | http://www.freepik.com/terms_of_use 27 | 28 | The terms described in the above link have precedence over the terms described 29 | in the present document. In case of disagreement, the Freepik Terms of Use 30 | will prevail. 31 | -------------------------------------------------------------------------------- /src/components/Signin/Signin.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const SignIn = ({onRouteChange}) =>{ 4 | return ( 5 |
6 |
7 |
8 |
9 | Sign In 10 |
11 | 12 | 13 |
14 |
15 | 16 | 17 |
18 |
19 |
20 | onRouteChange('home')} 22 | className="b ph3 pv2 input-reset ba b--black bg-transparent grow pointer f6 dib" 23 | type="submit" 24 | value="Sign in" 25 | /> 26 |
27 |
28 |

onRouteChange('register')} className="f6 link dim black db pointer">Register

29 |
30 |
31 |
32 |
33 | ); 34 | }; 35 | 36 | 37 | export default SignIn; -------------------------------------------------------------------------------- /src/components/Register/Register.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Register = ({onRouteChange}) =>{ 4 | return ( 5 |
6 |
7 |
8 |
9 | Register 10 |
11 | 12 | 13 |
14 |
15 | 16 | 17 |
18 |
19 | 20 | 21 |
22 |
23 |
24 | onRouteChange('signin')} 26 | className="b ph3 pv2 input-reset ba b--black bg-transparent grow pointer f6 dib" 27 | type="submit" 28 | value="Register" 29 | /> 30 |
31 |
32 |
33 |
34 | ); 35 | }; 36 | 37 | 38 | export default Register; -------------------------------------------------------------------------------- /src/components/Logo/Background-of-success-ideas/License free.txt: -------------------------------------------------------------------------------- 1 | IMPORTANT NOTICE: This license only applies if you downloaded this content as 2 | an unsubscribed user. If you are a premium user (ie, you pay a subscription) 3 | you are bound to the license terms described in the accompanying file 4 | "License premium.txt". 5 | 6 | --------------------- 7 | 8 | You must attribute the image to its author: 9 | 10 | In order to use a content or a part of it, you must attribute it to Macrovector / Freepik, 11 | so we will be able to continue creating new graphic resources every day. 12 | 13 | 14 | How to attribute it? 15 | 16 | For websites: 17 | 18 | Please, copy this code on your website to accredit the author: 19 | Designed by Macrovector / Freepik 20 | 21 | For printing: 22 | 23 | Paste this text on the final work so the authorship is known. 24 | - For example, in the acknowledgements chapter of a book: 25 | "Designed by Macrovector / Freepik" 26 | 27 | 28 | You are free to use this image: 29 | 30 | - For both personal and commercial projects and to modify it. 31 | - In a website or presentation template or application or as part of your design. 32 | 33 | You are not allowed to: 34 | 35 | - Sub-license, resell or rent it. 36 | - Include it in any online or offline archive or database. 37 | 38 | The full terms of the license are described in section 7 of the Freepik 39 | terms of use, available online in the following link: 40 | 41 | http://www.freepik.com/terms_of_use 42 | 43 | The terms described in the above link have precedence over the terms described 44 | in the present document. In case of disagreement, the Freepik Terms of Use 45 | will prevail. 46 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import './App.css'; 3 | import Particles from 'react-particles-js'; 4 | 5 | import Navigation from './components/Navigation/Navigation'; 6 | import Logo from './components/Logo/Logo'; 7 | import ImageLinkForm from './components/ImageLinkForm/ImageLinkForm'; 8 | import Rank from './components/Rank/Rank'; 9 | import FaceRecognition from './components/FaceRecognition/FaceRecognition'; 10 | import SignIn from './components/SignIn/SignIn'; 11 | import Register from './components/Register/Register'; 12 | 13 | // Require the client 14 | 15 | import Clarifai from 'clarifai'; 16 | 17 | // initialize with your api key. This will also work in your browser via http://browserify.org/ 18 | 19 | const app = new Clarifai.App({ 20 | apiKey: 'a6ce27301ad64150926093861f9c9fe7' 21 | }); 22 | 23 | 24 | const particlesParams = { 25 | particles:{ 26 | number:{ 27 | value: 30, 28 | density:{ 29 | enable: true, 30 | value_area: 600 31 | } 32 | } 33 | } 34 | }; 35 | 36 | class App extends Component { 37 | constructor(){ 38 | super(); 39 | this.state = { 40 | input:'', 41 | imageUrl: '', 42 | box: {}, 43 | route: 'signin', 44 | isSignedIn: false 45 | } 46 | } 47 | 48 | onRouteChange = (route) => { 49 | if( route === 'signout' ){ 50 | this.setState({isSignedIn: false}); 51 | } else if( route === 'home' ){ 52 | this.setState({isSignedIn: true}); 53 | } 54 | this.setState({route: route}) 55 | } 56 | 57 | calculateFaceLocation = (response) => { 58 | const clarifaiFaces = response.outputs[0].data.regions[0].region_info.bounding_box; 59 | console.log('calculateFaceLocation', clarifaiFaces); 60 | const image = document.getElementById('inputImage'); 61 | const width = Number(image.width); 62 | const height = Number(image.height); 63 | 64 | console.log('image', image); 65 | 66 | console.log('left_col', clarifaiFaces.left_col * width); 67 | const boxLocation = { 68 | leftCol : clarifaiFaces.left_col * width, 69 | topRow : clarifaiFaces.top_row * height, 70 | rightCol : width - clarifaiFaces.right_col * width, 71 | bottomRow : height - clarifaiFaces.bottom_row * height 72 | }; 73 | 74 | console.log('boxLocation', boxLocation); 75 | return boxLocation; 76 | } 77 | 78 | displayFaceBox = (box) => { 79 | // console.log('displayFaceBox', box); 80 | this.setState({box: box}) 81 | } 82 | 83 | onInputChange = (event) => { 84 | // console.log(event.target.value); 85 | this.setState({input: event.target.value}); 86 | } 87 | 88 | onButtonSubmit = () => { 89 | this.setState({imageUrl:this.state.input}); 90 | // console.log('button', this.state.input); 91 | app.models.predict( 92 | Clarifai.FACE_DETECT_MODEL, 93 | this.state.input) 94 | .then( response => { 95 | // do something with response 96 | // console.log(response); 97 | this.displayFaceBox(this.calculateFaceLocation(response)); 98 | }) 99 | .catch( err => { 100 | // there was an error 101 | console.log(err); 102 | }); 103 | }; 104 | 105 | render() { 106 | return ( 107 |
108 | 109 | 110 | { this.state.route === 'home' 111 | ?
112 | 113 |
114 | : ( this.state.route === 'signin' 115 | ? 116 | : 117 | ) 118 | } 119 | 120 | 124 | 128 | 129 |
130 | ); 131 | } 132 | } 133 | 134 | export default App; 135 | -------------------------------------------------------------------------------- /src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | 39 | // Add some additional logging to localhost, pointing developers to the 40 | // service worker/PWA documentation. 41 | navigator.serviceWorker.ready.then(() => { 42 | console.log( 43 | 'This web app is being served cache-first by a service ' + 44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ' 45 | ); 46 | }); 47 | } else { 48 | // Is not local host. Just register service worker 49 | registerValidSW(swUrl); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | function registerValidSW(swUrl) { 56 | navigator.serviceWorker 57 | .register(swUrl) 58 | .then(registration => { 59 | registration.onupdatefound = () => { 60 | const installingWorker = registration.installing; 61 | installingWorker.onstatechange = () => { 62 | if (installingWorker.state === 'installed') { 63 | if (navigator.serviceWorker.controller) { 64 | // At this point, the old content will have been purged and 65 | // the fresh content will have been added to the cache. 66 | // It's the perfect time to display a "New content is 67 | // available; please refresh." message in your web app. 68 | console.log('New content is available; please refresh.'); 69 | } else { 70 | // At this point, everything has been precached. 71 | // It's the perfect time to display a 72 | // "Content is cached for offline use." message. 73 | console.log('Content is cached for offline use.'); 74 | } 75 | } 76 | }; 77 | }; 78 | }) 79 | .catch(error => { 80 | console.error('Error during service worker registration:', error); 81 | }); 82 | } 83 | 84 | function checkValidServiceWorker(swUrl) { 85 | // Check if the service worker can be found. If it can't reload the page. 86 | fetch(swUrl) 87 | .then(response => { 88 | // Ensure service worker exists, and that we really are getting a JS file. 89 | if ( 90 | response.status === 404 || 91 | response.headers.get('content-type').indexOf('javascript') === -1 92 | ) { 93 | // No service worker found. Probably a different app. Reload the page. 94 | navigator.serviceWorker.ready.then(registration => { 95 | registration.unregister().then(() => { 96 | window.location.reload(); 97 | }); 98 | }); 99 | } else { 100 | // Service worker found. Proceed as normal. 101 | registerValidSW(swUrl); 102 | } 103 | }) 104 | .catch(() => { 105 | console.log( 106 | 'No internet connection found. App is running in offline mode.' 107 | ); 108 | }); 109 | } 110 | 111 | export function unregister() { 112 | if ('serviceWorker' in navigator) { 113 | navigator.serviceWorker.ready.then(registration => { 114 | registration.unregister(); 115 | }); 116 | } 117 | } 118 | --------------------------------------------------------------------------------