api/tasks
This commit is contained in:
parent
cb7514d988
commit
ade9a049c2
3 changed files with 79 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
45
tasks.py
Normal file
45
tasks.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from app.celery import app
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from item import utils
|
||||||
|
from user.models import User
|
||||||
|
from item.models import Item
|
||||||
|
|
||||||
|
from . import transcribe
|
||||||
|
|
||||||
|
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(layers, 'isSubtitles', True)
|
||||||
|
|
||||||
|
gpu = getattr(settings, "TRANSCRIBE_GPU", False)
|
||||||
|
join_sentences = getattr(settings, "TRANSCRIBE_JOIN", False)
|
||||||
|
model = getattr(settings, "TRANSCRIBE_MODEL", "small")
|
||||||
|
translate = getattr(settings, "TRANSCRIBE_TRANSLATE", "")
|
||||||
|
logger.error(
|
||||||
|
"transcribe %s %s %s %s %s %s %s",
|
||||||
|
item,
|
||||||
|
user,
|
||||||
|
subtitles,
|
||||||
|
translate,
|
||||||
|
gpu,
|
||||||
|
join_sentences,
|
||||||
|
model
|
||||||
|
)
|
||||||
|
|
||||||
|
transcribe.extract_subtitles(
|
||||||
|
item,
|
||||||
|
user,
|
||||||
|
subtitles,
|
||||||
|
translate,
|
||||||
|
gpu,
|
||||||
|
join_sentences=join_sentences,
|
||||||
|
model=model
|
||||||
|
)
|
32
views.py
Normal file
32
views.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from oxdjango.decorators import login_required_json
|
||||||
|
from oxdjango.shortcuts import render_to_json_response, get_object_or_404_json, json_response
|
||||||
|
|
||||||
|
from item.models import Item
|
||||||
|
from oxdjango.api import actions
|
||||||
|
from user.models import has_capability
|
||||||
|
|
||||||
|
from . import tasks
|
||||||
|
|
||||||
|
|
||||||
|
@login_required_json
|
||||||
|
def transcribeAudio(request, data):
|
||||||
|
'''
|
||||||
|
Transcribe audio and add to subtitles layer
|
||||||
|
takes {
|
||||||
|
item: string // item id
|
||||||
|
}
|
||||||
|
returns {
|
||||||
|
item: id // item id
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
response = {}
|
||||||
|
item = get_object_or_404_json(Item, public_id=data["item"])
|
||||||
|
if has_capability(request.user, 'canTranscribeAudio') and item.editalbe(request.user):
|
||||||
|
t = tasks.transcribe.delay(item=data["item"], user=request.user.username)
|
||||||
|
response["taskId"] = t.task_id
|
||||||
|
else:
|
||||||
|
response = json_response(status=403, text='permission denied')
|
||||||
|
return render_to_json_response(response)
|
||||||
|
actions.register(transcribeAudio, cache=False)
|
Loading…
Add table
Reference in a new issue