|
|
@ -1,3 +1,23 @@ |
|
|
|
from django.http import HttpResponseRedirect |
|
|
|
from django.shortcuts import render |
|
|
|
from .apps import DetectAppConfig |
|
|
|
from .forms import UploadFileForm |
|
|
|
from .upload import handle_uploaded_file |
|
|
|
from .detect import detect |
|
|
|
|
|
|
|
# Create your views here. |
|
|
|
|
|
|
|
def upload_file(request): |
|
|
|
result = None |
|
|
|
if request.method == 'POST': |
|
|
|
form = UploadFileForm(request.POST, request.FILES) |
|
|
|
if form.is_valid(): |
|
|
|
input_path = DetectAppConfig.image_filebase + DetectAppConfig.image_file_input |
|
|
|
output_path = DetectAppConfig.image_filebase + DetectAppConfig.image_file_output |
|
|
|
output_url = DetectAppConfig.image_urlbase + DetectAppConfig.image_file_output |
|
|
|
|
|
|
|
handle_uploaded_file(request.FILES['file'], input_path) |
|
|
|
detect(input_path, output_path) |
|
|
|
result = output_url |
|
|
|
else: |
|
|
|
form = UploadFileForm() |
|
|
|
return render(request, 'detect_app/upload.html', {'form': form, 'result': result}) |