pandora_transcribe/tasks.py
2025-01-24 20:54:25 +05:30

44 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
from datetime import datetime
import logging
from app.celery import app
from django.conf import settings
from item import utils
from item.models import Item
from taskqueue.models import Task
from user.models import User
from .transcribe import extract_subtitles
logger = logging.getLogger('pandora.' + __name__)
@app.task(queue='encoding')
def transcribe(**kwargs):
user = User.objects.get(username=kwargs["user"])
item = Item.objects.get(public_id=kwargs["item"])
subtitles = utils.get_by_key(settings.CONFIG['layers'], 'isSubtitles', True)['id']
gpu = getattr(settings, "TRANSCRIBE_GPU", False)
join_sentences = getattr(settings, "TRANSCRIBE_JOIN", False)
model = getattr(settings, "TRANSCRIBE_MODEL", "small")
translate = getattr(settings, "TRANSCRIBE_TRANSLATE", "")
task, created = Task.objects.get_or_create(item=item)
task.user = user
task.status = 'transcribing'
task.started = datetime.now()
task.save()
extract_subtitles(
item,
user,
subtitles,
translate,
gpu,
join_sentences=join_sentences,
model=model
)
task.ended = datetime.now()
task.status = 'finished'
task.save()