testing
Browse files- App/Transcription/TranscriptionRoutes.py +5 -6
- App/Worker.py +14 -1
App/Transcription/TranscriptionRoutes.py
CHANGED
@@ -12,12 +12,12 @@ import aiofiles, os, re
|
|
12 |
import uuid
|
13 |
import tempfile
|
14 |
from celery.result import AsyncResult
|
15 |
-
from App.Worker import transcription_task, downloadfile
|
16 |
from App.Users.Model import User
|
17 |
from App.Users.UserRoutes import get_token_owner
|
18 |
from App.Users.Schemas import UserSchema
|
19 |
from .Model import Transcriptions
|
20 |
-
from .Utils.fastapi_tasks import perform_background_task
|
21 |
import yt_dlp
|
22 |
from fastapi_jwt_auth import AuthJWT
|
23 |
|
@@ -72,7 +72,7 @@ async def download_audio(
|
|
72 |
r"(?u)[^-\w.]", "", short_uuid
|
73 |
) # Ensure the title is file-friendly
|
74 |
filename = f"{sanitized_title}.mp3"
|
75 |
-
file_path = os.path.join("
|
76 |
|
77 |
ydl_opts = {
|
78 |
"format": "bestaudio/best",
|
@@ -135,10 +135,9 @@ async def create_file(
|
|
135 |
):
|
136 |
extension = 'wav'
|
137 |
file_name = f"{genUUID()}.{extension}"
|
138 |
-
|
139 |
-
download_with_wget(link=url,download_dir='./Downloads',filename=file_name)
|
140 |
# celery task
|
141 |
-
task =
|
142 |
|
143 |
# create a transcription entry
|
144 |
transcription_enrty = await Transcriptions.objects.create(
|
|
|
12 |
import uuid
|
13 |
import tempfile
|
14 |
from celery.result import AsyncResult
|
15 |
+
from App.Worker import transcription_task, downloadfile,downloadUrl
|
16 |
from App.Users.Model import User
|
17 |
from App.Users.UserRoutes import get_token_owner
|
18 |
from App.Users.Schemas import UserSchema
|
19 |
from .Model import Transcriptions
|
20 |
+
from .Utils.fastapi_tasks import perform_background_task
|
21 |
import yt_dlp
|
22 |
from fastapi_jwt_auth import AuthJWT
|
23 |
|
|
|
72 |
r"(?u)[^-\w.]", "", short_uuid
|
73 |
) # Ensure the title is file-friendly
|
74 |
filename = f"{sanitized_title}.mp3"
|
75 |
+
file_path = os.path.join("./", "Downloads", filename)
|
76 |
|
77 |
ydl_opts = {
|
78 |
"format": "bestaudio/best",
|
|
|
135 |
):
|
136 |
extension = 'wav'
|
137 |
file_name = f"{genUUID()}.{extension}"
|
138 |
+
file_dir = os.path.join("./", "Downloads")
|
|
|
139 |
# celery task
|
140 |
+
task = downloadUrl.delay(link=url, download_dir=file_dir, filename=file_name, model_size=model)
|
141 |
|
142 |
# create a transcription entry
|
143 |
transcription_enrty = await Transcriptions.objects.create(
|
App/Worker.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from celery import Celery, chain
|
2 |
import os
|
3 |
-
import time
|
4 |
import cgi
|
5 |
from App import celery_config
|
6 |
import yt_dlp
|
@@ -22,6 +22,19 @@ def generate_store(self, data, task_id):
|
|
22 |
encode(chunks)
|
23 |
print("hellooo")
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
@celery.task(name="transcription", bind=True)
|
27 |
def transcription_task(self, file_path, model_size="tiny"):
|
|
|
1 |
from celery import Celery, chain
|
2 |
import os
|
3 |
+
import time,subprocess
|
4 |
import cgi
|
5 |
from App import celery_config
|
6 |
import yt_dlp
|
|
|
22 |
encode(chunks)
|
23 |
print("hellooo")
|
24 |
|
25 |
+
def download_with_wget(link, download_dir, filename):
|
26 |
+
subprocess.run(["aria2c", link, "-d", download_dir, "-o", filename])
|
27 |
+
|
28 |
+
@celery.task(name="download", bind=True)
|
29 |
+
def downloadUrl(self, link, download_dir, filename, model_size="base"):
|
30 |
+
file_path=os.path.join(download_dir,filename)
|
31 |
+
download_with_wget(link=link,download_dir=download_dir,filename=filename)
|
32 |
+
|
33 |
+
data = transcribe_file(state=self, file_path=file_path, model_size=model_size)
|
34 |
+
generate_store.delay(data["content"], self.request.id)
|
35 |
+
return data
|
36 |
+
|
37 |
+
|
38 |
|
39 |
@celery.task(name="transcription", bind=True)
|
40 |
def transcription_task(self, file_path, model_size="tiny"):
|