forked from jatolentino/AI-Facial-recognition
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 80b8847
Showing
10 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.contrib import admin | ||
|
||
from .models import User, Membership, Payment, File, TrackedRequest | ||
|
||
admin.site.register(User) | ||
admin.site.register(Membership) | ||
admin.site.register(Payment) | ||
admin.site.register(File) | ||
admin.site.register(TrackedRequest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CoreConfig(AppConfig): | ||
name = 'core' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import numpy as np | ||
import urllib | ||
import json | ||
import cv2 | ||
import os | ||
from django.conf import settings | ||
|
||
execution_path = settings.MEDIA_ROOT | ||
face_detector = os.path.join( | ||
settings.BASE_DIR, "haarcascade_frontalface_default.xml") | ||
|
||
|
||
def detect_faces(image_path=None, url=None): | ||
default = {"safely_executed": False} | ||
if image_path: | ||
true_image_path = os.path.join( | ||
execution_path, image_path.split('/media/')[1]) | ||
image_to_read = read_image(path=true_image_path) | ||
elif url: | ||
image_to_read = read_image(url=url) | ||
else: | ||
default["error_value"] = "There is no image provided" | ||
return default | ||
image_to_read = cv2.cvtColor(image_to_read, cv2.COLOR_BGR2GRAY) | ||
detector_value = cv2.CascadeClassifier(face_detector) | ||
values = detector_value.detectMultiScale(image_to_read, | ||
scaleFactor=1.1, | ||
minNeighbors=5, | ||
minSize=(30, 30), | ||
flags=cv2.CASCADE_SCALE_IMAGE) | ||
values = [(int(a), int(b), int(a + c), int(b + d)) | ||
for (a, b, c, d) in values] | ||
default.update({"number_of_faces": len(values), | ||
"faces": values, | ||
"safely_executed": True}) | ||
return default | ||
|
||
|
||
def read_image(path=None, stream=None, url=None): | ||
if path is not None: | ||
image = cv2.imread(path) | ||
else: | ||
if url is not None: | ||
response = urllib.request.urlopen(url) | ||
data_temp = response.read() | ||
elif stream is not None: | ||
data_temp = stream.read() | ||
image = np.asarray(bytearray(data_temp), dtype="uint8") | ||
image = cv2.imdecode(image, cv2.IMREAD_COLOR) | ||
return image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 2.2.1 on 2019-05-21 17:07 | ||
|
||
import django.contrib.auth.models | ||
import django.contrib.auth.validators | ||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('auth', '0011_update_proxy_permissions'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='User', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('password', models.CharField(max_length=128, verbose_name='password')), | ||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), | ||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), | ||
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), | ||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), | ||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), | ||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), | ||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), | ||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), | ||
('is_member', models.BooleanField(default=False)), | ||
('on_free_trial', models.BooleanField(default=True)), | ||
('stripe_customer_id', models.CharField(max_length=40)), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), | ||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), | ||
], | ||
options={ | ||
'verbose_name': 'user', | ||
'verbose_name_plural': 'users', | ||
'abstract': False, | ||
}, | ||
managers=[ | ||
('objects', django.contrib.auth.models.UserManager()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 2.2.1 on 2019-05-21 17:12 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Payment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('timestamp', models.DateTimeField(auto_now_add=True)), | ||
('amount', models.FloatField()), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Membership', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('type', models.CharField(choices=[('F', 'free_trial'), ('M', 'member'), ('N', 'not_member')], max_length=1)), | ||
('start_date', models.DateTimeField()), | ||
('end_date', models.DateTimeField()), | ||
('stripe_subscription_id', models.CharField(blank=True, max_length=40, null=True)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 2.2.1 on 2019-05-21 17:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0002_membership_payment'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='File', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('file', models.ImageField(upload_to='')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 2.2.1 on 2019-05-22 08:30 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0003_file'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='TrackedRequest', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('endpoint', models.CharField(max_length=50)), | ||
('timestamp', models.DateTimeField(auto_now_add=True)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
core/migrations/0005_membership_stripe_subscription_item_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.1 on 2019-05-22 13:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0004_trackedrequest'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='membership', | ||
name='stripe_subscription_item_id', | ||
field=models.CharField(blank=True, max_length=40, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.1 on 2019-05-22 13:21 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0005_membership_stripe_subscription_item_id'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='trackedrequest', | ||
name='usage_record_id', | ||
field=models.CharField(blank=True, max_length=50, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 2.2.1 on 2019-05-22 13:32 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0006_trackedrequest_usage_record_id'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='payment', | ||
name='user', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
] |