support for auto generation
Browse files
App/Transcription/TranscriptionRoutes.py
CHANGED
@@ -17,7 +17,7 @@ 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 |
|
@@ -123,6 +123,38 @@ async def delete_transcription(
|
|
123 |
}
|
124 |
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
@transcription_router.post("/uploadfile/")
|
127 |
async def create_file(
|
128 |
background_tasks: BackgroundTasks,
|
|
|
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,download_with_wget
|
21 |
import yt_dlp
|
22 |
from fastapi_jwt_auth import AuthJWT
|
23 |
|
|
|
123 |
}
|
124 |
|
125 |
|
126 |
+
@transcription_router.post("/url/")
|
127 |
+
async def create_file(
|
128 |
+
url: str,
|
129 |
+
model: str = Query(
|
130 |
+
"tiny",
|
131 |
+
enum=["tiny", "small", "medium", "base", "large-v2"],
|
132 |
+
description="Whisper model Sizes",
|
133 |
+
),
|
134 |
+
user: UserSchema = Depends(get_token_owner),
|
135 |
+
):
|
136 |
+
extension = 'wav'
|
137 |
+
file_name = f"{genUUID()}.{extension}"
|
138 |
+
|
139 |
+
download_with_wget(link=url,download_dir='./',filename=file_name)
|
140 |
+
# celery task
|
141 |
+
task = transcription_task.delay(file_name, model)
|
142 |
+
|
143 |
+
# create a transcription entry
|
144 |
+
transcription_enrty = await Transcriptions.objects.create(
|
145 |
+
task_id=task.id, user=user, file_name=file_name
|
146 |
+
)
|
147 |
+
|
148 |
+
return {
|
149 |
+
"file_name": file_name,
|
150 |
+
"task_id": task.id,
|
151 |
+
# "message_id": data.id,
|
152 |
+
}
|
153 |
+
|
154 |
+
|
155 |
+
|
156 |
+
|
157 |
+
|
158 |
@transcription_router.post("/uploadfile/")
|
159 |
async def create_file(
|
160 |
background_tasks: BackgroundTasks,
|
App/Transcription/Utils/fastapi_tasks.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1 |
from App import bot
|
2 |
from fastapi import UploadFile
|
3 |
from App.Transcription.Model import Transcriptions
|
|
|
4 |
|
5 |
-
|
6 |
-
async def perform_background_task(file_name:str,file: UploadFile, task_id: str):
|
7 |
data = await bot.send_file(
|
8 |
-
-1001925049183,
|
9 |
-
file_size=file.size,
|
10 |
-
caption=file.filename,
|
11 |
-
file=file_name
|
12 |
)
|
13 |
# get entry and update
|
14 |
entry: Transcriptions = await Transcriptions.objects.filter(task_id=task_id).first()
|
15 |
await entry.update(tl_file_id=str(data.id))
|
|
|
|
|
|
|
|
|
|
1 |
from App import bot
|
2 |
from fastapi import UploadFile
|
3 |
from App.Transcription.Model import Transcriptions
|
4 |
+
import subprocess
|
5 |
|
6 |
+
async def perform_background_task(file_name: str, file: UploadFile, task_id: str):
|
|
|
7 |
data = await bot.send_file(
|
8 |
+
-1001925049183, file_size=file.size, caption=file.filename, file=file_name
|
|
|
|
|
|
|
9 |
)
|
10 |
# get entry and update
|
11 |
entry: Transcriptions = await Transcriptions.objects.filter(task_id=task_id).first()
|
12 |
await entry.update(tl_file_id=str(data.id))
|
13 |
+
|
14 |
+
|
15 |
+
def download_with_wget(link, download_dir, filename):
|
16 |
+
subprocess.run(["aria2c", link, "-d", download_dir, "-o", filename])
|