├── .DS_Store ├── .gitignore ├── core ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── settings.cpython-39.pyc │ ├── urls.cpython-39.pyc │ ├── utils.cpython-39.pyc │ ├── views.cpython-39.pyc │ └── wsgi.cpython-39.pyc ├── asgi.py ├── settings.py ├── urls.py ├── utils.py ├── views.py └── wsgi.py ├── logs ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-39.pyc │ └── models.cpython-39.pyc ├── admin.py ├── apps.py ├── models.py ├── tests.py └── views.py ├── manage.py ├── profiles ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-39.pyc │ ├── models.cpython-39.pyc │ └── signals.cpython-39.pyc ├── admin.py ├── apps.py ├── models.py ├── signals.py ├── tests.py └── views.py ├── static ├── login.js └── style.css └── templates ├── base.html ├── login.html └── main.html /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | media 2 | db.sqlite3 3 | **/migrations/ -------------------------------------------------------------------------------- /core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__init__.py -------------------------------------------------------------------------------- /core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__pycache__/utils.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.1.7. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-g4_@%m_65uy=flaq9m$apz2%ff_d(4b!)0t*(d$dcrylptwdw5' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 41 | 'logs', 42 | 'profiles', 43 | ] 44 | 45 | LOGIN_URL = 'login/' 46 | 47 | MIDDLEWARE = [ 48 | 'django.middleware.security.SecurityMiddleware', 49 | 'django.contrib.sessions.middleware.SessionMiddleware', 50 | 'django.middleware.common.CommonMiddleware', 51 | 'django.middleware.csrf.CsrfViewMiddleware', 52 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 53 | 'django.contrib.messages.middleware.MessageMiddleware', 54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 55 | ] 56 | 57 | ROOT_URLCONF = 'core.urls' 58 | 59 | TEMPLATES = [ 60 | { 61 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 62 | 'DIRS': [ BASE_DIR / 'templates' ], 63 | 'APP_DIRS': True, 64 | 'OPTIONS': { 65 | 'context_processors': [ 66 | 'django.template.context_processors.debug', 67 | 'django.template.context_processors.request', 68 | 'django.contrib.auth.context_processors.auth', 69 | 'django.contrib.messages.context_processors.messages', 70 | ], 71 | }, 72 | }, 73 | ] 74 | 75 | WSGI_APPLICATION = 'core.wsgi.application' 76 | 77 | 78 | # Database 79 | # https://docs.djangoproject.com/en/4.1/ref/settings/#databases 80 | 81 | DATABASES = { 82 | 'default': { 83 | 'ENGINE': 'django.db.backends.sqlite3', 84 | 'NAME': BASE_DIR / 'db.sqlite3', 85 | } 86 | } 87 | 88 | 89 | # Password validation 90 | # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators 91 | 92 | AUTH_PASSWORD_VALIDATORS = [ 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 101 | }, 102 | { 103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 104 | }, 105 | ] 106 | 107 | 108 | # Internationalization 109 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ 110 | 111 | LANGUAGE_CODE = 'en-us' 112 | 113 | TIME_ZONE = 'UTC' 114 | 115 | USE_I18N = True 116 | 117 | USE_TZ = True 118 | 119 | 120 | # Static files (CSS, JavaScript, Images) 121 | # https://docs.djangoproject.com/en/4.1/howto/static-files/ 122 | 123 | STATIC_URL = 'static/' 124 | MEDIA_URL = 'media/' 125 | 126 | STATICFILES_DIRS = [BASE_DIR / 'static'] 127 | MEDIA_ROOT = BASE_DIR / 'media' 128 | 129 | # Default primary key field type 130 | # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field 131 | 132 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 133 | -------------------------------------------------------------------------------- /core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | from django.conf import settings 19 | from django.conf.urls.static import static 20 | 21 | from .views import ( 22 | login_view, 23 | logout_view, 24 | home_view, 25 | find_user_view 26 | ) 27 | 28 | urlpatterns = [ 29 | path('admin/', admin.site.urls), 30 | path('', home_view, name='home'), 31 | path('login/', login_view, name='login'), 32 | path('logout/', logout_view, name='logout'), 33 | path('classify/', find_user_view, name='classify'), 34 | ] 35 | 36 | urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 37 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 38 | -------------------------------------------------------------------------------- /core/utils.py: -------------------------------------------------------------------------------- 1 | import face_recognition as fr 2 | import numpy as np 3 | from profiles.models import Profile 4 | 5 | 6 | def is_ajax(request): 7 | return request.headers.get('x-requested-with') == 'XMLHttpRequest' 8 | 9 | 10 | def get_encoded_faces(): 11 | """ 12 | This function loads all user 13 | profile images and encodes their faces 14 | """ 15 | # Retrieve all user profiles from the database 16 | qs = Profile.objects.all() 17 | 18 | # Create a dictionary to hold the encoded face for each user 19 | encoded = {} 20 | 21 | for p in qs: 22 | # Initialize the encoding variable with None 23 | encoding = None 24 | 25 | # Load the user's profile image 26 | face = fr.load_image_file(p.photo.path) 27 | 28 | # Encode the face (if detected) 29 | face_encodings = fr.face_encodings(face) 30 | if len(face_encodings) > 0: 31 | encoding = face_encodings[0] 32 | else: 33 | print("No face found in the image") 34 | 35 | # Add the user's encoded face to the dictionary if encoding is not None 36 | if encoding is not None: 37 | encoded[p.user.username] = encoding 38 | 39 | # Return the dictionary of encoded faces 40 | return encoded 41 | 42 | 43 | def classify_face(img): 44 | """ 45 | This function takes an image as input and returns the name of the face it contains 46 | """ 47 | # Load all the known faces and their encodings 48 | faces = get_encoded_faces() 49 | faces_encoded = list(faces.values()) 50 | known_face_names = list(faces.keys()) 51 | 52 | # Load the input image 53 | img = fr.load_image_file(img) 54 | 55 | try: 56 | # Find the locations of all faces in the input image 57 | face_locations = fr.face_locations(img) 58 | 59 | # Encode the faces in the input image 60 | unknown_face_encodings = fr.face_encodings(img, face_locations) 61 | 62 | # Identify the faces in the input image 63 | face_names = [] 64 | for face_encoding in unknown_face_encodings: 65 | # Compare the encoding of the current face to the encodings of all known faces 66 | matches = fr.compare_faces(faces_encoded, face_encoding) 67 | 68 | # Find the known face with the closest encoding to the current face 69 | face_distances = fr.face_distance(faces_encoded, face_encoding) 70 | best_match_index = np.argmin(face_distances) 71 | 72 | # If the closest known face is a match for the current face, label the face with the known name 73 | if matches[best_match_index]: 74 | name = known_face_names[best_match_index] 75 | else: 76 | name = "Unknown" 77 | 78 | face_names.append(name) 79 | 80 | # Return the name of the first face in the input image 81 | return face_names[0] 82 | except: 83 | # If no faces are found in the input image or an error occurs, return False 84 | return False -------------------------------------------------------------------------------- /core/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.contrib.auth import logout, login 3 | from django.contrib.auth.decorators import login_required 4 | from django.http import JsonResponse 5 | from .utils import is_ajax, classify_face 6 | import base64 7 | from logs.models import Log 8 | from django.core.files.base import ContentFile 9 | from django.contrib.auth.models import User 10 | from profiles.models import Profile 11 | 12 | def login_view(request): 13 | return render(request, 'login.html', {}) 14 | 15 | def logout_view(request): 16 | logout(request) 17 | return redirect('login') 18 | 19 | @login_required 20 | def home_view(request): 21 | return render(request, 'main.html', {}) 22 | 23 | def find_user_view(request): 24 | if is_ajax(request): 25 | photo = request.POST.get('photo') 26 | _, str_img = photo.split(';base64') 27 | 28 | # print(photo) 29 | decoded_file = base64.b64decode(str_img) 30 | print(decoded_file) 31 | 32 | x = Log() 33 | x.photo.save('upload.png', ContentFile(decoded_file)) 34 | x.save() 35 | 36 | res = classify_face(x.photo.path) 37 | if res: 38 | user_exists = User.objects.filter(username=res).exists() 39 | if user_exists: 40 | user = User.objects.get(username=res) 41 | profile = Profile.objects.get(user=user) 42 | x.profile = profile 43 | x.save() 44 | 45 | login(request, user) 46 | return JsonResponse({'success': True}) 47 | return JsonResponse({'success': False}) 48 | -------------------------------------------------------------------------------- /core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /logs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/logs/__init__.py -------------------------------------------------------------------------------- /logs/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/logs/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /logs/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/logs/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /logs/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/logs/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /logs/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/logs/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /logs/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Log 3 | # Register your models here. 4 | 5 | admin.site.register(Log) -------------------------------------------------------------------------------- /logs/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class LogsConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'logs' 7 | -------------------------------------------------------------------------------- /logs/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from profiles.models import Profile 3 | 4 | # Create your models here. 5 | 6 | class Log(models.Model): 7 | profile = models.ForeignKey(Profile, on_delete=models.CASCADE, blank=True, null=True) 8 | photo = models.ImageField(upload_to='logs') 9 | is_correct = models.BooleanField(default=False) 10 | created = models.DateTimeField(auto_now_add=True) 11 | 12 | def __str__(self): 13 | return str(self.id) -------------------------------------------------------------------------------- /logs/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /logs/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /profiles/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = 'profiles.apps.ProfilesConfig' -------------------------------------------------------------------------------- /profiles/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/profiles/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /profiles/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/profiles/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /profiles/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/profiles/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /profiles/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/profiles/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /profiles/__pycache__/signals.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyplane/django-faceid/06d8b554e5b86ea72fa291a0ab20f4216f5d8702/profiles/__pycache__/signals.cpython-39.pyc -------------------------------------------------------------------------------- /profiles/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | # Register your models here. 4 | 5 | admin.site.register(Profile) -------------------------------------------------------------------------------- /profiles/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class ProfilesConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'profiles' 7 | 8 | def ready(self): 9 | import profiles.signals 10 | -------------------------------------------------------------------------------- /profiles/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | # Create your models here. 4 | 5 | class Profile(models.Model): 6 | user = models.OneToOneField(User, on_delete=models.CASCADE) 7 | photo = models.ImageField(blank=True, upload_to='photos') 8 | bio = models.TextField() 9 | created = models.DateTimeField(auto_now_add=True) 10 | 11 | def __str__(self): 12 | return f"profile of {self.user.username}" -------------------------------------------------------------------------------- /profiles/signals.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.models import User 2 | from .models import Profile 3 | from django.db.models.signals import post_save 4 | from django.dispatch import receiver 5 | 6 | @receiver(post_save, sender=User) 7 | def create_profile(sender, instance, created, **kwargs): 8 | if created: 9 | Profile.objects.create(user=instance) -------------------------------------------------------------------------------- /profiles/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /profiles/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /static/login.js: -------------------------------------------------------------------------------- 1 | console.log('hello world') 2 | 3 | const getCookie = (name) => { 4 | let cookieValue = null; 5 | if (document.cookie && document.cookie !== '') { 6 | const cookies = document.cookie.split(';'); 7 | for (let i = 0; i < cookies.length; i++) { 8 | const cookie = cookies[i].trim(); 9 | if (cookie.substring(0, name.length + 1) === (name + '=')) { 10 | cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 11 | break; 12 | } 13 | } 14 | } 15 | return cookieValue; 16 | } 17 | 18 | const csrftoken = getCookie('csrftoken'); 19 | 20 | const video = document.getElementById('video-element') 21 | const image = document.getElementById('img-element') 22 | const captureBtn = document.getElementById('capture-btn') 23 | const reloadBtn = document.getElementById('reload-btn') 24 | 25 | reloadBtn.addEventListener('click', () => { 26 | window.location.reload() 27 | }) 28 | 29 | if (navigator.mediaDevices.getUserMedia) { 30 | navigator.mediaDevices.getUserMedia({video: true}) 31 | .then((stream) => { 32 | video.srcObject = stream 33 | const {height, width} = stream.getTracks()[0].getSettings() 34 | 35 | captureBtn.addEventListener('click', e=> { 36 | e.preventDefault() 37 | captureBtn.classList.add('not-visible') 38 | const track = stream.getVideoTracks()[0] 39 | const imageCapture = new ImageCapture(track) 40 | console.log(imageCapture) 41 | 42 | imageCapture.takePhoto().then(blob => { 43 | console.log("took photo:", blob) 44 | const img = new Image(width, height) 45 | img.src = URL.createObjectURL(blob) 46 | image.append(img) 47 | 48 | video.classList.add('not-visible') 49 | 50 | const reader = new FileReader() 51 | 52 | reader.readAsDataURL(blob) 53 | reader.onloadend = () => { 54 | const base64data = reader.result 55 | console.log(base64data) 56 | 57 | const fd = new FormData() 58 | fd.append('csrfmiddlewaretoken', csrftoken) 59 | fd.append('photo', base64data) 60 | 61 | $.ajax({ 62 | type: 'POST', 63 | url: '/classify/', 64 | enctype: 'multipart/form-data', 65 | data: fd, 66 | processData: false, 67 | contentType: false, 68 | success: (resp) => { 69 | console.log(resp) 70 | window.location.href = window.location.origin 71 | }, 72 | error: (err) => { 73 | console.log(err) 74 | } 75 | }) 76 | } 77 | }).catch(error => { 78 | console.log('takePhoto() error: ', error); 79 | }); 80 | }); 81 | }) 82 | .catch(error => { 83 | console.log("Something went wrong!", error); 84 | }); 85 | } 86 | -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | .not-visible { 2 | display: none; 3 | } -------------------------------------------------------------------------------- /templates/base.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | {% block scripts %}{% endblock scripts %} 18 | 19 | face id 20 | 21 | 22 |
23 | {% block content %} 24 | {% endblock content %} 25 | 26 | 27 | -------------------------------------------------------------------------------- /templates/login.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | {% load static %} 3 | 4 | {% block scripts %} 5 | 6 | {% endblock scripts %} 7 | 8 | {% block content %} 9 |
10 | 11 |
12 | 13 |
14 | 15 |
16 | 17 | 18 |
19 | {% endblock content %} -------------------------------------------------------------------------------- /templates/main.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block content %} 4 | Logged in as : {{request.user.username}} 5 |

6 | logout 7 | 8 | {% endblock content %} --------------------------------------------------------------------------------