task_id
Browse files
App/Transcription/TranscriptionRoutes.py
CHANGED
@@ -7,6 +7,7 @@ from celery.result import AsyncResult
|
|
7 |
from App.Worker import transcription_task
|
8 |
from App.Users.Model import User
|
9 |
from .Model import Transcriptions
|
|
|
10 |
|
11 |
# from .Model import User
|
12 |
# from sqlalchemy import and_
|
@@ -17,6 +18,7 @@ transcription_router = APIRouter(tags=["User"])
|
|
17 |
|
18 |
@transcription_router.post("/uploadfile/")
|
19 |
async def create_file(
|
|
|
20 |
file: UploadFile,
|
21 |
userId: int = 1,
|
22 |
model: str = Query(
|
@@ -54,6 +56,7 @@ async def create_file(
|
|
54 |
transcription_enrty = await Transcriptions.objects.create(
|
55 |
task_id=task.id, user=user
|
56 |
)
|
|
|
57 |
return {
|
58 |
"file_size": file.size,
|
59 |
"file_name": file.filename,
|
@@ -76,5 +79,6 @@ async def get_status(task_id):
|
|
76 |
"task_id": task_id,
|
77 |
"task_status": task_result.status,
|
78 |
"task_result": task_result.result,
|
|
|
79 |
}
|
80 |
return result
|
|
|
7 |
from App.Worker import transcription_task
|
8 |
from App.Users.Model import User
|
9 |
from .Model import Transcriptions
|
10 |
+
from .Utils.fastapi_tasks import perform_background_task
|
11 |
|
12 |
# from .Model import User
|
13 |
# from sqlalchemy import and_
|
|
|
18 |
|
19 |
@transcription_router.post("/uploadfile/")
|
20 |
async def create_file(
|
21 |
+
background_tasks: BackgroundTasks,
|
22 |
file: UploadFile,
|
23 |
userId: int = 1,
|
24 |
model: str = Query(
|
|
|
56 |
transcription_enrty = await Transcriptions.objects.create(
|
57 |
task_id=task.id, user=user
|
58 |
)
|
59 |
+
background_tasks.add_task(perform_background_task, file=file, task_id=task.id)
|
60 |
return {
|
61 |
"file_size": file.size,
|
62 |
"file_name": file.filename,
|
|
|
79 |
"task_id": task_id,
|
80 |
"task_status": task_result.status,
|
81 |
"task_result": task_result.result,
|
82 |
+
"id": entry.tl_file_id,
|
83 |
}
|
84 |
return result
|
App/Transcription/Utils/fastapi_tasks.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from App import bot
|
2 |
+
from fastapi import UploadFile
|
3 |
+
from ..Model import Transcriptions
|
4 |
+
|
5 |
+
|
6 |
+
async def perform_background_task(file: UploadFile, task_id: str):
|
7 |
+
data = await bot.send_file(
|
8 |
+
-1001925049183,
|
9 |
+
file_size=file.size,
|
10 |
+
caption=file.filename,
|
11 |
+
file=f"./{file.filename}",
|
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=data.id)
|