Skip to content

Gecko in Doccano #11

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'server/templates')],
'DIRS': [
os.path.join(BASE_DIR, 'server/templates'),
os.path.join(BASE_DIR, 'server/node_modules')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -95,6 +98,7 @@

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'server/static'),
os.path.join(BASE_DIR, 'server/node_modules/gecko/build_external')
]

STATICFILES_STORAGE = 'app.storage.CompressedManifestStaticFilesStorage'
Expand Down
42 changes: 42 additions & 0 deletions app/server/migrations/0019_auto_20190904_2336.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 2.1.5 on 2019-09-04 23:36

from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('server', '0018_project_shuffle_documents'),
]

operations = [
migrations.CreateModel(
name='AudioLabelingAnnotation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('prob', models.FloatField(blank=True, default=None, null=True)),
('manual', models.BooleanField(default=False)),
('created_date_time', models.DateTimeField(auto_now_add=True)),
('updated_date_time', models.DateTimeField(auto_now=True)),
('done', models.BooleanField(default=False)),
('file_name', models.TextField(blank=True)),
('file_path', models.TextField(blank=True)),
('data', django.contrib.postgres.fields.jsonb.JSONField()),
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='audio_labeling_annotations', to='server.Document')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AlterField(
model_name='project',
name='project_type',
field=models.CharField(choices=[('DocumentClassification', 'document classification'), ('SequenceLabeling', 'sequence labeling'), ('Seq2seq', 'sequence to sequence'), ('ImageClassification', 'image classification'), ('ImageCaptioning', 'image captioning'), ('AudioLabeling', 'audio labeling (Gecko test)')], max_length=30),
),
migrations.AlterUniqueTogether(
name='audiolabelingannotation',
unique_together={('document', 'user')},
),
]
18 changes: 18 additions & 0 deletions app/server/migrations/0020_auto_20191031_1449.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.5 on 2019-10-31 14:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('server', '0019_auto_20190904_2336'),
]

operations = [
migrations.AlterField(
model_name='project',
name='project_type',
field=models.CharField(choices=[('DocumentClassification', 'document classification'), ('SequenceLabeling', 'sequence labeling'), ('Seq2seq', 'sequence to sequence'), ('ImageClassification', 'image classification'), ('ImageCaptioning', 'image captioning'), ('AudioLabeling', 'audio labeling (Gecko test)'), ('ConversationClassification', 'conversation classification')], max_length=30),
),
]
18 changes: 18 additions & 0 deletions app/server/migrations/0021_auto_20191105_1553.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.5 on 2019-11-05 15:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('server', '0020_auto_20191031_1449'),
]

operations = [
migrations.AlterField(
model_name='audiolabelingannotation',
name='data',
field=models.TextField(blank=True),
),
]
14 changes: 14 additions & 0 deletions app/server/migrations/0023_merge_20200604_0909.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.1.5 on 2020-06-04 09:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('server', '0021_auto_20191105_1553'),
('server', '0022_auto_20200317_0301'),
]

operations = [
]
29 changes: 29 additions & 0 deletions app/server/migrations/0024_auto_20200607_1709.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.1.5 on 2020-06-07 17:09

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('server', '0023_merge_20200604_0909'),
]

operations = [
migrations.AddField(
model_name='audiolabelingannotation',
name='additional_data',
field=models.TextField(default='{}'),
),
migrations.AlterField(
model_name='project',
name='project_type',
field=models.CharField(choices=[('DocumentClassification', 'document classification'), ('SequenceLabelingAlt', 'sequence labeling Alt'), ('SequenceLabeling', 'sequence labeling'), ('Seq2seq', 'sequence to sequence'), ('ImageClassification', 'image classification'), ('ImageCaptioning', 'image captioning'), ('AudioLabeling', 'audio labeling (Gecko test)'), ('ConversationClassification', 'conversation classification')], max_length=30),
),
migrations.AlterUniqueTogether(
name='audiolabelingannotation',
unique_together={('document', 'user', 'file_path')},
),
]
33 changes: 33 additions & 0 deletions app/server/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from django.core.exceptions import ValidationError
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db.models import Q, Count
from django.urls import reverse
Expand All @@ -16,6 +17,7 @@ class Project(models.Model):

