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 services.whisper_service import WhisperService
3
- from models.schema import TranscriptionResponse
4
 
 
 
 
 
5
 
6
- class TranscriptionController:
7
- def __init__(self):
8
- self.whisper_service = WhisperService()
 
 
 
 
9
 
10
- async def transcribe_audio(self, audio_file: bytes, output_language: str = None) -> TranscriptionResponse:
11
- try:
12
- result = await self.whisper_service.transcribe(audio_file, output_language)
13
- return TranscriptionResponse(**result)
14
- except Exception as e:
15
- raise HTTPException(status_code=500, detail=str(e))
 
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