I have a fastapi program runing on Azure container app that has a post endpoint that takes some minutes to response (includes several api calls to openai etc.).
When I run it localy, using postman, it gets me the response in the expected time.
But when runing with azure, after the first few minutes, I get this response in postman: stream timeout, and 504 getaway timeout. Also when following the log stream in azure, the connection stops, and when I restart it, it keeps showing the loggins as if the program is still runing.
Here is a snippet of the endpoint im trying to test:
@app.post("/transcribe")
async def transcribe(audio: UploadFile = File(...), song_name: str = Query(default=None),
singer: str = Query(default=None)):
log_event("INFO", f"New API call was made for song '{song_name}' by {singer}!")
# Generate the first image for the video based on the song name and singer
generate_first_image(song_name, singer)
Transcription, duration_seconds, temp_audio_path = await audio_to_text(audio)
log_event("INFO", f"Transcription: {Transcription}")
frames_with_characters = await text_to_frames(Transcription, duration_seconds)
log_event("INFO", f"Frames with characters: {frames_with_characters}")
video_path = generate_final_video(frames_with_characters, temp_audio_path)
# Remove temporary files
os.remove(temp_audio_path)
# Clean up temporary storage
clean_temporary_storage()
return FileResponse(path=video_path, media_type='video/mp4', filename="final_video.mp4")
I followed this document to deploy a Flask or FastAPI web app as a container in Azure Container Apps, using Python on Azure.
az acr build --resource-group reosuregroupname --registry registryName --image imadename:tag.The code reference from git
The code for Azure AI Translator in Azure AI services can be found in this doc.