使用 Modal 做 AI 影音示範 prompt

demo1.md

Example:

請產生一個 python script,可以執行以下任務。 請先不要執行這個 python script,我稍後會自己手動用 "modal run" 來執行。 任務: 製作10秒有聲影片: 內容需有以下海報文字" "2026第一屆趣味 AI 奧林匹亞競賽" 音樂: 加入科技感爵士風配樂。 旁白: "歡迎來到 2026 第一屆趣味 AI 奧林匹亞競賽。" 工作環境: * conda env (mednews) 裡的 python 3.12 * conda env (mednews) 裡的 modal 要求: * 旁白請用用台灣女生的語音。 * 要使用 NVIDIA GPU

Project

prompt 1: 測試 Modal

請產生一個 python script,可以執行以下任務。 請先不要執行這個 python script,我稍後會自己手動用 "modal run" 來執行。 我正在使用 VS Code,環境是: - Python 3.12 - Conda environment - 已安裝 modal - 已完成 Modal 登入 - 我要使用 NVIDIA GPU 任務: 請幫我建立一個最簡單的 Modal Python 範例: 1. 建立 app 2. 建立一個使用 GPU 的 function 3. 在 GPU function 裡使用 PyTorch 4. 印出 torch.cuda.is_available() 5. 印出 GPU 型號 6. 顯示 GPU VRAM 資訊 7. 本機執行時呼叫這個 remote function 請直接產生完整 Python 程式碼, 並告訴我檔名以及在 VS Code Terminal 要輸入的執行指令。 如果需要安裝 Python 套件,請使用 Modal Image 定義, 不要假設套件已經安裝在 Modal container 裡。

prompt 2: text-to-image

請產生一個 python script,可以執行以下任務。 請先不要執行這個 python script,我稍後會自己手動用 "modal run" 來執行。 請把目前的 Modal GPU 測試程式改造成 AI 圖像生成程式。 需求: - VS Code 開發 - Python 3.12 - Modal 執行 GPU workload - 使用 Hugging Face diffusers - 優先使用適合教學與推論的 text-to-image 模型 - GPU 使用 NVIDIA L40S - prompt 從 local function 傳入 remote GPU function - 生成 1024x1024 圖片 - 圖片存成 PNG - 最後把圖片結果傳回本機 測試 prompt: "A breathtaking wide-angle landscape photograph of rolling green grasslands on high plateau, Qingtiangang style, winding wooden post and rope trail through the lush grass, distant grazing water buffaloes, volcanic mountain hills under clear blue sky, fluffy white clouds, bright sunny day, soft golden sunlight, ultra-realistic, highly detailed, 8k resolution, shot on Sony A7R IV, 24mm lens" 請: 1. 先規劃檔案結構 2. 建立 Modal Image 3. 安裝 torch、diffusers、transformers 等必要套件 4. 正確設定 GPU 5. 載入模型 6. 執行 inference 7. 將生成圖片存回本機 output 資料夾 8. 提供完整可執行程式碼 另外請解釋哪些部分是在本機執行, 哪些部分是在 Modal GPU 上執行。

prompt 3: 使用 cache

請產生一個 python script,可以執行以下任務。 請先不要執行這個 python script,我稍後會自己手動用 "modal run" 來執行。 請 review 我目前使用 Modal + Hugging Face Diffusers 進行 AI 圖像生成的 Python 程式。 現在最大的問題是: 每次啟動 container 都可能重新下載模型, 造成啟動時間很久。 請幫我重構程式,使用 Modal Volume 建立 Hugging Face model cache。 需求: - 建立 persistent Volume - Hugging Face cache 儲存在 Volume - model 第一次下載後可以重複使用 - 使用 @modal.enter() 或適合的 Modal lifecycle 讓模型在 container 啟動時載入一次 - inference function 不要每次重新 load model - 保持程式適合初學者閱讀 另外請在程式碼中用註解標示: LOCAL REMOTE CPU REMOTE GPU CACHE MODEL LOADING INFERENCE 最後說明: 「沒有 cache」和「有 cache」的架構差異。

prompt 4: image-to-video

請產生一個 python script,可以執行以下任務。 請先不要執行這個 python script,我稍後會自己手動用 "modal run" 來執行。 我要在目前的 VS Code + Modal 專案加入 AI Video Generation。 請建立一個 image-to-video pipeline: 輸入: input.png 文字 prompt: "A vibrant rainbow gradually forms across the clear blue sky over the grassland, slowly appearing and becoming brighter and more vivid from left to right, gentle breeze swaying the grass softly, subtle clouds drifting, cinematic time-lapse lighting, natural atmospheric glow, photorealistic, 4k resolution, smooth motion." 輸出: 長度為 6 秒的 output.mp4 環境: - Python 3.12 - Modal - NVIDIA GPU - PyTorch - Hugging Face - diffusers - imageio / ffmpeg 請選擇一個目前適合 Hugging Face Diffusers 或 Transformers 生態系使用的 open-source image-to-video 模型。 請先檢查模型目前的官方使用方式, 不要使用已經過時的 API。 程式需求: 1. Modal GPU function 2. 模型 cache 3. input image 傳到 GPU container 4. 執行 image-to-video inference 5. 將 frames encode 成 MP4 6. MP4 傳回 VS Code 本機 7. 顯示 inference time 8. 顯示使用的 GPU 請先解釋架構,再產生完整程式碼。

prompt 5: pipeline

請產生一個 python script,可以執行以下任務。 請先不要執行這個 python script,我稍後會自己手動用 "modal run" 來執行。 請幫我把專案重構成一個完整 AI 影音生成 pipeline。 我要輸入: text-to-image prompt = """ A breathtaking wide-angle landscape photograph of rolling green grasslands on high plateau, Qingtiangang style, winding wooden post and rope trail through the lush grass, distant grazing water buffaloes, volcanic mountain hills under clear blue sky, fluffy white clouds, bright sunny day, soft golden sunlight, ultra-realistic, highly detailed, 4k resolution, shot on Sony A7R IV, 24mm lens """ image-to-video prompt = """ A vibrant rainbow gradually forms across the clear blue sky over the grassland, slowly appearing and becoming brighter and more vivid from left to right, gentle breeze swaying the grass softly, subtle clouds drifting, cinematic time-lapse lighting, natural atmospheric glow, photorealistic, 4k resolution, smooth motion. """ 系統自動完成: TEXT ↓ Text-to-Image ↓ image.png ↓ Image-to-Video ↓ video.mp4 技術環境: VS Code Python 3.12 Modal GPU PyTorch Hugging Face 請建立以下架構: project/ main.py image_generator.py video_generator.py config.py outputs/ 需求: - 圖像生成與影片生成分成不同 module - Modal GPU function 可以獨立測試 - Hugging Face models 使用 persistent cache - 每個階段顯示執行時間 - 有清楚的 exception handling - 自動建立 outputs 資料夾 - 檔名包含 timestamp - 不要把 API key 或 token 寫死在程式裡 - 使用 Modal Secret 管理需要的 token 請先產生 architecture plan。 確認 architecture 合理之後, 直接建立所有需要的 Python 程式碼。 程式碼以「教學可讀性」優先, 不要過度工程化。

這個網誌中的熱門文章

Q-EBM Search 網站的搜尋策略說明

在 MS Windows 系統跑 Claude Science 的方法(詳細安裝步驟)2026/7/11 更新版

線上課程:利用 Google 雲端免費額度,安裝您的專屬 Hermes Agent 全天候線上 AI 助理