Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
continue-revolution committed Nov 8, 2023
1 parent 11aa1d1 commit 4b47860
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Run AnimateDiff generation with Motion LoRA & Prompt Travel on CPU

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout A1111
uses: actions/checkout@v3
with:
repository: 'AUTOMATIC1111/stable-diffusion-webui'
path: 'stable-diffusion-webui'
- name: Checkout ControlNet
uses: actions/checkout@v3
with:
repository: 'Mikubill/sd-webui-controlnet'
path: 'stable-diffusion-webui/extensions/sd-webui-controlnet'
- name: Checkout AnimateDiff
uses: actions/checkout@v3
with:
repository: 'continue-revolution/sd-webui-animatediff'
path: 'stable-diffusion-webui/extensions/sd-webui-animatediff'
- name: Set up Python 3.11.4
uses: actions/setup-python@v4
with:
python-version: 3.11.4
cache: pip
cache-dependency-path: |
**/requirements*txt
launch.py
- name: Install test dependencies
run: |
pip install wait-for-it
pip install -r requirements-test.txt
working-directory: stable-diffusion-webui
env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_PROGRESS_BAR: "off"
- name: Setup environment
run: python launch.py --skip-torch-cuda-test --exit
working-directory: stable-diffusion-webui
env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_PROGRESS_BAR: "off"
TORCH_INDEX_URL: https://download.pytorch.org/whl/cpu
WEBUI_LAUNCH_LIVE_OUTPUT: "1"
PYTHONUNBUFFERED: "1"
- name: Cache AnimateDiff models
uses: actions/cache@v3
with:
path: stable-diffusion-webui/extensions/sd-webui-animatediff/model/
key: animatediff-models-v1
- name: Cache LoRA models
uses: actions/cache@v3
with:
path: stable-diffusion-webui/models/Lora
key: lora-models-v1
- name: Download AnimateDiff model for testing
run: |
if [ ! -f "extensions/sd-webui-animatediff/model/mm_sd_v15_v2.ckpt" ]; then
curl -Lo extensions/sd-webui-animatediff/model/mm_sd_v15_v2.ckpt https://huggingface.co/guoyww/animatediff/resolve/main/mm_sd_v15_v2.ckpt?download=true
fi
working-directory: stable-diffusion-webui
- name: Download LoRA model for testing
run: |
if [ ! -f "models/Lora/yoimiya.safetensors" ]; then
curl -Lo models/Lora/yoimiya.safetensors https://civitai.com/api/download/models/48374?type=Model&format=SafeTensor
fi
if [ ! -f "models/Lora/v2_lora_TiltDown.ckpt" ]; then
curl -Lo models/Lora/v2_lora_TiltDown.ckpt https://huggingface.co/guoyww/animatediff/resolve/main/v2_lora_TiltDown.ckpt?download=true
fi
- name: Start test server
run: >
python -m coverage run
--data-file=.coverage.server
launch.py
--skip-prepare-environment
--skip-torch-cuda-test
--test-server
--do-not-download-clip
--no-half
--disable-opt-split-attention
--use-cpu all
--api-server-stop
2>&1 | tee output.txt &
working-directory: stable-diffusion-webui
- name: Run tests
run: |
wait-for-it --service 127.0.0.1:7860 -t 600
python -m pytest -vv --junitxml=test/results.xml --cov ./extensions/sd-webui-animatediff --cov-report=xml --verify-base-url ./extensions/sd-webui-animatediff/tests
working-directory: stable-diffusion-webui
- name: Kill test server
if: always()
run: curl -vv -XPOST http://127.0.0.1:7860/sdapi/v1/server-stop && sleep 10
- name: Show coverage
run: |
python -m coverage combine .coverage*
python -m coverage report -i
python -m coverage html -i
working-directory: stable-diffusion-webui
- name: Upload main app output
uses: actions/upload-artifact@v3
if: always()
with:
name: output
path: output.txt
- name: Upload coverage HTML
uses: actions/upload-artifact@v3
if: always()
with:
name: htmlcov
path: htmlcov

41 changes: 41 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import pytest
import requests


@pytest.fixture()
def url_txt2img(base_url):
return f"{base_url}/sdapi/v1/txt2img"


@pytest.fixture()
def simple_txt2img_request():
return {
"prompt": '1girl, yoimiya (genshin impact), origen, line, comet, wink, Masterpiece, BestQuality. UltraDetailed, <lora:yoimiya:0.8>, <lora:v2_lora_TiltDown:0.8>\n0: closed mouth\n8: open mouth,',
"negative_prompt": "(sketch, duplicate, ugly, huge eyes, text, logo, monochrome, worst face, (bad and mutated hands:1.3), (worst quality:2.0), (low quality:2.0), (blurry:2.0), horror, geometry, bad_prompt_v2, (bad hands), (missing fingers), multiple limbs, bad anatomy, (interlocked fingers:1.2), Ugly Fingers, (extra digit and hands and fingers and legs and arms:1.4), crown braid, ((2girl)), (deformed fingers:1.2), (long fingers:1.2),succubus wings,horn,succubus horn,succubus hairstyle, (bad-artist-anime), bad-artist, bad hand, grayscale, skin spots, acnes, skin blemishes",
"batch_size": 1,
"steps": 2,
"cfg_scale": 7,
"alwayson_scripts": {
'AnimateDiff': {
'args': [{
'enable': True,
'batch_size': 2,
'video_length': 4,
}]
}
}
}


def test_txt2img_simple_performed(url_txt2img, simple_txt2img_request):
'''
This test checks the following:
- simple t2v generation
- prompt travel
- infinite context generator
- motion lora
'''
response = requests.post(url_txt2img, json=simple_txt2img_request)
assert response.status_code == 200
assert isinstance(response.json()['images'][0], str)

0 comments on commit 4b47860

Please sign in to comment.