Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Code Refactor #109

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions coreapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
path('scenetextvideo/', views.SceneTextVideo.as_view(), name='scene_text_video'),
path('nsfwvideo/', views.NsfwVideo.as_view(), name='nsfw_video'),
path('scenevideo/', views.SceneVideo.as_view(), name='scene_video'),

]
]
96 changes: 48 additions & 48 deletions coreapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework import views, status
from rest_framework.response import Response
from corelib.facenet.utils import (getnewuniquefilename)
from .main_api import (facerecogniseinimage, facerecogniseinvideo,
from corelib.main_api import (facerecogniseinimage, facerecogniseinvideo,
createembedding, process_streaming_video,
nsfwclassifier, similarface, object_detect,
text_detect, object_detect_video, scene_detect,
Expand Down Expand Up @@ -47,50 +47,51 @@ def post(self, request):
return Response(result, status=status.HTTP_400_BAD_REQUEST)


class SceneDetect(views.APIView):
""" To classify scene in an image
class SceneTextVideo(views.APIView):
""" To localize and recognise text in a video
Workflow
* if POST method request is made, then initially a random
filename is generated and then scene_detect method is
called which process the image and outputs the result
containing the dictionary of probability of type of
scene in the image
filename is generated and then text_detect_video method
is called which process the video and outputs the result
containing the dictionary of detected text and bounding
boxes of the text for each frame
Returns:
* output dictionary of detected scenes and probabilities
of scenes in image
* output dictionary of detected text and bounding
boxes of the text for each frame of the video
"""

def post(self, request):

logger.info(msg="POST Request for Scene Detection made")
logger.info(msg="POST Request for Scene Text Extraction in video made")
filename = getnewuniquefilename(request)
input_file = request.FILES['file']
result = scene_detect(input_file, filename)
result = text_detect_video(input_file, filename)
if "Error" not in result:
return Response(result, status=status.HTTP_200_OK)
else:
return Response(result, status=status.HTTP_400_BAD_REQUEST)


class SceneTextVideo(views.APIView):
""" To localize and recognise text in a video
class NsfwRecognise(views.APIView):
""" To recognise whether a image is nsfw or not

Workflow
* if POST method request is made, then initially a random
filename is generated and then text_detect_video method
is called which process the video and outputs the result
containing the dictionary of detected text and bounding
boxes of the text for each frame
filename is generated and then nsfwclassifier method is
called which process the image and outputs the result
containing the dictionary of probability of type of content
in the image

Returns:
* output dictionary of detected text and bounding
boxes of the text for each frame of the video
* output dictionary of probability content in the image
"""

def post(self, request):

logger.info(msg="POST Request for Scene Text Extraction in video made")
logger.info(msg="POST Request for NSFW Classification made")
filename = getnewuniquefilename(request)
input_file = request.FILES['file']
result = text_detect_video(input_file, filename)
result = nsfwclassifier(input_file, filename)
if "Error" not in result:
return Response(result, status=status.HTTP_200_OK)
else:
Expand Down Expand Up @@ -122,6 +123,31 @@ def post(self, request):
return Response(result, status=status.HTTP_400_BAD_REQUEST)


class SceneDetect(views.APIView):
""" To classify scene in an image
Workflow
* if POST method request is made, then initially a random
filename is generated and then scene_detect method is
called which process the image and outputs the result
containing the dictionary of probability of type of
scene in the image
Returns:
* output dictionary of detected scenes and probabilities
of scenes in image
"""

def post(self, request):

logger.info(msg="POST Request for Scene Detection made")
filename = getnewuniquefilename(request)
input_file = request.FILES['file']
result = scene_detect(input_file, filename)
if "Error" not in result:
return Response(result, status=status.HTTP_200_OK)
else:
return Response(result, status=status.HTTP_400_BAD_REQUEST)


class SceneVideo(views.APIView):
""" To classify scenes video
Workflow
Expand Down Expand Up @@ -188,32 +214,6 @@ def post(self, request):
status=status.HTTP_400_BAD_REQUEST)


class NsfwRecognise(views.APIView):
""" To recognise whether a image is nsfw or not

Workflow
* if POST method request is made, then initially a random
filename is generated and then nsfwclassifier method is
called which process the image and outputs the result
containing the dictionary of probability of type of content
in the image

Returns:
* output dictionary of probability content in the image
"""

def post(self, request):

logger.info(msg="POST Request for NSFW Classification made")
filename = getnewuniquefilename(request)
input_file = request.FILES['file']
result = nsfwclassifier(input_file, filename)
if "Error" not in result:
return Response(result, status=status.HTTP_200_OK)
else:
return Response(result, status=status.HTTP_400_BAD_REQUEST)


class VideoFr(views.APIView):
""" To recognise faces in video

Expand Down Expand Up @@ -523,4 +523,4 @@ def post(self, request):
if "Error" not in result:
return Response(result, status=status.HTTP_200_OK)
else:
return Response(result, status=status.HTTP_400_BAD_REQUEST)
return Response(result, status=status.HTTP_400_BAD_REQUEST)
Loading