Browse Source

Move auto labeling model to auto labeling app

pull/1646/head
Hironsan 3 years ago
parent
commit
7c9eb29020
7 changed files with 102 additions and 33 deletions
  1. 26
      backend/api/migrations/0030_delete_autolabelingconfig.py
  2. 30
      backend/api/models.py
  3. 2
      backend/auto_labeling/admin.py
  4. 37
      backend/auto_labeling/migrations/0001_initial.py
  5. 34
      backend/auto_labeling/models.py
  6. 3
      backend/auto_labeling/serializers.py
  7. 3
      backend/auto_labeling/views.py

26
backend/api/migrations/0030_delete_autolabelingconfig.py

@ -0,0 +1,26 @@
# Generated by Django 3.2.11 on 2022-01-20 04:17
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0029_auto_20220119_2333'),
]
operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.DeleteModel(
name='AutoLabelingConfig',
),
],
database_operations=[
migrations.AlterModelTable(
name='AutoLabelingConfig',
table='auto_labeling_autolabelingconfig'
)
]
)
]

30
backend/api/models.py

@ -3,7 +3,6 @@ import random
import string import string
import uuid import uuid
from auto_labeling_pipeline.models import RequestModelFactory
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
@ -412,35 +411,6 @@ class TextLabel(Annotation):
) )
class AutoLabelingConfig(models.Model):
model_name = models.CharField(max_length=100)
model_attrs = models.JSONField(default=dict)
template = models.TextField(default='')
label_mapping = models.JSONField(default=dict, blank=True)
project = models.ForeignKey(
to=Project,
on_delete=models.CASCADE,
related_name='auto_labeling_config'
)
default = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.model_name
def clean_fields(self, exclude=None):
super().clean_fields(exclude=exclude)
try:
RequestModelFactory.find(self.model_name)
except NameError:
message = f'The specified model name {self.model_name} does not exist.'
raise ValidationError(message)
except Exception:
message = 'The attributes does not match the model.'
raise ValidationError(message)
class RelationTypes(models.Model): class RelationTypes(models.Model):
color = models.TextField() color = models.TextField()
name = models.TextField() name = models.TextField()

2
backend/auto_labeling/admin.py

@ -1,6 +1,6 @@
from django.contrib import admin from django.contrib import admin
from api.models import AutoLabelingConfig
from .models import AutoLabelingConfig
class AutoLabelingConfigAdmin(admin.ModelAdmin): class AutoLabelingConfigAdmin(admin.ModelAdmin):

37
backend/auto_labeling/migrations/0001_initial.py

@ -0,0 +1,37 @@
# Generated by Django 3.2.11 on 2022-01-20 04:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('api', '0030_delete_autolabelingconfig'),
]
operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.CreateModel(
name='AutoLabelingConfig',
fields=[
('id',
models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('model_name', models.CharField(max_length=100)),
('model_attrs', models.JSONField(default=dict)),
('template', models.TextField(default='')),
('label_mapping', models.JSONField(blank=True, default=dict)),
('default', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
related_name='auto_labeling_config', to='api.project')),
],
),
],
database_operations=[]
)
]

34
backend/auto_labeling/models.py

@ -0,0 +1,34 @@
from auto_labeling_pipeline.models import RequestModelFactory
from django.core.exceptions import ValidationError
from django.db import models
from api.models import Project
class AutoLabelingConfig(models.Model):
model_name = models.CharField(max_length=100)
model_attrs = models.JSONField(default=dict)
template = models.TextField(default='')
label_mapping = models.JSONField(default=dict, blank=True)
project = models.ForeignKey(
to=Project,
on_delete=models.CASCADE,
related_name='auto_labeling_config'
)
default = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.model_name
def clean_fields(self, exclude=None):
super().clean_fields(exclude=exclude)
try:
RequestModelFactory.find(self.model_name)
except NameError:
message = f'The specified model name {self.model_name} does not exist.'
raise ValidationError(message)
except Exception:
message = 'The attributes does not match the model.'
raise ValidationError(message)

3
backend/auto_labeling/serializers.py

@ -1,9 +1,10 @@
from auto_labeling_pipeline.models import RequestModelFactory from auto_labeling_pipeline.models import RequestModelFactory
from rest_framework import serializers from rest_framework import serializers
from api.models import AutoLabelingConfig, DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ, SPEECH2TEXT, \
from api.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ, SPEECH2TEXT, \
IMAGE_CLASSIFICATION IMAGE_CLASSIFICATION
from api.serializers import CategorySerializer, SpanSerializer, TextLabelSerializer from api.serializers import CategorySerializer, SpanSerializer, TextLabelSerializer
from .models import AutoLabelingConfig
class AutoLabelingConfigSerializer(serializers.ModelSerializer): class AutoLabelingConfigSerializer(serializers.ModelSerializer):

3
backend/auto_labeling/views.py

@ -16,11 +16,12 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from api.models import AutoLabelingConfig, Example, Project
from api.models import Example, Project
from members.permissions import IsInProjectOrAdmin, IsProjectAdmin from members.permissions import IsInProjectOrAdmin, IsProjectAdmin
from .exceptions import (AutoLabelingException, AutoLabelingPermissionDenied, from .exceptions import (AutoLabelingException, AutoLabelingPermissionDenied,
AWSTokenError, SampleDataException, AWSTokenError, SampleDataException,
TemplateMappingError, URLConnectionError) TemplateMappingError, URLConnectionError)
from .models import AutoLabelingConfig
from .serializers import (AutoLabelingConfigSerializer, get_annotation_serializer) from .serializers import (AutoLabelingConfigSerializer, get_annotation_serializer)

Loading…
Cancel
Save