Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling #36

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 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')):
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")
print("---------------------translation started-----------------------")
return JSONResponse(status_code=400, content={"message":"Invalid file type"})
#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)