Code Monkey home page Code Monkey logo

never-blink's Introduction

Never-Blink

1. πŸŽ‰ Introduction

πŸ™Œ Upvote for my product hunt!

Randomly connect to a player around the world and challenge him/her. Remember not to blink!

For full version of demo video, click here.

2. πŸ“œ Implementation

1. Project structure

.
β”œβ”€β”€ backend
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ detect.py
β”‚   └── shape_predictor_68_face_landmarks.dat (detect model)
β”œβ”€β”€ package.json
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ server.py
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ app.jsx
β”‚   β”œβ”€β”€ index.js
β”‚   β”œβ”€β”€ play.jsx
β”‚   └── start.jsx
β”œβ”€β”€ static
β”‚   └── bundle.js
β”œβ”€β”€ templates
β”‚   └── index.html
└── webpack.config.js

We use react as our frontend framework, and use peerjs to communicate between clients. At backend, we use flask to host the server. For connection between clients and server, we use socketio to implement real-time data transfer.

2. Game State

We use the notion of Finite State Machine to design our game state. The circle is the state. The text in the top of each box is the event causing state transition, and the text in the bottom of each box is the action taken when event occurs. The logic looks quite simple here, but it is not that easy to implement. For more detail you can check play.jsx or server.py.

3. πŸ’» Development

I spent lots of time formatting my code and writing comments to make it as readable as possible. Hope you enjoy 😊

  1. Clone this repo.
git clone [email protected]:ByronHsu/Never-Blink.git
  1. Install the packages
# Frontend
npm install
# Backend
pip install -r requirements.txt
  1. Build and Run
# Build frontend files
npm run build
# Run server
npm run start

Every time you changed your code, you should run the above command again. We do not support hot module replacement now.

  1. Start and Enjoy

Goto https://0.0.0.0:3000

0.0.0.0:3000 does not work, remember to add https.

4. 🚧 Problem

  1. Because the detector is too slow and weak, we can not endure too many clients. Therefore, we do not deploy it to a public server now. We plan to train a robust and fast model in the future.
  2. When restarting, the old media connection listener will be called again. So we remove restart temporarily.

5. πŸ“– Reference

  1. Environment setup: https://github.com/rwieruch/minimal-react-webpack-babel-setup
  2. Simple P2P WebRTC package: https://github.com/peers/peerjs
  3. Socket-io: https://socket.io/docs/client-api/
  4. Flask-socketio: https://flask-socketio.readthedocs.io/en/latest/
  5. Blink detector: https://github.com/dilawar/eye-blink-detector
  6. Material UI: https://material-ui.com/

6. πŸ—žοΈ License

MIT Licensed

never-blink's People

Contributors

0xflotus avatar andyh0913 avatar byronhsu avatar edjw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

never-blink's Issues

npm run start fails

$ npm run start

> @ start /Users/dennis/Documents/Developer/Repositories/Never-Blink
> python3 server.py

WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Serving Flask app "server" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "server.py", line 226, in <module>
    keyfile=os.path.join('backend', 'server.key'), certfile=os.path.join('backend', 'server.crt'))
  File "/usr/local/lib/python3.7/site-packages/flask_socketio/__init__.py", line 524, in run
    use_reloader=use_reloader, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
TypeError: run_simple() got an unexpected keyword argument 'keyfile'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `python3 server.py`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/dschuessler/.npm/_logs/2019-06-13T20_55_26_642Z-debug.log

Python 3.7.3
macOS 10.14.5

Use tf.js for no load on backend

hey Byron a thought, wouldn't it be server-free if we use tf.js, there is https://github.com/justadudewhohacks/face-api.js to get started (and if you want to go the facial landmark way)

To arrive at the eye part, a simpler way is posenet, https://github.com/tensorflow/tfjs-models/tree/master/posenet and feed that to a simple CNN which can classify if eye open or closed, https://towardsdatascience.com/real-time-face-liveness-detection-with-python-keras-and-opencv-c35dc70dafd3

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.