# Path: ISeeNN/search_web/feature_extractor/extractor.py
# class ResizeExtractor(Extractor):
# 
#     def __init__(self, model_type, input_size):
#         self.__input_size = input_size
#         Extractor.__init__(self, model_type=model_type)
# 
#     def _build_model(self):
#         self._inputs = tf.placeholder("float", [1, self.__input_size[0], self.__input_size[1], 3])
#         self._model.build(self._inputs)
# 
#     def extract(self, image_path):
#         img = load_image(image_path, self.__input_size[0], self.__input_size[1])
#         return Extractor._get_feature(self, img)
# 
# class NoResizeExtractor(Extractor):
#     def __init__(self, model_type):
#         Extractor.__init__(self, model_type=model_type)
# 
#     def _build_model(self):
#         self._inputs = tf.placeholder("float", None)
#         self._model.build(self._inputs)
# 
#     def extract(self, image_path):
#         img = load_image(image_path)
#         return Extractor._get_feature(self, img)
# 
# Path: ISeeNN/search_web/feature_extractor/normalizer.py
# class NormalizerFactory:
# 
#     __normalizer_dict = dict(L2=L2Nomalizer, ROOT=RootNormalizer)
# 
#     @staticmethod
#     def get(name):
#         return NormalizerFactory.__normalizer_dict[name]()
# 
# Path: ISeeNN/search_web/models.py
# class Feature(Document):
#     image = fields.ObjectIdField(required=True)
#     dimension = fields.IntField(required=True)
#     data = fields.BinaryField(required=True)
#     model = fields.StringField(required=True)
#     identity = fields.StringField(required=True)
#     meta = {
#         'indexes': [
#             '#identity',
#             {
#                 'fields': ['image', 'identity'],
#                 'unique': True
#             }
#         ]
#     }
# 
# class DBImage(Document):
#     server = fields.ObjectIdField(required=True)
#     path = fields.StringField(required=True)
#     mime_type = fields.StringField(required=True)
#     width = fields.IntField(required=True)
#     height = fields.IntField(required=True)
#     source = fields.StringField()
#     meta = {
#         'indexes': [
#             {
#                 'fields': ['path'],
#                 'unique': True
#             },
#             '#source'
#         ]
#     }
# 
# class ImageServer(Document):
#     server_name = fields.StringField(required=True)
#     server_ip = fields.StringField(required=True)
# 
#     def __str__(self):
#         return "%s(%s)" % (self.server_name, self.server_ip)
# 
# class ImageUploadForm(forms.Form):
#     image_file = forms.ImageField()
# 
# class UserUploadImage(Document):
#     data = fields.ImageField(required=True, size=(1024, 1024), thumbnail_size=(640, 200))
#     feature = fields.BinaryField()
#     identity = fields.StringField()
# 
# class AestheticInfo(Document):
#     image = fields.ObjectIdField(required=True)
#     tags = fields.ListField()
#     score = fields.FloatField(required=True)


from django.shortcuts import render
from django.http import HttpResponse, HttpResponseGone, HttpResponseServerError, HttpResponseRedirect
from django.http import Http404
from django.conf import settings
from django.urls import reverse
from PIL import Image
from io import BytesIO
from .search_engine import Index, push_index_item, exec_query, QueryType
from .feature_extractor import ResizeExtractor, NoResizeExtractor, NormalizerFactory
from .models import Feature, DBImage, ImageServer, ImageUploadForm, UserUploadImage, AestheticInfo
import urllib.request, urllib.error
import time
import math
import numpy as np
import sys
            return HttpResponse(user_image.data.read(), content_type=mime_type)
    except UserUploadImage.DoesNotExist:
        raise Http404("Image Not Found")


def index(request):
    return render(request, 'search_web/index.html')


class ResultMeta:
    def __init__(self, id, score=0, width=0, height=0, aesthetic_tag=[], aesthetic_score=0.0):
        self.id = id
        self.score = score
        self.width = width
        self.height = height
        self.aesthetic_tag = aesthetic_tag
        self.aesthetic_score = aesthetic_score


def get_image_meta(id):
    dbimage = DBImage.objects.get(pk=id)
    if settings.AESTHETIC:
        try:
            aesthetic_info = AestheticInfo.objects.get(image=id)
            return ResultMeta(
                id=id,
                width=dbimage.width,
                height=dbimage.height,
                aesthetic_tag=aesthetic_info.tags,
                aesthetic_score=aesthetic_info.score)