SEQUENCE_LABELING_ALT = 'SequenceLabelingAlt'
Seq2seq = 'Seq2seq'
AudioLabeling = 'AudioLabeling'

PROJECT_CHOICES = ((k, v['title']) for k,v in project_types.items())

Expand Down Expand Up @@ -105,6 +107,10 @@ def get_documents_kwargs(self, user, labels=None):
ret["seq_annotations__user"] = user
if (labels):
ret[ "seq_annotations__label__in"] = labels
elif self.is_type_of(Project.AudioLabeling):
ret["audio_labeling_annotations__user"] = user
if (labels):
ret[ "audio_labeling_annotations__label__in"] = labels
else:
print('Project type: '+self.project_type)
raise ValueError('Invalid project_type')
Expand Down Expand Up @@ -167,6 +173,11 @@ def get_documents(self, is_null=True, user=None):
docs = docs.exclude(seq2seq_annotations__user=user)
else:
docs = docs.filter(seq2seq_annotations__isnull=is_null)
elif self.is_type_of(Project.AudioLabeling):
if user:
docs = docs.exclude(audio_labeling_annotations__user=user)
else:
docs = docs.filter(audio_labeling_annotations__isnull=is_null)
else:
print('Project type: '+self.project_type)
raise ValueError('Invalid project_type')
Expand All @@ -183,6 +194,7 @@ def get_document_serializer(self):
from .serializers import ClassificationDocumentSerializer
from .serializers import SequenceDocumentSerializer
from .serializers import Seq2seqDocumentSerializer
from .serializers import AudioDocumentSerializer
if self.is_type_of(Project.DOCUMENT_CLASSIFICATION):
return ClassificationDocumentSerializer
elif self.is_type_of(Project.SEQUENCE_LABELING_ALT):
Expand All @@ -191,13 +203,16 @@ def get_document_serializer(self):
return SequenceDocumentSerializer
elif self.is_type_of(Project.Seq2seq):
return Seq2seqDocumentSerializer
elif self.is_type_of(Project.AudioLabeling):
return AudioDocumentSerializer
else:
raise ValueError('Invalid project_type')

def get_annotation_serializer(self):
from .serializers import DocumentAnnotationSerializer
from .serializers import SequenceAnnotationSerializer
from .serializers import Seq2seqAnnotationSerializer
from .serializers import AudioAnnotationSerializer
if self.is_type_of(Project.DOCUMENT_CLASSIFICATION):
return DocumentAnnotationSerializer
elif self.is_type_of(Project.SEQUENCE_LABELING_ALT):
Expand All @@ -206,6 +221,8 @@ def get_annotation_serializer(self):
return SequenceAnnotationSerializer
elif self.is_type_of(Project.Seq2seq):
return Seq2seqAnnotationSerializer
elif self.is_type_of(Project.AudioLabeling):
return AudioAnnotationSerializer

def get_annotation_class(self):
if self.is_type_of(Project.DOCUMENT_CLASSIFICATION):
Expand All @@ -216,6 +233,10 @@ def get_annotation_class(self):
return SequenceAnnotation
elif self.is_type_of(Project.Seq2seq):
return Seq2seqAnnotation
elif self.is_type_of(Project.Seq2seq):
return Seq2seqAnnotation
elif self.is_type_of(Project.AudioLabeling):
return AudioLabelingAnnotation

def __str__(self):
return self.name
Expand Down Expand Up @@ -387,6 +408,8 @@ def get_annotations(self):
return self.seq_annotations.all()
elif self.project.is_type_of(Project.Seq2seq):
return self.seq2seq_annotations.all()
elif self.project.is_type_of(Project.AudioLabeling):
return self.audio_labeling_annotations.all()

def to_csv(self):
return self.make_dataset()
Expand Down Expand Up @@ -534,3 +557,13 @@ class Seq2seqAnnotation(Annotation):

class Meta:
unique_together = ('document', 'user', 'text')

class AudioLabelingAnnotation(Annotation):
document = models.ForeignKey(Document, related_name='audio_labeling_annotations', on_delete=models.CASCADE)
done = models.BooleanField(default=False)
file_name = models.TextField(blank=True)
file_path = models.TextField(blank=True)
data = models.TextField(blank=True)

class Meta:
unique_together = ('document', 'user', 'file_path')
Loading