From d696a6f8549cf0b8ca83d926a3406c80283bda8d Mon Sep 17 00:00:00 2001 From: Anna Grund <annagrund@Annas-MacBook-Pro.local> Date: Sat, 4 Nov 2023 15:13:31 +0200 Subject: [PATCH] test --- .../static/js/ajp-category-suggestion.js | 74 +----------------- ajapaik/ajapaik/templates/_toolbox.html | 75 +------------------ ajapaik/settings/default.py | 6 +- 3 files changed, 7 insertions(+), 148 deletions(-) diff --git a/ajapaik/ajapaik/static/js/ajp-category-suggestion.js b/ajapaik/ajapaik/static/js/ajp-category-suggestion.js index b51d89157..a5f1f4936 100644 --- a/ajapaik/ajapaik/static/js/ajp-category-suggestion.js +++ b/ajapaik/ajapaik/static/js/ajp-category-suggestion.js @@ -1,5 +1,4 @@ function submitCategorySuggestion(photoIds, isMultiSelect) { - sendCategorySuggestionToAI(photoIds, scene, viewpointElevation) $('#ajp-loading-overlay').show(); return fetch(photoSceneUrl, { method: 'POST', @@ -99,75 +98,4 @@ function clickSceneCategoryButton(buttonId) { $('#' + buttonId).addClass('btn-outline-primary'); $('#' + buttonId).removeClass('btn-outline-dark'); $('#' + buttonId).removeClass('btn-light'); -} - -function getImageCategory(photoId, callback) { - let onSuccess = function (response) { - callback(determinePictureCategory(response.data)); - }; - getRequest( - '/object-categorization/get-latest-category/' + photoId + '/', - null, - null, - constants.translations.queries.GET_CATEGORY_FAILED, - onSuccess - ); -} - -function determinePictureCategory(responseData) { - let responseDict = {}; - for (let data of responseData) { - let fields = data["fields"]; - if ("scene" in fields) { - if (fields["scene"] === 0) { - responseDict["scene"] = "interior"; - } else { - responseDict["scene"] = "exterior"; - } - } - if ("viewpoint_elevation" in fields) { - if (fields["viewpoint_elevation"] === 0) { - responseDict["viewpoint_elevation"] = "ground"; - } else if (fields["viewpoint_elevation"] === 1) { - responseDict["viewpoint_elevation"] = "raised"; - } else if (fields["viewpoint_elevation"] === 2) { - responseDict["viewpoint_elevation"] = "areal"; - } - } - } - return responseDict; -} - -function sendCategorySuggestionToAI(photoIds, scene, viewpointElevation) { - let sceneVerdict = scene.toLowerCase(); - let viewpointElevationVerdict = viewpointElevation.toLowerCase(); - - let payload = { - "photo_id": photoIds[0] - }; - - if (sceneVerdict === "interior") { - payload["scene_to_alternate"] = 0 - } - if (sceneVerdict === "exterior") { - payload["scene_to_alternate"] = 1 - } - if (viewpointElevationVerdict === "ground") { - payload["viewpoint_elevation_to_alternate"] = 0 - } - if (viewpointElevationVerdict === "raised") { - payload["viewpoint_elevation_to_alternate"] = 1 - } - if (viewpointElevationVerdict === "raised") { - payload["viewpoint_elevation_to_alternate"] = 2 - } - - postRequest( - '/object-categorization/confirm-latest-category', - payload, - constants.translations.queries.POST_CATEGORY_CONFIRMATION_SUCCESS, - constants.translations.queries.POST_CATEGORY_CONFIRMATION_FAILED, - function () { - } - ); -} +} \ No newline at end of file diff --git a/ajapaik/ajapaik/templates/_toolbox.html b/ajapaik/ajapaik/templates/_toolbox.html index 474f2907c..ba3a2261d 100644 --- a/ajapaik/ajapaik/templates/_toolbox.html +++ b/ajapaik/ajapaik/templates/_toolbox.html @@ -75,9 +75,8 @@ </ul> {% trans 'Share' %} </div> - <div class="d-flex mr-2 ajp-toolbox-button-wrapper" style="display:grid; position: relative;" + <div class="d-flex mr-2 ajp-toolbox-button-wrapper" title="{% trans 'Add a category - clicking this button will enable you to categorize this picture to various categories such as whether this picture depicts indoors or outdoors' %}"> - <div style='position: absolute; top: 0; right: 0; background-color: #cfcdcc; color: #f2683a; font-size: 12px; padding: 1px 2px;'>AI</div> <button id="ajp-categorize-scene" type="button" data-toggle="popover" class="ajp-button" tabindex="0" data-is-categorization-button="true"> <span class="material-icons notranslate ajp-text-gray ajp-icon-36">category</span> @@ -148,35 +147,6 @@ var shareUrl = '{{ hostname }}{% if is_photo_modal %}{{ photo.get_detail_url }}{% elif rephoto %}{{ rephoto.get_absolute_url }}{% else %}{{ photo.get_absolute_url }}{% endif %}'; window.lastEnteredName = undefined; - function handleAIPrediction() { - getImageCategory('{{ photo.id }}', function (categoryMap) { - console.log(categoryMap) - let scene = categoryMap["scene"] - let viewpoint_elevation = categoryMap["viewpoint_elevation"] - - if (scene === "exterior") { - clickSceneCategoryButton('exterior-button'); - $("#exterior-ai").show(); - } - if (scene === "interior") { - clickSceneCategoryButton('interior-button'); - $("#interior-ai").show(); - } - if (viewpoint_elevation === "ground") { - clickViewpointElevationCategoryButton('ground-button'); - $("#ground-ai").show(); - } - if (viewpoint_elevation === "aerial") { - clickViewpointElevationCategoryButton('aerial-button'); - $("#aerial-ai").show(); - } - if (viewpoint_elevation === "raised") { - clickViewpointElevationCategoryButton('raised-button'); - $("#raised-ai").show(); - } - }); - } - function fetchPhotoInfo(url) { return fetch(url + '{{ photo.id }}' + '/').then(function(response) { return response.json(); @@ -239,45 +209,7 @@ buttonTranslation = 'Submit'; } - let content = `<div class='d-flex mb-4 justify-content-center'> - <div class='d-flex' style='flex-direction:column;align-items:center;'> - <button onclick='clickSceneCategoryButton(this.id);' id='interior-button' class='btn mr-2 ` + topLeftButtonClass + `' style='display:grid; position: relative;'> - <div id='interior-ai' style='display: none; position: absolute; top: 0; right: 0; background-color: #cfcdcc; color: #f2683a; font-size: 12px; padding: 1px 2px;'>AI</div> - <span class='material-icons notranslate ajp-icon-48'>hotel</span> - <span>` + gettext('Interior') + `</span> - </button> - </div> - <div class='d-flex' style='flex-direction:column;align-items:center;'> - <button onclick='clickSceneCategoryButton(this.id);' id='exterior-button' class='btn ml-2 ` + topRightButtonClass + `' style='display:grid; position: relative;'> - <div id='exterior-ai' style='display: none; position: absolute; top: 0; right: 0; background-color: #cfcdcc; color: #f2683a; font-size: 12px; padding: 1px 2px;'>AI</div> - <span class='material-icons ajp-icon-48 notranslate'>home</span> - <span>` + gettext('Exterior') + `</span> - </button> - </div> - </div> - <div class='d-flex'><div class='d-flex' style='flex-direction:column;align-items:center;'> - <button onclick='clickViewpointElevationCategoryButton(this.id);' id='ground-button' class='btn mr-2 ` + bottomLeftButtonClass + `' style='display:grid; position: relative;'> - <div id='ground-ai' style='display: none; position: absolute; top: 0; right: 0; background-color: #cfcdcc; color: #f2683a; font-size: 12px; padding: 1px 2px;'>AI</div> - <span class='material-icons notranslate ajp-icon-48'>nature_people</span> - <span>` + gettext('Ground') + `</span> - </button> - </div> - <div class='d-flex' style='flex-direction:column;align-items:center;'> - <button onclick='clickViewpointElevationCategoryButton(this.id);' id='raised-button' class='btn mr-2 ` + bottomMiddleButtonClass + `' style='display:grid; position: relative;'> - <div id='raised-ai' style='display: none; position: absolute; top: 0; right: 0; background-color: #cfcdcc; color: #f2683a; font-size: 12px; padding: 1px 2px;'>AI</div> - <span class='material-icons notranslate ajp-icon-48'>location_city</span> - <span>` + gettext('Raised') + `</span> - </button> - </div> - <div class='d-flex' style='flex-direction:column;align-items:center;'> - <button onclick='clickViewpointElevationCategoryButton(this.id);' id='aerial-button' class='btn ml-2 d-grid ` + bottomRightButtonClass + `' style='display:grid; position: relative;'> - <div id='aerial-ai' style='display: none; position: absolute; top: 0; right: 0; background-color: #cfcdcc; color: #f2683a; font-size: 12px; padding: 1px 2px;'>AI</div> - <span class='material-icons ajp-icon-48 notranslate'>flight</span> - <span>` + gettext('Aerial') + `</span> - </button> - </div> - </div>`; - + let content = `<div class='d-flex mb-4 justify-content-center'><div class='d-flex' style='flex-direction:column;align-items:center;'><button onclick='clickSceneCategoryButton(this.id);' id='interior-button' class='btn mr-2 ` + topLeftButtonClass + `' style='display:grid;'><span class='material-icons notranslate ajp-icon-48'>hotel</span><span>` + gettext('Interior') + `</span></button></div><div class='d-flex' style='flex-direction:column;align-items:center;'><button onclick='clickSceneCategoryButton(this.id);' id='exterior-button' class='btn ml-2 ` + topRightButtonClass + `' style='display:grid;'><span class='material-icons ajp-icon-48 notranslate'>home</span><span>` + gettext('Exterior') + `</span></button></div></div><div class='d-flex'><div class='d-flex' style='flex-direction:column;align-items:center;'><button onclick='clickViewpointElevationCategoryButton(this.id);' id='ground-button' class='btn mr-2 ` + bottomLeftButtonClass + `' style='display:grid;'><span class='material-icons notranslate ajp-icon-48'>nature_people</span><span>` + gettext('Ground') + `</span></button></div><div class='d-flex' style='flex-direction:column;align-items:center;'><button onclick='clickViewpointElevationCategoryButton(this.id);' id='raised-button' class='btn mr-2 ` + bottomMiddleButtonClass + `' style='display:grid;'><span class='material-icons notranslate ajp-icon-48'>location_city</span><span>` + gettext('Raised') + `</span></button></div><div class='d-flex' style='flex-direction:column;align-items:center;'><button onclick='clickViewpointElevationCategoryButton(this.id);' id='aerial-button' class='btn ml-2 d-grid ` + bottomRightButtonClass + `' style='display:grid;'><span class='material-icons ajp-icon-48 notranslate'>flight</span><span>` + gettext('Aerial') + `</span></button></div></div>`; let actionButtonTemplate = `<button id='send-suggestion-button' onclick="submitCategorySuggestion(['{{ photo.id }}'], false);" class='btn btn-success mt-3 w-100' disabled>` + gettext(buttonTranslation) + `</button>`; content += actionButtonTemplate; @@ -382,7 +314,6 @@ $('#ajp-categorize-scene').popover('hide'); } else { $('#ajp-categorize-scene').popover('show'); - handleAIPrediction(); } }); @@ -578,4 +509,4 @@ } }); </script> -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/ajapaik/settings/default.py b/ajapaik/settings/default.py index 6c745e83c..03471ba60 100644 --- a/ajapaik/settings/default.py +++ b/ajapaik/settings/default.py @@ -104,7 +104,7 @@ SECRET_KEY = '!!! paste your own secret key here !!!' MIDDLEWARE = [ - 'corsheaders.middleware.CorsMiddleware', + # 'corsheaders.middleware.CorsMiddleware', 'django_hosts.middleware.HostsRequestMiddleware', 'django.middleware.gzip.GZipMiddleware', 'django.middleware.security.SecurityMiddleware', @@ -199,7 +199,7 @@ 'ajapaik.ajapaik_object_recognition', 'ajapaik.ajapaik_object_categorization', 'django_user_agents', - 'corsheaders', + # 'corsheaders', # Django allauth and related applications. 'allauth', @@ -399,7 +399,7 @@ ACCOUNT_AUTHENTICATION_METHOD = 'email' ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_UNIQUE_EMAIL = True -ACCOUNT_EMAIL_VERIFICATION = 'mandatory' +ACCOUNT_EMAIL_VERIFICATION = 'none' ACCOUNT_USERNAME_REQUIRED = False ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False SOCIALACCOUNT_EMAIL_VERIFICATION = 'none'