# Path: ISeeNN/search_web/feature_extractor/extractor.py
# class ResizeExtractor(Extractor):
# 
#     def __init__(self, model_type, input_size):
#         self.__input_size = input_size
#         Extractor.__init__(self, model_type=model_type)
# 
#     def _build_model(self):
#         self._inputs = tf.placeholder("float", [1, self.__input_size[0], self.__input_size[1], 3])
#         self._model.build(self._inputs)
# 
#     def extract(self, image_path):
#         img = load_image(image_path, self.__input_size[0], self.__input_size[1])
#         return Extractor._get_feature(self, img)
# 
# class NoResizeExtractor(Extractor):
#     def __init__(self, model_type):
#         Extractor.__init__(self, model_type=model_type)
# 
#     def _build_model(self):
#         self._inputs = tf.placeholder("float", None)
#         self._model.build(self._inputs)
# 
#     def extract(self, image_path):
#         img = load_image(image_path)
#         return Extractor._get_feature(self, img)
# 
# Path: ISeeNN/search_web/feature_extractor/normalizer.py
# class NormalizerFactory:
# 
#     __normalizer_dict = dict(L2=L2Nomalizer, ROOT=RootNormalizer)
# 
#     @staticmethod
#     def get(name):
#         return NormalizerFactory.__normalizer_dict[name]()
# 
# Path: ISeeNN/search_web/models.py
# class Feature(Document):
#     image = fields.ObjectIdField(required=True)
#     dimension = fields.IntField(required=True)
#     data = fields.BinaryField(required=True)
#     model = fields.StringField(required=True)
#     identity = fields.StringField(required=True)
#     meta = {
#         'indexes': [
#             '#identity',
#             {
#                 'fields': ['image', 'identity'],
#                 'unique': True
#             }
#         ]
#     }
# 
# class DBImage(Document):
#     server = fields.ObjectIdField(required=True)
#     path = fields.StringField(required=True)
#     mime_type = fields.StringField(required=True)
#     width = fields.IntField(required=True)
#     height = fields.IntField(required=True)
#     source = fields.StringField()
#     meta = {
#         'indexes': [
#             {
#                 'fields': ['path'],
#                 'unique': True
#             },
#             '#source'
#         ]
#     }
# 
# class ImageServer(Document):
#     server_name = fields.StringField(required=True)
#     server_ip = fields.StringField(required=True)
# 
#     def __str__(self):
#         return "%s(%s)" % (self.server_name, self.server_ip)
# 
# class ImageUploadForm(forms.Form):
#     image_file = forms.ImageField()
# 
# class UserUploadImage(Document):
#     data = fields.ImageField(required=True, size=(1024, 1024), thumbnail_size=(640, 200))
#     feature = fields.BinaryField()
#     identity = fields.StringField()
# 
# class AestheticInfo(Document):
#     image = fields.ObjectIdField(required=True)
#     tags = fields.ListField()
#     score = fields.FloatField(required=True)


# Path: ISeeNN/search_web/views.py
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseGone, HttpResponseServerError, HttpResponseRedirect
from django.http import Http404
from django.conf import settings
from django.urls import reverse
from PIL import Image
from io import BytesIO
from .search_engine import Index, push_index_item, exec_query, QueryType
from .feature_extractor import ResizeExtractor, NoResizeExtractor, NormalizerFactory
from .models import Feature, DBImage, ImageServer, ImageUploadForm, UserUploadImage, AestheticInfo
import urllib.request, urllib.error
import time
import math
import numpy as np
import sys

            return HttpResponse(user_image.data.read(), content_type=mime_type)
    except UserUploadImage.DoesNotExist:
        raise Http404("Image Not Found")


def index(request):
    return render(request, 'search_web/index.html')


class ResultMeta:
    def __init__(self, id, score=0, width=0, height=0, aesthetic_tag=[], aesthetic_score=0.0):
        self.id = id
        self.score = score
        self.width = width
        self.height = height
        self.aesthetic_tag = aesthetic_tag
        self.aesthetic_score = aesthetic_score


def get_image_meta(id):
    dbimage = DBImage.objects.get(pk=id)
    if settings.AESTHETIC:
        try:
            aesthetic_info = AestheticInfo.objects.get(image=id)
            return ResultMeta(
                id=id,
                width=dbimage.width,
                height=dbimage.height,
                aesthetic_tag=aesthetic_info.tags,
                aesthetic_score=aesthetic_info.score)

        except AestheticInfo.DoesNotExist: