From 5b3f540720c4ed3deb1083b9980cff38d6d12df7 Mon Sep 17 00:00:00 2001 From: allholy Date: Thu, 16 Jan 2025 11:50:51 +0100 Subject: [PATCH 1/2] Add ai field to model and description form --- apiv2/serializers.py | 7 ++++++- sounds/admin.py | 2 +- sounds/forms.py | 2 ++ sounds/models.py | 3 +++ sounds/views.py | 2 ++ templates/sounds/edit_and_describe.html | 5 +++++ utils/sound_upload.py | 3 +++ 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apiv2/serializers.py b/apiv2/serializers.py index 523e2acba..578a0fabd 100644 --- a/apiv2/serializers.py +++ b/apiv2/serializers.py @@ -42,7 +42,7 @@ DEFAULT_FIELDS_IN_SOUND_DETAIL = 'id,url,name,tags,description,bst_category,geotag,created,license,type,channels,filesize,bitrate,' + \ 'bitdepth,duration,samplerate,username,pack,pack_name,download,bookmark,previews,images,' + \ 'num_downloads,avg_rating,num_ratings,rate,comments,num_comments,comment,similar_sounds,' + \ -'analysis,analysis_frames,analysis_stats,is_explicit' # All except for analyzers +'analysis,analysis_frames,analysis_stats,is_explicit,is_gen_ai' # All except for analyzers DEFAULT_FIELDS_IN_PACK_DETAIL = None # Separated by commas (None = all) @@ -132,6 +132,7 @@ class Meta: 'ac_analysis', # Kept for legacy reasons only as it is also contained in 'analyzers_output' 'analyzers_output', 'is_explicit', + 'is_gen_ai', 'score', ) @@ -312,6 +313,10 @@ def get_analyzers_output(self, obj): is_explicit = serializers.SerializerMethodField() def get_is_explicit(self, obj): return obj.is_explicit + + is_gen_ai = serializers.SerializerMethodField() + def get_is_gen_ai(self, obj): + return obj.is_gen_ai class SoundListSerializer(AbstractSoundSerializer): diff --git a/sounds/admin.py b/sounds/admin.py index 73f8550bc..434c05019 100644 --- a/sounds/admin.py +++ b/sounds/admin.py @@ -49,7 +49,7 @@ class SoundAdmin(DjangoObjectActions, admin.ModelAdmin): ('User defined fields', {'fields': ('description', 'license', 'original_filename', 'bst_category', 'sources', 'pack')}), ('File properties', {'fields': ('md5', 'type', 'duration', 'bitrate', 'bitdepth', 'samplerate', 'filesize', 'channels', 'date_recorded')}), - ('Moderation', {'fields': ('moderation_state', 'moderation_date', 'has_bad_description', 'is_explicit')}), + ('Moderation', {'fields': ('moderation_state', 'moderation_date', 'has_bad_description', 'is_explicit', 'is_gen_ai')}), ('Processing', {'fields': ('processing_state', 'processing_date', 'processing_ongoing_state', 'processing_log', 'similarity_state')}), ) raw_id_fields = ('user', 'pack', 'sources') diff --git a/sounds/forms.py b/sounds/forms.py index cd23d441b..4b3a11f8d 100644 --- a/sounds/forms.py +++ b/sounds/forms.py @@ -260,6 +260,7 @@ class SoundEditAndDescribeForm(forms.Form): help_text="You can add timestamps to the description using the syntax #minute:second (e.g. \"#1:07 nice bird chirp\"). " "This will be rendered with a little play button to play the sound at that timestamp. " + HtmlCleaningCharField.make_help_text()) is_explicit = forms.BooleanField(required=False, label="The sound contains explicit content") + is_gen_ai = forms.BooleanField(required=False, label="The sound involves generative AI") license_qs = License.objects.filter(Q(name__istartswith='Attribution') | Q(name__istartswith='Creative')) license = forms.ModelChoiceField(queryset=license_qs, required=True, widget=forms.RadioSelect()) pack = forms.ChoiceField(label="Select a pack for this sound:", choices=[], required=False) @@ -292,6 +293,7 @@ def __init__(self, *args, **kwargs): user_packs = kwargs.pop('user_packs', False) super().__init__(*args, **kwargs) self.fields['is_explicit'].widget.attrs['class'] = 'bw-checkbox' + self.fields['is_gen_ai'].widget.attrs['class'] = 'bw-checkbox' self.fields['remove_geotag'].widget.attrs['class'] = 'bw-checkbox' self.fields['license'].widget.attrs['class'] = 'bw-radio' diff --git a/sounds/models.py b/sounds/models.py index d95006eb9..c779fe662 100644 --- a/sounds/models.py +++ b/sounds/models.py @@ -434,6 +434,7 @@ def bulk_query_solr(self, sound_ids): sound.original_filename, sound.bst_category, sound.is_explicit, + sound.is_gen_ai, sound.filesize, sound.md5, sound.channels, @@ -493,6 +494,7 @@ def bulk_query(self, where, order_by, limit, args, include_analyzers_output=Fals sound.original_filename, sound.bst_category, sound.is_explicit, + sound.is_gen_ai, sound.avg_rating, sound.channels, sound.filesize, @@ -659,6 +661,7 @@ class Sound(models.Model): moderation_note = models.TextField(null=True, blank=True, default=None) has_bad_description = models.BooleanField(default=False) is_explicit = models.BooleanField(default=False) + is_gen_ai = models.BooleanField(default=False) # processing PROCESSING_STATE_CHOICES = ( diff --git a/sounds/views.py b/sounds/views.py index f09214b6b..d31396dcb 100644 --- a/sounds/views.py +++ b/sounds/views.py @@ -437,6 +437,7 @@ def create_sounds(request, forms): 'description': form.cleaned_data.get('description', ''), 'tags': form.cleaned_data.get('tags', ''), 'is_explicit': form.cleaned_data['is_explicit'], + 'is_gen_ai': form.cleaned_data['is_gen_ai'], } pack = form.cleaned_data.get('pack', False) @@ -490,6 +491,7 @@ def create_sounds(request, forms): def update_edited_sound(sound, data): sound.is_explicit = data["is_explicit"] + sound.is_gen_ai = data["is_gen_ai"] sound.set_tags(data["tags"]) sound.description = remove_control_chars(data["description"]) sound.original_filename = data["name"] diff --git a/templates/sounds/edit_and_describe.html b/templates/sounds/edit_and_describe.html index 6650dd683..07c95b044 100644 --- a/templates/sounds/edit_and_describe.html +++ b/templates/sounds/edit_and_describe.html @@ -89,6 +89,11 @@
Basic information
{{ form.is_explicit.label_tag }} {{ form.is_explicit }} +
+ {{ form.is_gen_ai.errors }} + {{ form.is_gen_ai.label_tag }} + {{ form.is_gen_ai }} +
diff --git a/utils/sound_upload.py b/utils/sound_upload.py index 0a7b61cd7..9eec92974 100644 --- a/utils/sound_upload.py +++ b/utils/sound_upload.py @@ -254,6 +254,9 @@ def create_sound(user, if 'is_explicit' in sound_fields: sound.is_explicit = sound_fields['is_explicit'] + if 'is_gen_ai' in sound_fields: + sound.is_gen_ai = sound_fields['is_gen_ai'] + # 6.5 set uploaded apiv2 client or bulk progress object (if any) sound.uploaded_with_apiv2_client = apiv2_client sound.uploaded_with_bulk_upload_progress = bulk_upload_progress From a3ad619998afc897ec9d044b42a64e8481afbb42 Mon Sep 17 00:00:00 2001 From: allholy Date: Thu, 16 Jan 2025 15:36:34 +0100 Subject: [PATCH 2/2] Migration of ai field --- sounds/migrations/0055_sound_is_gen_ai.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sounds/migrations/0055_sound_is_gen_ai.py diff --git a/sounds/migrations/0055_sound_is_gen_ai.py b/sounds/migrations/0055_sound_is_gen_ai.py new file mode 100644 index 000000000..30de4a8b9 --- /dev/null +++ b/sounds/migrations/0055_sound_is_gen_ai.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2025-01-16 15:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sounds', '0054_alter_sound_bst_category'), + ] + + operations = [ + migrations.AddField( + model_name='sound', + name='is_gen_ai', + field=models.BooleanField(default=False), + ), + ]