Skip to content

Commit fa49d07

Browse files
authored
Merge pull request #109 from PulkitMishra/master
[WIP] Code Refactor
2 parents e67e617 + d011b19 commit fa49d07

File tree

3 files changed

+214
-215
lines changed

3 files changed

+214
-215
lines changed

coreapi/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
path('scenetextvideo/', views.SceneTextVideo.as_view(), name='scene_text_video'),
1919
path('nsfwvideo/', views.NsfwVideo.as_view(), name='nsfw_video'),
2020
path('scenevideo/', views.SceneVideo.as_view(), name='scene_video'),
21-
22-
]
21+
]

coreapi/views.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework import views, status
33
from rest_framework.response import Response
44
from corelib.facenet.utils import (getnewuniquefilename)
5-
from .main_api import (facerecogniseinimage, facerecogniseinvideo,
5+
from corelib.main_api import (facerecogniseinimage, facerecogniseinvideo,
66
createembedding, process_streaming_video,
77
nsfwclassifier, similarface, object_detect,
88
text_detect, object_detect_video, scene_detect,
@@ -47,50 +47,51 @@ def post(self, request):
4747
return Response(result, status=status.HTTP_400_BAD_REQUEST)
4848

4949

50-
class SceneDetect(views.APIView):
51-
""" To classify scene in an image
50+
class SceneTextVideo(views.APIView):
51+
""" To localize and recognise text in a video
5252
Workflow
5353
* if POST method request is made, then initially a random
54-
filename is generated and then scene_detect method is
55-
called which process the image and outputs the result
56-
containing the dictionary of probability of type of
57-
scene in the image
54+
filename is generated and then text_detect_video method
55+
is called which process the video and outputs the result
56+
containing the dictionary of detected text and bounding
57+
boxes of the text for each frame
5858
Returns:
59-
* output dictionary of detected scenes and probabilities
60-
of scenes in image
59+
* output dictionary of detected text and bounding
60+
boxes of the text for each frame of the video
6161
"""
6262

6363
def post(self, request):
6464

65-
logger.info(msg="POST Request for Scene Detection made")
65+
logger.info(msg="POST Request for Scene Text Extraction in video made")
6666
filename = getnewuniquefilename(request)
6767
input_file = request.FILES['file']
68-
result = scene_detect(input_file, filename)
68+
result = text_detect_video(input_file, filename)
6969
if "Error" not in result:
7070
return Response(result, status=status.HTTP_200_OK)
7171
else:
7272
return Response(result, status=status.HTTP_400_BAD_REQUEST)
7373

7474

75-
class SceneTextVideo(views.APIView):
76-
""" To localize and recognise text in a video
75+
class NsfwRecognise(views.APIView):
76+
""" To recognise whether a image is nsfw or not
77+
7778
Workflow
7879
* if POST method request is made, then initially a random
79-
filename is generated and then text_detect_video method
80-
is called which process the video and outputs the result
81-
containing the dictionary of detected text and bounding
82-
boxes of the text for each frame
80+
filename is generated and then nsfwclassifier method is
81+
called which process the image and outputs the result
82+
containing the dictionary of probability of type of content
83+
in the image
84+
8385
Returns:
84-
* output dictionary of detected text and bounding
85-
boxes of the text for each frame of the video
86+
* output dictionary of probability content in the image
8687
"""
8788

8889
def post(self, request):
8990

90-
logger.info(msg="POST Request for Scene Text Extraction in video made")
91+
logger.info(msg="POST Request for NSFW Classification made")
9192
filename = getnewuniquefilename(request)
9293
input_file = request.FILES['file']
93-
result = text_detect_video(input_file, filename)
94+
result = nsfwclassifier(input_file, filename)
9495
if "Error" not in result:
9596
return Response(result, status=status.HTTP_200_OK)
9697
else:
@@ -122,6 +123,31 @@ def post(self, request):
122123
return Response(result, status=status.HTTP_400_BAD_REQUEST)
123124

124125

126+
class SceneDetect(views.APIView):
127+
""" To classify scene in an image
128+
Workflow
129+
* if POST method request is made, then initially a random
130+
filename is generated and then scene_detect method is
131+
called which process the image and outputs the result
132+
containing the dictionary of probability of type of
133+
scene in the image
134+
Returns:
135+
* output dictionary of detected scenes and probabilities
136+
of scenes in image
137+
"""
138+
139+
def post(self, request):
140+
141+
logger.info(msg="POST Request for Scene Detection made")
142+
filename = getnewuniquefilename(request)
143+
input_file = request.FILES['file']
144+
result = scene_detect(input_file, filename)
145+
if "Error" not in result:
146+
return Response(result, status=status.HTTP_200_OK)
147+
else:
148+
return Response(result, status=status.HTTP_400_BAD_REQUEST)
149+
150+
125151
class SceneVideo(views.APIView):
126152
""" To classify scenes video
127153
Workflow
@@ -188,32 +214,6 @@ def post(self, request):
188214
status=status.HTTP_400_BAD_REQUEST)
189215

190216

191-
class NsfwRecognise(views.APIView):
192-
""" To recognise whether a image is nsfw or not
193-
194-
Workflow
195-
* if POST method request is made, then initially a random
196-
filename is generated and then nsfwclassifier method is
197-
called which process the image and outputs the result
198-
containing the dictionary of probability of type of content
199-
in the image
200-
201-
Returns:
202-
* output dictionary of probability content in the image
203-
"""
204-
205-
def post(self, request):
206-
207-
logger.info(msg="POST Request for NSFW Classification made")
208-
filename = getnewuniquefilename(request)
209-
input_file = request.FILES['file']
210-
result = nsfwclassifier(input_file, filename)
211-
if "Error" not in result:
212-
return Response(result, status=status.HTTP_200_OK)
213-
else:
214-
return Response(result, status=status.HTTP_400_BAD_REQUEST)
215-
216-
217217
class VideoFr(views.APIView):
218218
""" To recognise faces in video
219219
@@ -523,4 +523,4 @@ def post(self, request):
523523
if "Error" not in result:
524524
return Response(result, status=status.HTTP_200_OK)
525525
else:
526-
return Response(result, status=status.HTTP_400_BAD_REQUEST)
526+
return Response(result, status=status.HTTP_400_BAD_REQUEST)

0 commit comments

Comments
 (0)