From f5af8263545a5f10760ac581e519d3b4a1a79f06 Mon Sep 17 00:00:00 2001 From: Sharyu Marwadi Date: Sat, 5 Oct 2024 10:09:16 +0530 Subject: [PATCH 1/2] error fixed and .ogg extension added --- service/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/main.py b/service/main.py index cf5afb4..2d46c4b 100644 --- a/service/main.py +++ b/service/main.py @@ -30,9 +30,9 @@ async def upload_audio(body: Body): try: print("----------audio file link-----------",body.audio_file_link,"-----------------------") # Check file type - if not body.audio_file_link.endswith(('.m4a', '.mp4','.mp3','.webm','.mpga','.wav','.mpeg')): + if not body.audio_file_link.endswith(('.m4a', '.mp4','.mp3','.webm','.mpga','.wav','.mpeg','.ogg')): logger.error("invalid file type") - raise HTTPException(status_code=400, detail="Invalid file type") + return JSONResponse(status_code=400, content={"message":"Invalid file type"}) print("---------------------translation started-----------------------") #translation = translate_with_whisper(transcription) translation = translate_with_whisper(body.audio_file_link) From b83a8e79ce37e2e90c22453e1cb2b290b37c4440 Mon Sep 17 00:00:00 2001 From: Sharyu Marwadi Date: Sat, 5 Oct 2024 11:45:18 +0530 Subject: [PATCH 2/2] Invalid file link error added --- service/main.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/service/main.py b/service/main.py index 2d46c4b..8f1c433 100644 --- a/service/main.py +++ b/service/main.py @@ -26,19 +26,18 @@ class Body(BaseModel): @app.post("/upload-audio") async def upload_audio(body: Body): - print("------------body--------------",body,"--------------------------") try: - print("----------audio file link-----------",body.audio_file_link,"-----------------------") + #check if string is empty + if body.audio_file_link == "": + return JSONResponse(status_code=400, content={"message":"Invalid file link"}) # Check file type if not body.audio_file_link.endswith(('.m4a', '.mp4','.mp3','.webm','.mpga','.wav','.mpeg','.ogg')): logger.error("invalid file type") return JSONResponse(status_code=400, content={"message":"Invalid file type"}) - print("---------------------translation started-----------------------") #translation = translate_with_whisper(transcription) translation = translate_with_whisper(body.audio_file_link) logger.info("translation done") - print("---------------------summary started-----------------------") #summary = summarize_using_openai(translation) summary = summarize_using_openai(translation) @@ -47,5 +46,4 @@ async def upload_audio(body: Body): return JSONResponse(content={"message": "File processed successfully!", "translation":translation, "summary": summary}, status_code=200) except Exception as e: - print("---------------",e,"-------------------") return JSONResponse(content={"message": str(e)}, status_code=500)