2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

高火力 DOKの「ノートブック」機能を使ってComfyUIをngrokで接続する

Posted at

はじめに

ComfyUIを高火力 DOKの「ノートブック」機能を利用し、ngrokを使って接続できるようにするメモです。

今回は高火力 DOKを使用します。
高火力 DOKは、さくらインターネットが提供するコンテナ型GPUサービスです。
https://www.sakura.ad.jp/koukaryoku-dok/

前提

ngrokのトークンを取得

ngrokを利用するには、トークンが必要です。以下の手順で取得します。

https://dashboard.ngrok.com/ にアクセスし、サイドバーのYour Authtokenを選択します。
中央にあるYour Authtokenをメモしておきましょう。
ngrok token.png

高火力DOK

「ノートブック」の起動

ノートブックの利用方法を参考にノートブック(JupyterLab)を起動し外部から接続できるようにします。

高火力 DOKのダッシュボードにアクセスし、
サイドバーから「ノートブック」を選択したのち「起動」を選択します。
dok tasks.png

「起動」を選択し、JupyterLabが起動するまで待ちます。

「開く」を選択するとJupyterLabにアクセスできます。
※起動するまで3分程度かかる場合があるようです。
jupyterlab open.png

Jupyter NotebookにアクセスできたらNotebookのPython 3(ipykernel)を選択します
dok notebook.png

ComfyUIの起動

以下コードを順番に実行します。

  • pyngrokのインストール
!pip install pyngrok

pyngrok.png

  • ComfyUIをgitからDLし、必要なパッケージのインストール
!git clone https://github.com/comfyanonymous/ComfyUI.git
%cd ~/ComfyUI
!pip install -r requirements.txt

clone ComfyUI.png

  • ComfyUI ManagerをgitからDLし、必要なパッケージのインストール
%cd ~/ComfyUI/custom_nodes
!git clone https://github.com/Comfy-Org/ComfyUI-Manager.git comfyui-manager
%cd ~/ComfyUI/custom_nodes/comfyui-manager
!pip install -r requirements.txt

clone ComfyUI Manager.png

  • ディレクトリの移動と成果物保存場所の変更
%cd ~/ComfyUI
!rm -rf ~/ComfyUI/output
!ln -vs /opt/artifact ~/ComfyUI/output
  • 【任意】モデルのDL
    #(コメントアウト)を外して実行する
# !curl -Lo "/home/jovyan/ComfyUI/models/checkpoints/v1-5-pruned-emaonly-fp16.safetensors" "https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors"
  • ComfyUIの起動
ngrok_token="ngrokで取得したトークン"

from threading import Thread
from pyngrok import ngrok
import subprocess

def start_ngrok(port, token):
    ngrok.set_auth_token(token)
    url = ngrok.connect(port)
    print(f"ngrok tunnel started at: {url}")

# ngrok 起動(非同期)
ngrok_thread = Thread(target=start_ngrok, args=(8188, ngrok_token))
ngrok_thread.start()

!python main.py --preview-method auto --enable-cors-header --use-pytorch-cross-attention

start ComfyUI.png

起動すると
ngrok tunnel started at: NgrokTunnel: "https://xxxx.ngrok-free.app" -> "http://localhost:8188"
と表示されるので、スタートアップタスクが完了したらURLをクリックします。

ngrok.png

URLに飛んだら「Visit site」をクリックします。
dok visit.png

ComfyUIが開きます Yatta!!!
ComfyUI.png

終わるとき

停止を忘れると従量課金されていくので忘れずに停止しましょう

高火力 DOKのダッシュボードにアクセスし、
サイドバーから「ノートブック」を選択したのち、「終了」を選択します。

ポップアップにて「終了」を選択します。

成果物について

生成した画像などの成果物は高火力 DOKのダッシュボードからダウンロードすることもできます。(期限付き)
dok artifact.png

まとめ

この記事では、高火力 DOKの「ノートブック」機能を使ってComfyUIをngrokで接続する手順を説明しました。

ここまで読んでいただきありがとうございました

参考文献

高火力 DOK ドキュメント
ComfyUI-notebook-for-SageMaker-Studio-Lab

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?