HuggingFace Inference Endpoints用のWan2.2-I2V-A14Bカスタムハンドラー。画像からプロンプト駆動の高品質動画を生成します。
wan-i2v-handler/
├── handler.py # メインハンドラー
├── Dockerfile # Dockerイメージ定義
├── requirements-base.txt # 基本依存関係(torch等)
├── requirements.txt # Python依存関係
├── README.md # このファイル
└── tests/ # テストスイート
├── README.md # テストドキュメント
├── test_endpoint.py # テストユーティリティ
├── run_test_cases.py # テストケース実行
└── testdata/ # テスト用画像
1cd huggingface-endpoint/wan-i2v-handler
2docker build -t wan2.2-i2v-handler .
1# テスト画像を tests/testdata/ に配置
2cp your_test_image.jpg tests/testdata/case1.jpg
1cd tests
2
3# 全テストケース実行
4python run_test_cases.py
5
6# 特定のケースのみ
7python run_test_cases.py --case 1
8
9# カスタム画像でテスト
10python test_endpoint.py testdata/case1.jpg \
11 --prompt "camera slowly zooms in, cinematic motion"
1import requests
2import base64
3
4# 画像をbase64エンコード
5with open("tests/testdata/case1.jpg", "rb") as f:
6 image_b64 = base64.b64encode(f.read()).decode()
7
8# リクエスト送信
9response = requests.post("http://localhost:8080", json={
10 "inputs": image_b64,
11 "parameters": {
12 "prompt": "camera slowly zooms in, cinematic motion",
13 "guidance_scale": 3.5,
14 "num_inference_steps": 40,
15 "num_frames": 81
16 }
17})
18
19# 動画をデコード
20result = response.json()
21video_data_uri = result["video"] # data:video/mp4;base64,...
22
23# base64デコードして保存
24video_b64 = video_data_uri.split(",")[1]
25with open("output.mp4", "wb") as f:
26 f.write(base64.b64decode(video_b64))
1# Docker Hubにログイン
2docker login
3
4# タグ付け
5docker tag wan2.2-i2v-handler yourusername/wan2.2-i2v-handler:latest
6
7# プッシュ
8docker push yourusername/wan2.2-i2v-handler:latest
HF_HOME=/models
TRANSFORMERS_CACHE=/models
ENABLE_TF32=true
1VITE_HF_WAN_I2V_ENDPOINT_URL=https://YOUR_ENDPOINT_ID....endpoints.huggingface.cloud
2VITE_HF_TOKEN=hf_...
3VITE_HF_NAMESPACE=yourusername
1{
2 "inputs": "base64_encoded_image",
3 "parameters": {
4 "prompt": "camera slowly zooms in",
5 "guidance_scale": 3.5,
6 "num_inference_steps": 40,
7 "num_frames": 81,
8 "height": 720,
9 "width": 1280,
10 "fps": 16
11 }
12}
1{
2 "video": "data:video/mp4;base64,AAAAHGZ0eXBpc29tAAACAGlzb21..."
3}
1# Python 3.10 + PyTorch 2.9 + CUDA 12.8の場合
2pip install https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.0/flash_attn-2.8.3+cu128torch2.9-cp310-cp310-linux_x86_64.whl
1# ninjaのインストール(並列ビルド)
2apt-get install ninja-build
3pip install packaging ninja
4
5# --no-build-isolation必須
6pip install flash-attn --no-build-isolation