summaryrefslogtreecommitdiff
path: root/megapixels
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-01-13 21:06:51 +0100
committerJules Laplace <julescarbon@gmail.com>2019-01-13 21:06:51 +0100
commitb4ed297a6dc73ec5f5cf2772ca1b754ea3f98cae (patch)
tree59798cf83e459a7f543515f54af2d7898257f44a /megapixels
parent6710b9f7f223acd01ac82171d9f9f4eb577f5885 (diff)
basic blurring applet
Diffstat (limited to 'megapixels')
-rw-r--r--megapixels/app/server/api.py1
-rw-r--r--megapixels/app/server/api_task.py10
-rw-r--r--megapixels/app/server/tasks/blur.py67
-rw-r--r--megapixels/app/server/tasks/fullmonte.py6
-rw-r--r--megapixels/app/server/tasks/sleep.py2
-rw-r--r--megapixels/app/settings/app_cfg.py1
6 files changed, 46 insertions, 41 deletions
diff --git a/megapixels/app/server/api.py b/megapixels/app/server/api.py
index 663f52cc..5ad454d8 100644
--- a/megapixels/app/server/api.py
+++ b/megapixels/app/server/api.py
@@ -39,7 +39,6 @@ def show(dataset_name):
else:
return jsonify({ 'status': 404 })
-
@api.route('/dataset/<dataset_name>/face', methods=['POST'])
def upload(dataset_name):
"""Query an image against FAISS and return the matching identities"""
diff --git a/megapixels/app/server/api_task.py b/megapixels/app/server/api_task.py
index fb24c154..c9bc19ed 100644
--- a/megapixels/app/server/api_task.py
+++ b/megapixels/app/server/api_task.py
@@ -31,22 +31,23 @@ def task_status(task_name, task_id):
return jsonify({
'state': 'error',
'percent': 100,
- 'message': 'Unknown task'
+ 'message': 'Unknown task',
})
-
# app.logger.info('task state: {}'.format(task.state))
if task.state == 'PENDING':
response = {
'state': task.state,
'percent': 0,
- 'message': 'Pending...'
+ 'message': 'Pending...',
+ 'data': task.info,
}
elif task.state != 'FAILURE':
response = {
'state': task.state,
'percent': task.info.get('percent', 0),
'uuid': task.info.get('uuid', 0),
- 'message': task.info.get('message', '')
+ 'message': task.info.get('message', ''),
+ 'data': task.info,
}
if 'result' in task.info:
response['result'] = task.info['result']
@@ -56,6 +57,7 @@ def task_status(task_name, task_id):
'state': task.state,
'percent': 100,
'message': str(task.info), # this is the exception raised
+ 'data': task.info,
}
return jsonify(response)
diff --git a/megapixels/app/server/tasks/blur.py b/megapixels/app/server/tasks/blur.py
index d1f67f54..42977097 100644
--- a/megapixels/app/server/tasks/blur.py
+++ b/megapixels/app/server/tasks/blur.py
@@ -9,6 +9,8 @@ import numpy as np
from app.utils.im_utils import ensure_np, ensure_pil
from flask import current_app as app
+import app.settings.app_cfg as cfg
+
from app.server.tasks import celery
from celery.utils.log import get_task_logger
@@ -19,57 +21,58 @@ import imutils
def blur_task(self, uuid_name, fn):
"""Process image and update during"""
celery_logger.debug('process_image_task, uuid: {}'.format(uuid_name))
+ celery_logger.debug('fn: {}'.format(fn))
files = []
+ meta = {
+ 'step': 0,
+ 'total': 3,
+ 'message': 'Starting',
+ 'uuid': uuid_name,
+ 'data': {},
+ }
+ self.update_state(state='PROCESSING', meta=meta)
+
im = Image.open(fn).convert('RGB')
+ os.remove(fn)
- self.update_state(
- state = 'PROCESSING',
- meta = {
- 'percent': 0.25,
- 'message': 'Applying blur',
- 'uuid': uuid_name
- })
+ meta['step'] += 1
+ meta['message'] = 'Applying blur'
+ self.update_state(state='PROCESSING', meta=meta)
im_np = ensure_np(im)
im_blur = cv.blur(im_np, (5,5), 1.0)
im_blur_pil = ensure_pil(im_blur)
fn = uuid_name + '_blur.jpg'
- # fpath = os.path.join(render_dir, fn)
- # im_blur_pil.save(fpath, 'JPEG', quality=95)
+ fpath = os.path.join(cfg.DIR_SITE_USER_CONTENT, fn)
+ im_blur_pil.save(fpath, 'JPEG', quality=80)
+ celery_logger.debug('fpath: {}'.format(fpath))
+ print('fpath: {}'.format(fpath))
# files.append({
# 'title': 'Blurred image',
# 'fn': render_uri + uuid_name + '_blur.jpg'
# })
+ meta['step'] += 1
+ meta['message'] = 'Applying blur'
+ meta['data']['blur_fn'] = os.path.join('/user_content/', fn)
+ self.update_state(state='PROCESSING', meta=meta)
time.sleep(3)
- self.update_state(
- state = 'PROCESSING',
- meta = {
- 'percent': 0.75,
- 'message': 'Sleeping some more',
- 'uuid': uuid_name
- })
- time.sleep(2)
+ if os.path.exists(fpath):
+ os.remove(fpath)
- data = {
- 'uuid': uuid_name,
- 'date': str(datetime.datetime.now()),
- 'files': files
- }
+ meta['step'] += 1
+ meta['message'] = 'Securely deleting user content'
+ self.update_state(state='PROCESSING', meta=meta)
+ time.sleep(2)
- # json_path = os.path.join(json_dir, uuid_name + '.json')
- # with open(json_path, 'w') as json_file:
- # json.dump(data, json_file)
+ celery_logger.debug('done!!')
+
+ meta['step'] = meta['total']
+ meta['state'] = 'complete'
+ return meta
- celery_logger.debug('ok')
-
- return {
- 'percent': 100,
- 'state': 'complete',
- 'uuid': uuid_name,
- }
diff --git a/megapixels/app/server/tasks/fullmonte.py b/megapixels/app/server/tasks/fullmonte.py
index 17ca9403..8215656a 100644
--- a/megapixels/app/server/tasks/fullmonte.py
+++ b/megapixels/app/server/tasks/fullmonte.py
@@ -17,15 +17,15 @@ from app.processors import face_detector, face_landmarks
from app.models.data_store import DataStore
@celery.task(bind=True)
-def fullmonte_task(self, uuid_name):
- return
-
+def fullmonte_task(self, uuid_name, fn):
# TOOD add selective testing
opt_run_pose = True
opt_run_2d_68 = True
opt_run_3d_68 = True
opt_run_3d_68 = True
+ return
+
# -------------------------------------------------
# init here
diff --git a/megapixels/app/server/tasks/sleep.py b/megapixels/app/server/tasks/sleep.py
index 9b91cc52..fa40b0e9 100644
--- a/megapixels/app/server/tasks/sleep.py
+++ b/megapixels/app/server/tasks/sleep.py
@@ -22,7 +22,7 @@ def sleep_task(self, uuid_name):
for i,m in enumerate(msgs):
percent = int(float(i)/float(len(msgs))*100.0)
self.update_state(
- state = 'PROCESSING',
+ state = 'processing',
meta = {
'percent': percent,
'message': m['msg'],
diff --git a/megapixels/app/settings/app_cfg.py b/megapixels/app/settings/app_cfg.py
index a8f41819..fea47572 100644
--- a/megapixels/app/settings/app_cfg.py
+++ b/megapixels/app/settings/app_cfg.py
@@ -148,6 +148,7 @@ S3_DATASETS_PATH = "v1" # datasets is already in the filename
DIR_SITE_PUBLIC = "../site/public"
DIR_SITE_CONTENT = "../site/content"
DIR_SITE_TEMPLATES = "../site/templates"
+DIR_SITE_USER_CONTENT = "../site/public/user_content"
# -----------------------------------------------------------------------------
# Celery