fastapi 程序在邮递员中测试 Azure 容器应用程序时出现 504 超时超时

问题描述 投票:0回答:1

我有一个在 Azure 容器应用程序上运行的 fastapi 程序,该程序有一个需要几分钟才能响应的 post 端点(包括对 openai 等的多个 api 调用)。

当我使用邮递员在本地运行它时,它会在预期的时间内得到响应。

但是当使用 azure 运行时,在最初的几分钟之后,我在邮递员中收到此响应:流超时和 504 getaway 超时。 此外,当在天蓝色中跟踪日志流时,连接会停止,当我重新启动它时,它会继续显示登录,就好像程序仍在运行一样。

这是我尝试测试的端点的片段:

@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")
docker postman fastapi http-status-code-504 azure-container-apps
1个回答
0
投票

我按照本文档在 Azure 上使用 Python 将 Flask 或 FastAPI Web 应用程序部署为 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

代码参考来自git enter image description here

Azure AI 服务中 Azure AI Translator 的代码可以在此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

© www.soinside.com 2019 - 2024. All rights reserved.