Skip to content

Code migration to django3 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Live Face Detection using Opencv with Django or Tornado Framework
======================================

It'll capture image from your webcam and detect your face. It's also supported real time face detect from webcam video.

Installation
=============

* Please make sure you already installed Python3 and pip in your system, then Clone this repository ::

git clone https://github.com/talhaanwarch/facedetect.git

* Now install requirements of python libraries ::

pip install -r requirements.txt

* Now we need to run tornado server for create websocket ::

python websocket.py
#It may be show popup for allow or not firewall , So click on allow to run websocket

* Now run Django project using below command ::

python manage.py runserver

* Now you can access project ::

http://127.0.0.1:8000/image/ # detect face from image

http://127.0.0.1:8000/video/ # detect face from live webcam

* **Note**
If you are on a windows machine, you can open two terminal one for websocket and the other for django server.
On linux server you may move tornado server to background and then lanuch django server.


34 changes: 0 additions & 34 deletions README.rst

This file was deleted.

22 changes: 0 additions & 22 deletions liveface/urls.py

This file was deleted.

6 changes: 0 additions & 6 deletions main/admin.py

This file was deleted.

8 changes: 0 additions & 8 deletions main/apps.py

This file was deleted.

49 changes: 0 additions & 49 deletions main/detect.py

This file was deleted.

6 changes: 0 additions & 6 deletions main/models.py

This file was deleted.

8 changes: 0 additions & 8 deletions main/urls.py

This file was deleted.

File renamed without changes.
16 changes: 16 additions & 0 deletions main_app/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for main_app project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main_app.settings')

application = get_asgi_application()
48 changes: 26 additions & 22 deletions liveface/settings.py → main_app/settings.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
"""
Django settings for liveface project.
Django settings for main_app project.

Generated by 'django-admin startproject' using Django 1.11.10.
Generated by 'django-admin startproject' using Django 3.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=70wzndlj)cfz#hs26s@%%_b_*i3(n5__&y5@#v#x7#1l&9&9%'
SECRET_KEY = '#do=m1@^a!br78ql!^$**3k=h@y7j-+5$&f#zo(4!o(yzd+nmt'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -37,7 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main.apps.MainConfig',
'sub_app'
]

MIDDLEWARE = [
Expand All @@ -50,12 +50,12 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'liveface.urls'
ROOT_URLCONF = 'main_app.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -68,16 +68,22 @@
},
]

WSGI_APPLICATION = 'liveface.wsgi.application'
WSGI_APPLICATION = 'main_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -96,7 +102,7 @@


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -110,12 +116,10 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'sub_app','static')

MEDIA_ROOT = os.path.join(BASE_DIR, 'sub_app','media')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
27 changes: 27 additions & 0 deletions main_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""main_app URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include,re_path
from sub_app import views
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve

urlpatterns = [
path('admin/', admin.site.urls),
path('',include('sub_app.urls')),
re_path(r'^media/(?P<path>.*)$', serve, kwargs={'document_root': settings.MEDIA_ROOT})
]
6 changes: 3 additions & 3 deletions liveface/wsgi.py → main_app/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""
WSGI config for liveface project.
WSGI config for main_app project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "liveface.settings")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main_app.settings')

application = get_wsgi_application()
30 changes: 15 additions & 15 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "liveface.settings")


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main_app.settings')
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Loading