Browse Source

Add AutoLabelingConfigTest API

pull/1206/head
Hironsan 4 years ago
parent
commit
ac580002f2
3 changed files with 70 additions and 16 deletions
  1. 30
      Pipfile.lock
  2. 7
      app/api/urls.py
  3. 49
      app/api/views.py

30
Pipfile.lock

@ -34,11 +34,11 @@
}, },
"auto-labeling-pipeline": { "auto-labeling-pipeline": {
"hashes": [ "hashes": [
"sha256:8cb950f9b7ef083468442100fa46ce8c3b5a1e1721d96691d7c07e82aa28de31",
"sha256:ca7b600b7117606c21d77e122b0f0fed2e9c6b9aa6630a76e30750b06ea403cb"
"sha256:271cb07d521b2d25cd15102b3f03862826e248cac0ccf0cba6cba923d888761d",
"sha256:31eeea736910c6aa4b9ed5e8ec204dba5bca2a64525d451ca1c4377dddcccbcf"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.1.6"
"version": "==0.1.7"
}, },
"boto3": { "boto3": {
"hashes": [ "hashes": [
@ -178,11 +178,11 @@
}, },
"django": { "django": {
"hashes": [ "hashes": [
"sha256:2d78425ba74c7a1a74b196058b261b9733a8570782f4e2828974777ccca7edf7",
"sha256:efa2ab96b33b20c2182db93147a0c3cd7769d418926f9e9f140a60dca7c64ca9"
"sha256:169e2e7b4839a7910b393eec127fd7cbae62e80fa55f89c6510426abf673fe5f",
"sha256:c6c0462b8b361f8691171af1fb87eceb4442da28477e12200c40420176206ba7"
], ],
"index": "pypi", "index": "pypi",
"version": "==3.1.5"
"version": "==3.1.6"
}, },
"django-cors-headers": { "django-cors-headers": {
"hashes": [ "hashes": [
@ -645,10 +645,10 @@
}, },
"pytz": { "pytz": {
"hashes": [ "hashes": [
"sha256:16962c5fb8db4a8f63a26646d8886e9d769b6c511543557bc84e9569fb9a9cb4",
"sha256:180befebb1927b16f6b57101720075a984c019ac16b1b7575673bea42c6c3da5"
"sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da",
"sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798"
], ],
"version": "==2020.5"
"version": "==2021.1"
}, },
"requests": { "requests": {
"hashes": [ "hashes": [
@ -951,11 +951,11 @@
}, },
"django": { "django": {
"hashes": [ "hashes": [
"sha256:2d78425ba74c7a1a74b196058b261b9733a8570782f4e2828974777ccca7edf7",
"sha256:efa2ab96b33b20c2182db93147a0c3cd7769d418926f9e9f140a60dca7c64ca9"
"sha256:169e2e7b4839a7910b393eec127fd7cbae62e80fa55f89c6510426abf673fe5f",
"sha256:c6c0462b8b361f8691171af1fb87eceb4442da28477e12200c40420176206ba7"
], ],
"index": "pypi", "index": "pypi",
"version": "==3.1.5"
"version": "==3.1.6"
}, },
"flake8": { "flake8": {
"hashes": [ "hashes": [
@ -1147,10 +1147,10 @@
}, },
"pytz": { "pytz": {
"hashes": [ "hashes": [
"sha256:16962c5fb8db4a8f63a26646d8886e9d769b6c511543557bc84e9569fb9a9cb4",
"sha256:180befebb1927b16f6b57101720075a984c019ac16b1b7575673bea42c6c3da5"
"sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da",
"sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798"
], ],
"version": "==2020.5"
"version": "==2021.1"
}, },
"pyyaml": { "pyyaml": {
"hashes": [ "hashes": [

7
app/api/urls.py

@ -12,7 +12,7 @@ from .views import TextUploadAPI, TextDownloadAPI, CloudUploadAPI
from .views import StatisticsAPI from .views import StatisticsAPI
from .views import RoleMappingList, RoleMappingDetail, Roles from .views import RoleMappingList, RoleMappingDetail, Roles
from .views import AutoLabelingTemplateListAPI, AutoLabelingTemplateDetailAPI from .views import AutoLabelingTemplateListAPI, AutoLabelingTemplateDetailAPI
from .views import AutoLabelingConfigList, AutoLabelingConfigDetail
from .views import AutoLabelingConfigList, AutoLabelingConfigDetail, AutoLabelingConfigTest
urlpatterns = [ urlpatterns = [
path('health', Health.as_view(), name='health'), path('health', Health.as_view(), name='health'),
@ -74,6 +74,11 @@ urlpatterns = [
view=AutoLabelingConfigDetail.as_view(), view=AutoLabelingConfigDetail.as_view(),
name='auto_labeling_config' name='auto_labeling_config'
), ),
path(
route='projects/<int:project_id>/auto-labeling-config-testing',
view=AutoLabelingConfigTest.as_view(),
name='auto_labeling_config_test'
)
] ]
# urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'xml']) # urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'xml'])

49
app/api/views.py

@ -3,6 +3,11 @@ import json
import random import random
from auto_labeling_pipeline.menu import Options from auto_labeling_pipeline.menu import Options
from auto_labeling_pipeline.models import RequestModelFactory
from auto_labeling_pipeline.mappings import MappingTemplate
from auto_labeling_pipeline.task import TaskFactory
from auto_labeling_pipeline.postprocessing import PostProcessor
from auto_labeling_pipeline.pipeline import pipeline
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import transaction from django.db import transaction
@ -522,3 +527,47 @@ class AutoLabelingConfigDetail(generics.RetrieveUpdateDestroyAPIView):
serializer_class = AutoLabelingConfigSerializer serializer_class = AutoLabelingConfigSerializer
lookup_url_kwarg = 'config_id' lookup_url_kwarg = 'config_id'
permission_classes = [IsAuthenticated & IsProjectAdmin] permission_classes = [IsAuthenticated & IsProjectAdmin]
class AutoLabelingConfigTest(APIView):
permission_classes = [IsAuthenticated & IsProjectAdmin]
def post(self, *args, **kwargs):
try:
output = self.pass_config_validation()
output = self.pass_pipeline_call(output)
return Response(
data={'valid': True, 'labels': output.dict()},
status=status.HTTP_200_OK
)
except Exception:
return Response(
data={'valid': False},
status=status.HTTP_400_BAD_REQUEST
)
def pass_config_validation(self):
config = self.request.data['config']
serializer = AutoLabelingConfigSerializer(data=config)
serializer.is_valid(raise_exception=True)
return serializer
def pass_pipeline_call(self, serializer):
test_input = self.request.data['input']
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
model = RequestModelFactory.create(
model_name=serializer.data.get('model_name'),
attributes=serializer.data.get('model_attrs')
)
template = MappingTemplate(
task=TaskFactory.create(project.project_type),
template=serializer.data.get('template')
)
post_processor = PostProcessor(serializer.data.get('label_mapping'))
labels = pipeline(
text=test_input,
request_model=model,
mapping_template=template,
post_processing=post_processor
)
return labels
Loading…
Cancel
Save