def custom_image_clf_train_controller(request):
    if request.method == "POST":
        pretty_request(request)
        params = json.loads(request.body.decode(CHARSET))
        user_id = request.META['HTTP_USER_ID']
        train_request = ImageClfRequest(params)
        job_id = create_job(user_id, TRAIN, train_request.service, train_request.name)
        train_component.delay(params, user_id, job_id)
        response = {"job_id":job_id}
        return HttpResponse(json.dumps(response), content_type=CONTENT_TYPE, status=200)
def face_detection_image_controller(request):
    try:
        if request.method == "POST":
            pretty_request(request)
            with open('original_image', 'wb') as f:
                f.write(request.FILES['image'].read())
            image_path = "original_image"
            response = face_detection_image(image_path)
            return HttpResponse(response, content_type=CONTENT_TYPE, status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
def job_list(request):
    try:
        if request.method == "POST":
            print(pretty_request(request))
            user_id = request.META['HTTP_USER_ID']
            params = json.loads(request.body.decode(CHARSET))
            status  = params['status']
            service = params['service']
            jobs_list = []
            if status == "ALL":
                jobs_list = JobStatus.objects.filter(user_id=user_id, task=constants.TRAIN, service=service).values()
            elif status == constants.FINISH:
                jobs_list = JobStatus.objects.filter(user_id=user_id, task_status=constants.FINISH, task=constants.TRAIN, service=service).values()
            response = []
            for job in jobs_list:
                x = {
                    "status" : job["task_status"],
                    "output": job["output"]
                }
                response.append(x)
            output={}
            output["job_list"] = response
            return HttpResponse(json.dumps(output), content_type=CONTENT_TYPE, status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
def custom_image_clf_predict_controller(request):
    if request.method == "POST":
        print(pretty_request(request))
        params = json.loads(request.body.decode(CHARSET))
        user_id = request.META['HTTP_USER_ID']
        prediction_request = PredictionRequest(params)
        job_id = create_job(user_id, PREDICT, prediction_request.service, prediction_request.name)
        predict_component.delay(params, user_id, job_id)
        response = {"job_id": job_id}
        return HttpResponse(json.dumps(response), content_type=CONTENT_TYPE, status=200)
def image_clf_controller(request):
    try:
        if request.method == "POST":
            print(pretty_request(request))
            with open('clf_image.jpg', 'wb') as f:
                f.write(request.FILES['image'].read())
            image_path = "clf_image.jpg"
            response = image_classification(image_path)
            return HttpResponse(json.dumps(response), content_type=CONTENT_TYPE, status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
def custom_image_clf_predict_image_controller(request):
    try:
        if request.method == "POST":
            print(pretty_request(request))
            with open('clf_image.jpg', 'wb') as f:
                f.write(request.FILES['image'].read())
            image_path = "clf_image.jpg"
            model_url = request.POST["modelUrl"]
            user_id = request.META['HTTP_USER_ID']
            response = prediction_image(image_path, model_url, user_id)
            return HttpResponse(json.dumps(response), content_type=CONTENT_TYPE, status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
def obj_json(request):
    try:
        if request.method == "POST":
            print(pretty_request(request))
            with open('original_image.png', 'wb') as f:
                f.write(request.FILES['image'].read())
            image_path = "original_image.png"
            response = object_detection_json(image_path)
            return HttpResponse(json.dumps(response),
                                content_type=CONTENT_TYPE,
                                status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
Esempio n. 8
0
def license_plate_image_controller(request):
    try:
        if request.method == "POST":
            print(pretty_request(request))
            with open('lp.png', 'wb') as f:
                f.write(request.FILES['image'].read())
            image_path = "lp.png"
            response = licence_plate_image(image_path)
            return HttpResponse(response,
                                content_type=CONTENT_TYPE,
                                status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
def custom_obj_detection_predict_image_controller(request):
    try:
        if request.method == "POST":
            print(pretty_request(request))
            with open('original_image.png', 'wb') as f:
                f.write(request.FILES['image'].read())
            image_path = "original_image.png"
            model_url = request.POST["modelUrl"]
            user_id = request.META['HTTP_USER_ID']
            response = custom_object_detection_image(model_url, image_path,
                                                     user_id)
            return HttpResponse(response,
                                content_type=CONTENT_TYPE,
                                status=200)
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)
def job_status(request, job_id):
    try:
        if request.method == "GET":
            print(pretty_request(request))
            job = JobStatus.objects.get(job_id=job_id)
            response = {
                "task": job.task,
                "status" : job.task_status,
                "output": job.output
            }
            if response is not None:
                return HttpResponse(json.dumps(response), content_type=CONTENT_TYPE, status=200)
            else:
                raise JobNotFoundError()
    except Exception as e:
        traceback.print_exc()
        return HttpResponse(e.args, status=500, content_type=CONTENT_TYPE)