fastapi program getting 504 getaway timeout when testing Azure container app in postman

61 views Asked by At

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")
1

There are 1 answers

0
Sampath On

I followed this document to deploy a Flask or FastAPI web app as a container in Azure Container Apps, using Python on Azure.

enter image description here

az acr build --resource-group reosuregroupname --registry registryName --image imadename:tag.

enter image description here

enter image description here

enter image description here

The code reference from git enter image description here

The code for Azure AI Translator in Azure AI services can be found in this doc.


@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}")

    # Translate the transcription to French and Zulu
    translated_text = translate_text(Transcription)
    fr_translation = translated_text[0]['translations'][0]['text']
    zu_translation = translated_text[0]['translations'][1]['text']

    # Further processing for video frames with translated text
    # Assuming you have a function text_to_frames() for this purpose

    frames_with_characters = await text_to_frames(f"{fr_translation} {zu_translation}", 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")

enter image description here

enter image description here

enter image description here