Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Grund authored and Anna Grund committed Nov 4, 2023
1 parent 4374b3c commit d696a6f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 148 deletions.
74 changes: 1 addition & 73 deletions ajapaik/ajapaik/static/js/ajp-category-suggestion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function submitCategorySuggestion(photoIds, isMultiSelect) {
sendCategorySuggestionToAI(photoIds, scene, viewpointElevation)
$('#ajp-loading-overlay').show();
return fetch(photoSceneUrl, {
method: 'POST',
Expand Down Expand Up @@ -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 () {
}
);
}
}
75 changes: 3 additions & 72 deletions ajapaik/ajapaik/templates/_toolbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -382,7 +314,6 @@
$('#ajp-categorize-scene').popover('hide');
} else {
$('#ajp-categorize-scene').popover('show');
handleAIPrediction();
}
});

Expand Down Expand Up @@ -578,4 +509,4 @@
}
});
</script>
{% endblock %}
{% endblock %}
6 changes: 3 additions & 3 deletions ajapaik/settings/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -199,7 +199,7 @@
'ajapaik.ajapaik_object_recognition',
'ajapaik.ajapaik_object_categorization',
'django_user_agents',
'corsheaders',
# 'corsheaders',

# Django allauth and related applications.
'allauth',
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit d696a6f

Please sign in to comment.