Skip to content

Commit

Permalink
Merge branch 'ai_field' into bst_field
Browse files Browse the repository at this point in the history
  • Loading branch information
allholy committed Jan 16, 2025
2 parents d2084d8 + a3ad619 commit eeb6d22
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2 deletions.
7 changes: 6 additions & 1 deletion apiv2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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',
)

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion sounds/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions sounds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,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)
Expand Down Expand Up @@ -293,6 +294,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'

Expand Down
18 changes: 18 additions & 0 deletions sounds/migrations/0055_sound_is_gen_ai.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
3 changes: 3 additions & 0 deletions sounds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = (
Expand Down
2 changes: 2 additions & 0 deletions sounds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions templates/sounds/edit_and_describe.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ <h5 class="text-light-grey v-spacing-2">Basic information</h5>
{{ form.is_explicit.label_tag }}
{{ form.is_explicit }}
</div>
<div class="v-spacing-top-2">
{{ form.is_gen_ai.errors }}
{{ form.is_gen_ai.label_tag }}
{{ form.is_gen_ai }}
</div>
</div>

<div class="v-spacing-2">
Expand Down
3 changes: 3 additions & 0 deletions utils/sound_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eeb6d22

Please sign in to comment.