ComfyUI Extension: ComfyUI-LoRA-Captioner

Authored by JetterTW

Created

Updated

1 stars

Run ComfyUI workflows without the setup

No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.

A custom ComfyUI node designed for LoRA training that integrates local LLM APIs to automatically generate high-quality, multilingual captions in English, Traditional Chinese, and Simplified Chinese with customizable system prompts and configurable parameters. (Description by CC)

Looking for a different extension?

Custom Nodes (0)

    README

    ComfyUI-LoRA-Caption-Generator

    Version License Author

    這是一個專為 LoRA 訓練設計的 ComfyUI 自定義節點。它能透過整合本地 LLM API(如 LM Studio, Ollama 或 OpenAI 格式之 API),自動為訓練圖片生成高品質、多語言(英文、繁體中文、簡體中文)的標籤(Captions/Labels)。

    ✨ 功能特點

    • 多語言同步輸出:一次請求即可同時獲得英文、繁體中文、簡體中文描述,方便進行不同語系的訓練或標註。
    • 模型風格自定義:內建 prompts.json 配置系統,可針對不同底模(如 Flux 的自然語言、SDXL 的標籤風格)切換不同的系統提示詞。
    • 高度可配置參數:支援調整 Temperature、Max Tokens、Seed 等參數,精確控制生成內容的創意度與隨機性。
    • JSON 結構化輸出:採用強制的 JSON 輸出格式,確保數據解析的穩定性,不會因為 LLM 的廢話而導致節點報錯。
    • 輕量化設計:與本地 LLM API 接軌,無需額外消耗雲端算力,隱私與成本兼具。

    🚀 安裝方法

    1. 進入您的 ComfyUI/custom_nodes 目錄。
    2. 使用 Git 下載本專案:
      git clone https://github.com/JetterTW/ComfyUI-LoRA-Captioner.git
      
      
    3. 進入資料夾並確保已安裝依賴套件:
      pip install -r requirements.txt
      
      
    4. 重啟 ComfyUI。

    ⚙️ 參數說明

    | 參數名稱 | 類型 | 預設值 | 功能說明 | | :--- | :--- | :--- | :--- | | image | IMAGE | - | 輸入需要進行標記的訓練圖片。 | | trigger_word | STRING | style_name | 設定 LoRA 的觸發詞,模型會將其自然融入描述中。 | | prompt_style | DROPDOWN | (依 JSON 而定) | 從 prompts.json 選擇不同的系統提示詞風格。 | | api_url | STRING | http://127.0.0.1:1234/v1/chat/completions | 本地或遠端 LLM API 的端點。 | | model_name | STRING | gemma4 | 指定要使用的模型名稱(需與 API 伺服器端一致)。 | | api_key | STRING | not-needed | API 認證金鑰(本地模型通常填 not-needed)。 | | max_new_tokens | INT | 2048 | 生成文字的最大長度上限。 | | temperature | FLOAT | 0.7 | 創意程度 (0.0 - 2.0)。越高越具想像力,越低越穩定。 | | seed | INT | 0 | 生成種子。更改種子可獲得不同的描述內容。 |

    🚀 使用場景範例

    場景 A:訓練 Flux 模型 (自然語言風格)

    1. 設定prompt_style 選擇 Flux (Natural Language)
    2. 輸出結果"A beautiful woman with long flowing hair, wearing a silk blue dress, standing in a sunlit garden, highly detailed texture, realistic lighting, style_name."
    3. 用途:符合 Flux 對於長句描述的訓練需求。

    場景 B:訓練 SDXL / Z-Image 模型 (標籤風格)

    1. 設定prompt_style 選擇 Z-Image / SDXL Style (Tag-Based)
    2. 輸出結果"style_name, 1girl, blue dress, silk, long hair, garden, sunlight, masterpiece, highly detailed."
    3. 用途:符合傳統標籤化 (Tag-based) 訓練邏輯。

    🛠️ 推薦工作流 (Workflow)

    建議的訓練準備流程如下:

    1. Load Image $\rightarrow$ LoRA Caption Generator $\rightarrow$ Save Text File (使用 ComfyUI 的檔案儲存節點)。
    2. 您可以利用 ComfyUI 的批量處理功能,一次讀取一個資料夾的所有圖片,並自動生成對應的 .txt 標籤檔。

    ⚠️ 注意事項

    1. API 兼容性:請確保您的 API 端點支援 Vision (視覺) 能力(例如 gemma4-visionllava),否則節點無法「看到」圖片內容。
    2. JSON 格式:本節點強烈依賴 API 回傳正確的 JSON 格式,若使用的模型不支援 response_format: { "type": "json_object" },可能需要調整 Prompt。
    3. 硬體要求:執行本地 LLM 視覺模型需要一定的顯存 (VRAM),建議至少 12GB 以上以獲得流暢體驗。

    👤 作者與授權


    Made with ❤️ for the AI Art Community.

    Run ComfyUI workflows without the setup

    No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.

    Learn more