Skip to content

Commit

Permalink
Invalid file link error added
Browse files Browse the repository at this point in the history
  • Loading branch information
SharyuMarwadi committed Oct 5, 2024
1 parent f5af826 commit b83a8e7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

0 comments on commit b83a8e7

Please sign in to comment.