Update controllers/transcription_controller.py
#1
by
Omkar008
- opened
controllers/transcription_controller.py
CHANGED
@@ -1,15 +1,23 @@
|
|
1 |
-
from fastapi import HTTPException
|
2 |
-
from
|
3 |
-
from models
|
4 |
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
1 |
+
from fastapi import UploadFile, HTTPException
|
2 |
+
from tempfile import NamedTemporaryFile
|
3 |
+
from models import transcribe_audio
|
4 |
|
5 |
+
async def process_uploaded_files(files: list[UploadFile]):
|
6 |
+
"""Processes a list of uploaded files and returns transcription results."""
|
7 |
+
if not files:
|
8 |
+
raise HTTPException(status_code=400, detail="No files were provided")
|
9 |
|
10 |
+
results = []
|
11 |
+
for file in files:
|
12 |
+
with NamedTemporaryFile(delete=True) as temp:
|
13 |
+
with open(temp.name, "wb") as temp_file:
|
14 |
+
temp_file.write(file.file.read())
|
15 |
+
|
16 |
+
transcript = transcribe_audio(temp.name)
|
17 |
|
18 |
+
results.append({
|
19 |
+
'filename': file.filename,
|
20 |
+
'transcript': transcript,
|
21 |
+
})
|
22 |
+
|
23 |
+
return results
|