Act as an expert Python and cloud deployment engineer. Write...
Prompt
Act as an expert Python and cloud deployment engineer. Write a Modal (modal.com) script that deploys a FastAPI web service to generate MIDI visualizer videos using midis2jam2 and GPU acceleration. Please ensure the script includes the following specific requirements: - Define a custom Modal Image that explicitly installs Python, FastAPI, FFmpeg, and the midis2jam2 dependencies via apt_install and pip_install. - Assign a GPU to the Modal function handling the rendering. - Use Modal's decorator to serve the FastAPI application. - Create a POST endpoint that accepts a .mid file via UploadFile. The function must save the uploaded file to a temporary directory in the Modal container, run the midis2jam2 subprocess using GPU-accelerated flags, and return the rendered .mp4 video as a FileResponse or streaming response. - Ensure the temporary files are deleted after the video is returned to prevent storage leaks, and include error handling for invalid file types or failed rendering processes.