2023-12-06 18:12:31 +01:00
|
|
|
{% extends 'base.html' %}
|
|
|
|
{%load static%}
|
|
|
|
{%block extracss%}
|
|
|
|
<link rel="stylesheet" href="{%static 'DetectionApp/css/upload.css' %}">
|
|
|
|
{%endblock extracss%}
|
|
|
|
{%block content%}
|
2023-12-23 17:01:39 +01:00
|
|
|
<form method="POST" enctype="multipart/form-data" id="upload_form">
|
2023-11-20 15:53:42 +01:00
|
|
|
{% csrf_token %}
|
|
|
|
<div class="side_menu">
|
2023-12-13 02:11:29 +01:00
|
|
|
{% if not user.is_authenticated %}
|
|
|
|
<p id="description">Please login to submit image</p>
|
|
|
|
<button onclick="location.href='{% url 'login' %}'" id='submit' method="GET" type='button'>Login</button>
|
2023-12-19 17:33:46 +01:00
|
|
|
{% else %}
|
2023-11-20 15:53:42 +01:00
|
|
|
<p id="description">Choose image for analysis</p>
|
2023-11-28 18:32:10 +01:00
|
|
|
<input type="submit" id="submit" value="Submit">
|
2023-11-20 15:53:42 +01:00
|
|
|
{%endif%}
|
|
|
|
</div>
|
2023-12-23 17:01:39 +01:00
|
|
|
<div id="progress"></div>
|
2023-12-19 17:33:46 +01:00
|
|
|
<div class="upload_field">
|
|
|
|
<label for="id_image", class="upload_button" id="image-preview-container">
|
2023-11-20 15:53:42 +01:00
|
|
|
{{form.as_p}}
|
2023-12-19 17:33:46 +01:00
|
|
|
<img id="image-preview" src="{% static 'DetectionApp/images/upload_img.png' %}" alt="Image Preview" style="width:640px; height:460px;"/>
|
2023-11-20 15:53:42 +01:00
|
|
|
</label>
|
2023-12-19 17:33:46 +01:00
|
|
|
</div>
|
2023-11-20 15:53:42 +01:00
|
|
|
</form>
|
2023-11-27 16:52:09 +01:00
|
|
|
<script>
|
2023-12-19 17:33:46 +01:00
|
|
|
document.getElementById('id_image').addEventListener('change', function () {
|
|
|
|
var input = this;
|
|
|
|
var previewContainer = document.getElementById('image-preview-container');
|
2023-11-27 16:52:09 +01:00
|
|
|
|
2023-12-19 17:33:46 +01:00
|
|
|
|
|
|
|
if (input.files && input.files.length > 1) {
|
|
|
|
document.getElementById('image-preview').style.display='none'
|
|
|
|
for (var i = 0; i < input.files.length; i++) {
|
|
|
|
(function (index) {
|
2023-11-27 16:52:09 +01:00
|
|
|
var reader = new FileReader();
|
|
|
|
|
2023-12-19 17:33:46 +01:00
|
|
|
reader.onload = function (e) {
|
|
|
|
// Create a new image element for each preview
|
|
|
|
var img = document.createElement('img');
|
|
|
|
img.src = e.target.result;
|
|
|
|
img.id = 'image-preview'
|
|
|
|
img.style.display = 'block';
|
|
|
|
img.style.width='640px'
|
|
|
|
img.style.height='460px'
|
|
|
|
img.style.marginRight="5px"
|
|
|
|
|
|
|
|
// Append the image element to the container
|
|
|
|
previewContainer.style.overflowY='hidden'
|
|
|
|
previewContainer.style.overflowX='scroll'
|
|
|
|
previewContainer.style.width='640px'
|
|
|
|
previewContainer.style.height='460px'
|
|
|
|
previewContainer.appendChild(img);
|
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsDataURL(input.files[index]);
|
|
|
|
})(i);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
2023-11-27 16:52:09 +01:00
|
|
|
reader.onload = function(e) {
|
|
|
|
document.getElementById('image-preview').src = e.target.result;
|
|
|
|
document.getElementById('image-preview').style.display = 'block';
|
|
|
|
}
|
2023-12-19 17:33:46 +01:00
|
|
|
reader.readAsDataURL(input.files[0]);
|
2023-11-27 16:52:09 +01:00
|
|
|
|
2023-12-19 17:33:46 +01:00
|
|
|
}
|
|
|
|
});
|
2023-11-27 16:52:09 +01:00
|
|
|
</script>
|
|
|
|
</form>
|
2023-12-06 18:12:31 +01:00
|
|
|
{%endblock content%}
|