0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dioxus + ComfyUI で作る!日本語対応画像生成アプリ

Last updated at Posted at 2026-01-02

Dioxus v0.7 + ComfyUI で作る!Gemini/LM Studio連携・日本語対応画像生成アプリ

概要

Dioxus v0.7.0 の公式 examples にある image_generator_openai.rs をベースに、ローカルで動作する ComfyUI (Stable Diffusion) をバックエンドとして利用できるように拡張しました。

Stable Diffusion は日本語プロンプトの理解が難しいため、LM Studio(ローカルLLM)や Google Gemini 3 Flash と連携し、日本語の指示を自動で英訳する機能を搭載しています。

コード生成やプロンプト作成のコツについては、Gemini 3 Flash を「最強のペアプロ相手」として活用しました。

動作イメージ

MyAppイメージ.png
https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/191459/30ef5ee6-5538-4b33-81f7-be88687fa329.png

開発環境(絶対無料派の構成)

  • PC: マウスコンピューター G-Tune
  • GPU: GeForce RTX 4070 SUPER (12GB) / RAM: 32GB
  • OS: Windows 11 Home
  • Editor: VS Code, MarkText
  • Shell: Git Bash

1. ComfyUI のインストールと準備

ComfyUI はポータブル版を使用するため、既存の Python 環境を汚さずに構築できます。

  1. ダウンロード: ComfyUI GitHub の「Direct link to download」から ComfyUI_windows_portable_nvidia.7z を入手し、展開します
  2. モデルの入手: Hugging Facestabilityai/stable-diffusion-xl-base-1.0 を検索します
  3. ファイルの配置: Files and versions タブから sd_xl_base_1.0.safetensors をダウンロードし、以下のフォルダに保存します
    ComfyUI_windows_portable\ComfyUI\models\checkpoints

2. ComfyUI の動作確認

アプリを動かす前に、ComfyUI 単体での動作を確認します。

  1. ComfyUI_windows_portable\run_nvidia_gpu.bat を実行します
  2. ブラウザで UI が開いたら、左端の「Load Checkpoint」ノードで sd_xl_base_1.0.safetensors を選択
  3. プロンプトに 「a beautiful real leopard」等と入力し、画像サイズ(Width/Height)を 1024 に設定
  4. 右上の 「Queue Prompt」 をクリックし、画像が生成されることを確認します
    ※生成物は ComfyUI_windows_portable\ComfyUI\output に保存されます。

3. LLM連携による日英翻訳機能

Stable Diffusion への指示を最適化するため、以下の機能を実装しました。

  • Google AI Studio連携: Gemini API キーを入力することで、高精度な英訳とプロンプトの最適化を行います
  • LM Studio連携: ローカル環境(localhost:1234)で動作する LLM(例: openai/gpt-oss-20b)を利用可能。API キーがない場合のフォールバックとして機能します
  • 編集機能: 翻訳された英語プロンプトを、生成前に手動で微調整できるフィールドを追加しました

4. アプリのインストールと実行方法

ステップ1:実行ファイルの取得

git clone https://github.com/tnagata/image-generator-comfyui.git
image-generator-comfyui\release\windows\image-generator-comfyui.exe

ステップ2:バックエンドの起動

run_nvidia_gpu.bat を実行して ComfyUI を起動しておきます。

ステップ3:アプリの起動

image-generator-comfyui.exeを起動します

ステップ4:設定と生成

  1. API Key フィールド: Google AI Studio のキーを入力します
  • 空の場合は LM Studio(サーバーモード)へ接続に行きます。筆者は gpt-oss 20B をロードして使用していますが、短い英訳用なので軽量なモデルで十分です
  1. Prompt (日本語 OK): 日本語で生成したいイメージを入力します
  2. Translated Prompt (Editable): 自動翻訳された英文を確認・調整します
  3. Create Image: ボタンをクリック。数秒で右側の Results 領域に画像が表示されます

開発のヒントとまとめ

ComfyUI の API 連携は一見難解ですが、Dioxus と Rust を組み合わせることで非常に堅牢なツールになりました。特に LM Studio の Developer Logs は、リクエストの構造を確認する際に非常に役立ちました。

生成された画像は ComfyUI 側の output フォルダに蓄積されるため、ストレージ容量にはご注意ください!


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?