Spaces:
Running
Running
limit max number of images
#2
by
radames
- opened
- .pre-commit-config.yaml +0 -10
- LICENSE +0 -21
- README.md +2 -4
- app.py +44 -123
- app_canny.py → gradio_canny2image.py +35 -52
- app_depth.py → gradio_depth2image.py +25 -43
- app_fake_scribble.py → gradio_fake_scribble2image.py +25 -40
- app_hed.py → gradio_hed2image.py +25 -40
- app_hough.py → gradio_hough2image.py +28 -44
- app_normal.py → gradio_normal2image.py +26 -44
- app_pose.py → gradio_pose2image.py +25 -46
- app_scribble.py → gradio_scribble2image.py +24 -38
- app_scribble_interactive.py → gradio_scribble2image_interactive.py +26 -41
- app_seg.py → gradio_seg2image.py +25 -43
- model.py +674 -598
- notebooks/notebook.ipynb +0 -80
- patch +0 -13
- requirements.txt +1 -5
- style.css +0 -5
.pre-commit-config.yaml
CHANGED
|
@@ -35,13 +35,3 @@ repos:
|
|
| 35 |
hooks:
|
| 36 |
- id: yapf
|
| 37 |
args: ['--parallel', '--in-place']
|
| 38 |
-
- repo: https://github.com/kynan/nbstripout
|
| 39 |
-
rev: 0.6.0
|
| 40 |
-
hooks:
|
| 41 |
-
- id: nbstripout
|
| 42 |
-
args: ['--extra-keys', 'metadata.interpreter metadata.kernelspec cell.metadata.pycharm']
|
| 43 |
-
- repo: https://github.com/nbQA-dev/nbQA
|
| 44 |
-
rev: 1.6.4
|
| 45 |
-
hooks:
|
| 46 |
-
- id: nbqa-isort
|
| 47 |
-
- id: nbqa-yapf
|
|
|
|
| 35 |
hooks:
|
| 36 |
- id: yapf
|
| 37 |
args: ['--parallel', '--in-place']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
MIT License
|
| 2 |
-
|
| 3 |
-
Copyright (c) 2023 hysts
|
| 4 |
-
|
| 5 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
-
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
-
in the Software without restriction, including without limitation the rights
|
| 8 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
-
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
-
furnished to do so, subject to the following conditions:
|
| 11 |
-
|
| 12 |
-
The above copyright notice and this permission notice shall be included in all
|
| 13 |
-
copies or substantial portions of the Software.
|
| 14 |
-
|
| 15 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
-
SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -4,12 +4,10 @@ emoji: 🌖
|
|
| 4 |
colorFrom: pink
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 8 |
-
python_version: 3.10.
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
-
license: mit
|
| 12 |
-
suggested_hardware: t4-medium
|
| 13 |
---
|
| 14 |
|
| 15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 4 |
colorFrom: pink
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.18.0
|
| 8 |
+
python_version: 3.10.9
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -3,155 +3,76 @@
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import os
|
| 6 |
-
import pathlib
|
| 7 |
import shlex
|
| 8 |
import subprocess
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
-
import torch
|
| 12 |
|
| 13 |
if os.getenv('SYSTEM') == 'spaces':
|
| 14 |
with open('patch') as f:
|
| 15 |
subprocess.run(shlex.split('patch -p1'), stdin=f, cwd='ControlNet')
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
from
|
| 35 |
-
from
|
| 36 |
-
from
|
| 37 |
-
from app_hed import create_demo as create_demo_hed
|
| 38 |
-
from app_hough import create_demo as create_demo_hough
|
| 39 |
-
from app_normal import create_demo as create_demo_normal
|
| 40 |
-
from app_pose import create_demo as create_demo_pose
|
| 41 |
-
from app_scribble import create_demo as create_demo_scribble
|
| 42 |
-
from app_scribble_interactive import \
|
| 43 |
create_demo as create_demo_scribble_interactive
|
| 44 |
-
from
|
| 45 |
-
from model import Model
|
| 46 |
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
'''
|
| 51 |
|
| 52 |
-
|
| 53 |
-
ALLOW_CHANGING_BASE_MODEL = SPACE_ID != 'hysts/ControlNet'
|
| 54 |
-
|
| 55 |
-
if SPACE_ID is not None:
|
| 56 |
-
DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
| 57 |
-
if not torch.cuda.is_available():
|
| 58 |
-
DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
|
| 59 |
-
|
| 60 |
-
if torch.cuda.is_available():
|
| 61 |
-
if os.getenv('SYSTEM') == 'spaces':
|
| 62 |
-
download_all_controlnet_weights()
|
| 63 |
-
|
| 64 |
-
MAX_IMAGES = int(os.getenv('MAX_IMAGES', '3'))
|
| 65 |
-
DEFAULT_NUM_IMAGES = min(MAX_IMAGES, int(os.getenv('DEFAULT_NUM_IMAGES', '1')))
|
| 66 |
-
|
| 67 |
-
DEFAULT_MODEL_ID = os.getenv('DEFAULT_MODEL_ID',
|
| 68 |
-
'runwayml/stable-diffusion-v1-5')
|
| 69 |
-
model = Model(base_model_id=DEFAULT_MODEL_ID, task_name='canny')
|
| 70 |
|
| 71 |
with gr.Blocks(css='style.css') as demo:
|
| 72 |
gr.Markdown(DESCRIPTION)
|
| 73 |
with gr.Tabs():
|
| 74 |
with gr.TabItem('Canny'):
|
| 75 |
-
create_demo_canny(model.process_canny,
|
| 76 |
-
max_images=MAX_IMAGES,
|
| 77 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 78 |
with gr.TabItem('Hough'):
|
| 79 |
-
create_demo_hough(model.process_hough,
|
| 80 |
-
max_images=MAX_IMAGES,
|
| 81 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 82 |
with gr.TabItem('HED'):
|
| 83 |
-
create_demo_hed(model.process_hed,
|
| 84 |
-
max_images=MAX_IMAGES,
|
| 85 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 86 |
with gr.TabItem('Scribble'):
|
| 87 |
-
create_demo_scribble(model.process_scribble,
|
| 88 |
-
max_images=MAX_IMAGES,
|
| 89 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 90 |
with gr.TabItem('Scribble Interactive'):
|
| 91 |
create_demo_scribble_interactive(
|
| 92 |
-
model.process_scribble_interactive,
|
| 93 |
-
max_images=MAX_IMAGES,
|
| 94 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 95 |
with gr.TabItem('Fake Scribble'):
|
| 96 |
-
create_demo_fake_scribble(model.process_fake_scribble,
|
| 97 |
-
max_images=MAX_IMAGES,
|
| 98 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 99 |
with gr.TabItem('Pose'):
|
| 100 |
-
create_demo_pose(model.process_pose,
|
| 101 |
-
max_images=MAX_IMAGES,
|
| 102 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 103 |
with gr.TabItem('Segmentation'):
|
| 104 |
-
create_demo_seg(model.process_seg,
|
| 105 |
-
max_images=MAX_IMAGES,
|
| 106 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 107 |
with gr.TabItem('Depth'):
|
| 108 |
-
create_demo_depth(model.process_depth,
|
| 109 |
-
max_images=MAX_IMAGES,
|
| 110 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 111 |
with gr.TabItem('Normal map'):
|
| 112 |
-
create_demo_normal(model.process_normal,
|
| 113 |
-
max_images=MAX_IMAGES,
|
| 114 |
-
default_num_images=DEFAULT_NUM_IMAGES)
|
| 115 |
-
|
| 116 |
-
with gr.Accordion(label='Base model', open=False):
|
| 117 |
-
with gr.Row():
|
| 118 |
-
with gr.Column():
|
| 119 |
-
current_base_model = gr.Text(label='Current base model')
|
| 120 |
-
with gr.Column(scale=0.3):
|
| 121 |
-
check_base_model_button = gr.Button('Check current base model')
|
| 122 |
-
with gr.Row():
|
| 123 |
-
with gr.Column():
|
| 124 |
-
new_base_model_id = gr.Text(
|
| 125 |
-
label='New base model',
|
| 126 |
-
max_lines=1,
|
| 127 |
-
placeholder='runwayml/stable-diffusion-v1-5',
|
| 128 |
-
info=
|
| 129 |
-
'The base model must be compatible with Stable Diffusion v1.5.',
|
| 130 |
-
interactive=ALLOW_CHANGING_BASE_MODEL)
|
| 131 |
-
with gr.Column(scale=0.3):
|
| 132 |
-
change_base_model_button = gr.Button(
|
| 133 |
-
'Change base model', interactive=ALLOW_CHANGING_BASE_MODEL)
|
| 134 |
-
if not ALLOW_CHANGING_BASE_MODEL:
|
| 135 |
-
gr.Markdown(
|
| 136 |
-
'''The base model is not allowed to be changed in this Space so as not to slow down the demo, but it can be changed if you duplicate the Space. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a>'''
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
-
gr.Markdown('''### Related Spaces
|
| 140 |
-
|
| 141 |
-
- [Space using Anything-v4.0 as base model](https://huggingface.co/spaces/hysts/ControlNet-with-Anything-v4)
|
| 142 |
-
- https://huggingface.co/spaces/jonigata/PoseMaker2
|
| 143 |
-
- https://huggingface.co/spaces/diffusers/controlnet-openpose
|
| 144 |
-
- https://huggingface.co/spaces/diffusers/controlnet-canny
|
| 145 |
-
''')
|
| 146 |
-
|
| 147 |
-
check_base_model_button.click(fn=lambda: model.base_model_id,
|
| 148 |
-
outputs=current_base_model,
|
| 149 |
-
queue=False)
|
| 150 |
-
new_base_model_id.submit(fn=model.set_base_model,
|
| 151 |
-
inputs=new_base_model_id,
|
| 152 |
-
outputs=current_base_model)
|
| 153 |
-
change_base_model_button.click(fn=model.set_base_model,
|
| 154 |
-
inputs=new_base_model_id,
|
| 155 |
-
outputs=current_base_model)
|
| 156 |
|
| 157 |
-
demo.queue(api_open=False
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 6 |
import shlex
|
| 7 |
import subprocess
|
| 8 |
|
| 9 |
import gradio as gr
|
|
|
|
| 10 |
|
| 11 |
if os.getenv('SYSTEM') == 'spaces':
|
| 12 |
with open('patch') as f:
|
| 13 |
subprocess.run(shlex.split('patch -p1'), stdin=f, cwd='ControlNet')
|
| 14 |
+
commands = [
|
| 15 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/dpt_hybrid-midas-501f0c75.pt -O dpt_hybrid-midas-501f0c75.pt',
|
| 16 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/body_pose_model.pth -O body_pose_model.pth',
|
| 17 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/hand_pose_model.pth -O hand_pose_model.pth',
|
| 18 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_large_512_fp32.pth -O mlsd_large_512_fp32.pth',
|
| 19 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_tiny_512_fp32.pth -O mlsd_tiny_512_fp32.pth',
|
| 20 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/network-bsds500.pth -O network-bsds500.pth',
|
| 21 |
+
'wget https://huggingface.co/ckpt/ControlNet/resolve/main/upernet_global_small.pth -O upernet_global_small.pth',
|
| 22 |
+
]
|
| 23 |
+
for command in commands:
|
| 24 |
+
subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')
|
| 25 |
+
|
| 26 |
+
from gradio_canny2image import create_demo as create_demo_canny
|
| 27 |
+
from gradio_depth2image import create_demo as create_demo_depth
|
| 28 |
+
from gradio_fake_scribble2image import create_demo as create_demo_fake_scribble
|
| 29 |
+
from gradio_hed2image import create_demo as create_demo_hed
|
| 30 |
+
from gradio_hough2image import create_demo as create_demo_hough
|
| 31 |
+
from gradio_normal2image import create_demo as create_demo_normal
|
| 32 |
+
from gradio_pose2image import create_demo as create_demo_pose
|
| 33 |
+
from gradio_scribble2image import create_demo as create_demo_scribble
|
| 34 |
+
from gradio_scribble2image_interactive import \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
create_demo as create_demo_scribble_interactive
|
| 36 |
+
from gradio_seg2image import create_demo as create_demo_seg
|
| 37 |
+
from model import Model
|
| 38 |
|
| 39 |
+
MAX_IMAGES = 1
|
| 40 |
+
DESCRIPTION = '''# ControlNet
|
| 41 |
|
| 42 |
+
This is an unofficial demo for [https://github.com/lllyasviel/ControlNet](https://github.com/lllyasviel/ControlNet).
|
| 43 |
+
'''
|
| 44 |
+
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
| 45 |
+
DESCRIPTION += f'''<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.<br/>
|
| 46 |
+
<a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true">
|
| 47 |
+
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
| 48 |
+
<p/>
|
| 49 |
'''
|
| 50 |
|
| 51 |
+
model = Model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
with gr.Blocks(css='style.css') as demo:
|
| 54 |
gr.Markdown(DESCRIPTION)
|
| 55 |
with gr.Tabs():
|
| 56 |
with gr.TabItem('Canny'):
|
| 57 |
+
create_demo_canny(model.process_canny, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 58 |
with gr.TabItem('Hough'):
|
| 59 |
+
create_demo_hough(model.process_hough, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 60 |
with gr.TabItem('HED'):
|
| 61 |
+
create_demo_hed(model.process_hed, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 62 |
with gr.TabItem('Scribble'):
|
| 63 |
+
create_demo_scribble(model.process_scribble, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 64 |
with gr.TabItem('Scribble Interactive'):
|
| 65 |
create_demo_scribble_interactive(
|
| 66 |
+
model.process_scribble_interactive, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 67 |
with gr.TabItem('Fake Scribble'):
|
| 68 |
+
create_demo_fake_scribble(model.process_fake_scribble, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 69 |
with gr.TabItem('Pose'):
|
| 70 |
+
create_demo_pose(model.process_pose, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 71 |
with gr.TabItem('Segmentation'):
|
| 72 |
+
create_demo_seg(model.process_seg, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 73 |
with gr.TabItem('Depth'):
|
| 74 |
+
create_demo_depth(model.process_depth, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
| 75 |
with gr.TabItem('Normal map'):
|
| 76 |
+
create_demo_normal(model.process_normal, max_images=MAX_IMAGES)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
demo.queue(api_open=False).launch()
|
app_canny.py → gradio_canny2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_canny2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Canny Edge Maps')
|
|
@@ -16,40 +16,39 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
-
maximum=
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
value=9.0,
|
| 47 |
-
step=0.1)
|
| 48 |
seed = gr.Slider(label='Seed',
|
| 49 |
minimum=-1,
|
| 50 |
maximum=2147483647,
|
| 51 |
step=1,
|
| 52 |
randomize=True)
|
|
|
|
| 53 |
a_prompt = gr.Textbox(
|
| 54 |
label='Added Prompt',
|
| 55 |
value='best quality, extremely detailed')
|
|
@@ -59,33 +58,17 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 59 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 60 |
)
|
| 61 |
with gr.Column():
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
input_image,
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
n_prompt,
|
| 71 |
-
num_samples,
|
| 72 |
-
image_resolution,
|
| 73 |
-
num_steps,
|
| 74 |
-
guidance_scale,
|
| 75 |
-
seed,
|
| 76 |
-
canny_low_threshold,
|
| 77 |
-
canny_high_threshold,
|
| 78 |
]
|
| 79 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 80 |
run_button.click(fn=process,
|
| 81 |
-
inputs=
|
| 82 |
-
outputs=
|
| 83 |
api_name='canny')
|
| 84 |
return demo
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
if __name__ == '__main__':
|
| 88 |
-
from model import Model
|
| 89 |
-
model = Model()
|
| 90 |
-
demo = create_demo(model.process_canny)
|
| 91 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_canny2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Canny Edge Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
+
low_threshold = gr.Slider(label='Canny low threshold',
|
| 27 |
+
minimum=1,
|
| 28 |
+
maximum=255,
|
| 29 |
+
value=100,
|
| 30 |
+
step=1)
|
| 31 |
+
high_threshold = gr.Slider(label='Canny high threshold',
|
| 32 |
+
minimum=1,
|
| 33 |
+
maximum=255,
|
| 34 |
+
value=200,
|
| 35 |
+
step=1)
|
| 36 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 37 |
+
minimum=1,
|
| 38 |
+
maximum=100,
|
| 39 |
+
value=20,
|
| 40 |
+
step=1)
|
| 41 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 42 |
+
minimum=0.1,
|
| 43 |
+
maximum=30.0,
|
| 44 |
+
value=9.0,
|
| 45 |
+
step=0.1)
|
|
|
|
|
|
|
| 46 |
seed = gr.Slider(label='Seed',
|
| 47 |
minimum=-1,
|
| 48 |
maximum=2147483647,
|
| 49 |
step=1,
|
| 50 |
randomize=True)
|
| 51 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 52 |
a_prompt = gr.Textbox(
|
| 53 |
label='Added Prompt',
|
| 54 |
value='best quality, extremely detailed')
|
|
|
|
| 58 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 59 |
)
|
| 60 |
with gr.Column():
|
| 61 |
+
result_gallery = gr.Gallery(label='Output',
|
| 62 |
+
show_label=False,
|
| 63 |
+
elem_id='gallery').style(
|
| 64 |
+
grid=2, height='auto')
|
| 65 |
+
ips = [
|
| 66 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 67 |
+
image_resolution, ddim_steps, scale, seed, eta, low_threshold,
|
| 68 |
+
high_threshold
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
]
|
|
|
|
| 70 |
run_button.click(fn=process,
|
| 71 |
+
inputs=ips,
|
| 72 |
+
outputs=[result_gallery],
|
| 73 |
api_name='canny')
|
| 74 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_depth.py → gradio_depth2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_depth2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Depth Maps')
|
|
@@ -13,38 +13,37 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
| 16 |
-
is_depth_image = gr.Checkbox(label='Is depth image',
|
| 17 |
-
value=False)
|
| 18 |
num_samples = gr.Slider(label='Images',
|
| 19 |
minimum=1,
|
| 20 |
maximum=max_images,
|
| 21 |
-
value=
|
| 22 |
step=1)
|
| 23 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 24 |
minimum=256,
|
| 25 |
-
maximum=
|
| 26 |
value=512,
|
| 27 |
step=256)
|
| 28 |
detect_resolution = gr.Slider(label='Depth Resolution',
|
| 29 |
minimum=128,
|
| 30 |
-
maximum=
|
| 31 |
value=384,
|
| 32 |
step=1)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
seed = gr.Slider(label='Seed',
|
| 44 |
minimum=-1,
|
| 45 |
maximum=2147483647,
|
| 46 |
step=1,
|
| 47 |
randomize=True)
|
|
|
|
| 48 |
a_prompt = gr.Textbox(
|
| 49 |
label='Added Prompt',
|
| 50 |
value='best quality, extremely detailed')
|
|
@@ -54,33 +53,16 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 54 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 55 |
)
|
| 56 |
with gr.Column():
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
input_image,
|
| 63 |
-
|
| 64 |
-
a_prompt,
|
| 65 |
-
n_prompt,
|
| 66 |
-
num_samples,
|
| 67 |
-
image_resolution,
|
| 68 |
-
detect_resolution,
|
| 69 |
-
num_steps,
|
| 70 |
-
guidance_scale,
|
| 71 |
-
seed,
|
| 72 |
-
is_depth_image,
|
| 73 |
]
|
| 74 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 75 |
run_button.click(fn=process,
|
| 76 |
-
inputs=
|
| 77 |
-
outputs=
|
| 78 |
api_name='depth')
|
| 79 |
return demo
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
if __name__ == '__main__':
|
| 83 |
-
from model import Model
|
| 84 |
-
model = Model()
|
| 85 |
-
demo = create_demo(model.process_depth)
|
| 86 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_depth2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Depth Maps')
|
|
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
|
|
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='Depth Resolution',
|
| 27 |
minimum=128,
|
| 28 |
+
maximum=1024,
|
| 29 |
value=384,
|
| 30 |
step=1)
|
| 31 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 32 |
+
minimum=1,
|
| 33 |
+
maximum=100,
|
| 34 |
+
value=20,
|
| 35 |
+
step=1)
|
| 36 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 37 |
+
minimum=0.1,
|
| 38 |
+
maximum=30.0,
|
| 39 |
+
value=9.0,
|
| 40 |
+
step=0.1)
|
| 41 |
seed = gr.Slider(label='Seed',
|
| 42 |
minimum=-1,
|
| 43 |
maximum=2147483647,
|
| 44 |
step=1,
|
| 45 |
randomize=True)
|
| 46 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 47 |
a_prompt = gr.Textbox(
|
| 48 |
label='Added Prompt',
|
| 49 |
value='best quality, extremely detailed')
|
|
|
|
| 53 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 54 |
)
|
| 55 |
with gr.Column():
|
| 56 |
+
result_gallery = gr.Gallery(label='Output',
|
| 57 |
+
show_label=False,
|
| 58 |
+
elem_id='gallery').style(
|
| 59 |
+
grid=2, height='auto')
|
| 60 |
+
ips = [
|
| 61 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 62 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
]
|
|
|
|
| 64 |
run_button.click(fn=process,
|
| 65 |
+
inputs=ips,
|
| 66 |
+
outputs=[result_gallery],
|
| 67 |
api_name='depth')
|
| 68 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_fake_scribble.py → gradio_fake_scribble2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_fake_scribble2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Fake Scribble Maps')
|
|
@@ -16,33 +16,34 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
-
maximum=
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='HED Resolution',
|
| 27 |
minimum=128,
|
| 28 |
-
maximum=
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
seed = gr.Slider(label='Seed',
|
| 42 |
minimum=-1,
|
| 43 |
maximum=2147483647,
|
| 44 |
step=1,
|
| 45 |
randomize=True)
|
|
|
|
| 46 |
a_prompt = gr.Textbox(
|
| 47 |
label='Added Prompt',
|
| 48 |
value='best quality, extremely detailed')
|
|
@@ -52,32 +53,16 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 52 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 53 |
)
|
| 54 |
with gr.Column():
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
input_image,
|
| 61 |
-
|
| 62 |
-
a_prompt,
|
| 63 |
-
n_prompt,
|
| 64 |
-
num_samples,
|
| 65 |
-
image_resolution,
|
| 66 |
-
detect_resolution,
|
| 67 |
-
num_steps,
|
| 68 |
-
guidance_scale,
|
| 69 |
-
seed,
|
| 70 |
]
|
| 71 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 72 |
run_button.click(fn=process,
|
| 73 |
-
inputs=
|
| 74 |
-
outputs=
|
| 75 |
api_name='fake_scribble')
|
| 76 |
return demo
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
if __name__ == '__main__':
|
| 80 |
-
from model import Model
|
| 81 |
-
model = Model()
|
| 82 |
-
demo = create_demo(model.process_fake_scribble)
|
| 83 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_fake_scribble2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Fake Scribble Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='HED Resolution',
|
| 27 |
minimum=128,
|
| 28 |
+
maximum=1024,
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 32 |
+
minimum=1,
|
| 33 |
+
maximum=100,
|
| 34 |
+
value=20,
|
| 35 |
+
step=1)
|
| 36 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 37 |
+
minimum=0.1,
|
| 38 |
+
maximum=30.0,
|
| 39 |
+
value=9.0,
|
| 40 |
+
step=0.1)
|
| 41 |
seed = gr.Slider(label='Seed',
|
| 42 |
minimum=-1,
|
| 43 |
maximum=2147483647,
|
| 44 |
step=1,
|
| 45 |
randomize=True)
|
| 46 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 47 |
a_prompt = gr.Textbox(
|
| 48 |
label='Added Prompt',
|
| 49 |
value='best quality, extremely detailed')
|
|
|
|
| 53 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 54 |
)
|
| 55 |
with gr.Column():
|
| 56 |
+
result_gallery = gr.Gallery(label='Output',
|
| 57 |
+
show_label=False,
|
| 58 |
+
elem_id='gallery').style(
|
| 59 |
+
grid=2, height='auto')
|
| 60 |
+
ips = [
|
| 61 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 62 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
]
|
|
|
|
| 64 |
run_button.click(fn=process,
|
| 65 |
+
inputs=ips,
|
| 66 |
+
outputs=[result_gallery],
|
| 67 |
api_name='fake_scribble')
|
| 68 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_hed.py → gradio_hed2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_hed2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with HED Maps')
|
|
@@ -16,33 +16,34 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
-
maximum=
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='HED Resolution',
|
| 27 |
minimum=128,
|
| 28 |
-
maximum=
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
seed = gr.Slider(label='Seed',
|
| 42 |
minimum=-1,
|
| 43 |
maximum=2147483647,
|
| 44 |
step=1,
|
| 45 |
randomize=True)
|
|
|
|
| 46 |
a_prompt = gr.Textbox(
|
| 47 |
label='Added Prompt',
|
| 48 |
value='best quality, extremely detailed')
|
|
@@ -52,32 +53,16 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 52 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 53 |
)
|
| 54 |
with gr.Column():
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
input_image,
|
| 61 |
-
|
| 62 |
-
a_prompt,
|
| 63 |
-
n_prompt,
|
| 64 |
-
num_samples,
|
| 65 |
-
image_resolution,
|
| 66 |
-
detect_resolution,
|
| 67 |
-
num_steps,
|
| 68 |
-
guidance_scale,
|
| 69 |
-
seed,
|
| 70 |
]
|
| 71 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 72 |
run_button.click(fn=process,
|
| 73 |
-
inputs=
|
| 74 |
-
outputs=
|
| 75 |
api_name='hed')
|
| 76 |
return demo
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
if __name__ == '__main__':
|
| 80 |
-
from model import Model
|
| 81 |
-
model = Model()
|
| 82 |
-
demo = create_demo(model.process_hed)
|
| 83 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_hed2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with HED Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='HED Resolution',
|
| 27 |
minimum=128,
|
| 28 |
+
maximum=1024,
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 32 |
+
minimum=1,
|
| 33 |
+
maximum=100,
|
| 34 |
+
value=20,
|
| 35 |
+
step=1)
|
| 36 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 37 |
+
minimum=0.1,
|
| 38 |
+
maximum=30.0,
|
| 39 |
+
value=9.0,
|
| 40 |
+
step=0.1)
|
| 41 |
seed = gr.Slider(label='Seed',
|
| 42 |
minimum=-1,
|
| 43 |
maximum=2147483647,
|
| 44 |
step=1,
|
| 45 |
randomize=True)
|
| 46 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 47 |
a_prompt = gr.Textbox(
|
| 48 |
label='Added Prompt',
|
| 49 |
value='best quality, extremely detailed')
|
|
|
|
| 53 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 54 |
)
|
| 55 |
with gr.Column():
|
| 56 |
+
result_gallery = gr.Gallery(label='Output',
|
| 57 |
+
show_label=False,
|
| 58 |
+
elem_id='gallery').style(
|
| 59 |
+
grid=2, height='auto')
|
| 60 |
+
ips = [
|
| 61 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 62 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
]
|
|
|
|
| 64 |
run_button.click(fn=process,
|
| 65 |
+
inputs=ips,
|
| 66 |
+
outputs=[result_gallery],
|
| 67 |
api_name='hed')
|
| 68 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_hough.py → gradio_hough2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_hough2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Hough Line Maps')
|
|
@@ -16,45 +16,46 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
-
maximum=
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='Hough Resolution',
|
| 27 |
minimum=128,
|
| 28 |
-
maximum=
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
-
|
| 32 |
label='Hough value threshold (MLSD)',
|
| 33 |
minimum=0.01,
|
| 34 |
maximum=2.0,
|
| 35 |
value=0.1,
|
| 36 |
step=0.01)
|
| 37 |
-
|
| 38 |
label='Hough distance threshold (MLSD)',
|
| 39 |
minimum=0.01,
|
| 40 |
maximum=20.0,
|
| 41 |
value=0.1,
|
| 42 |
step=0.01)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
seed = gr.Slider(label='Seed',
|
| 54 |
minimum=-1,
|
| 55 |
maximum=2147483647,
|
| 56 |
step=1,
|
| 57 |
randomize=True)
|
|
|
|
| 58 |
a_prompt = gr.Textbox(
|
| 59 |
label='Added Prompt',
|
| 60 |
value='best quality, extremely detailed')
|
|
@@ -64,34 +65,17 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 64 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 65 |
)
|
| 66 |
with gr.Column():
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
input_image,
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
n_prompt,
|
| 76 |
-
num_samples,
|
| 77 |
-
image_resolution,
|
| 78 |
-
detect_resolution,
|
| 79 |
-
num_steps,
|
| 80 |
-
guidance_scale,
|
| 81 |
-
seed,
|
| 82 |
-
mlsd_value_threshold,
|
| 83 |
-
mlsd_distance_threshold,
|
| 84 |
]
|
| 85 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 86 |
run_button.click(fn=process,
|
| 87 |
-
inputs=
|
| 88 |
-
outputs=
|
| 89 |
api_name='hough')
|
| 90 |
return demo
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
if __name__ == '__main__':
|
| 94 |
-
from model import Model
|
| 95 |
-
model = Model()
|
| 96 |
-
demo = create_demo(model.process_hough)
|
| 97 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_hough2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Hough Line Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='Hough Resolution',
|
| 27 |
minimum=128,
|
| 28 |
+
maximum=1024,
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
+
value_threshold = gr.Slider(
|
| 32 |
label='Hough value threshold (MLSD)',
|
| 33 |
minimum=0.01,
|
| 34 |
maximum=2.0,
|
| 35 |
value=0.1,
|
| 36 |
step=0.01)
|
| 37 |
+
distance_threshold = gr.Slider(
|
| 38 |
label='Hough distance threshold (MLSD)',
|
| 39 |
minimum=0.01,
|
| 40 |
maximum=20.0,
|
| 41 |
value=0.1,
|
| 42 |
step=0.01)
|
| 43 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 44 |
+
minimum=1,
|
| 45 |
+
maximum=100,
|
| 46 |
+
value=20,
|
| 47 |
+
step=1)
|
| 48 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 49 |
+
minimum=0.1,
|
| 50 |
+
maximum=30.0,
|
| 51 |
+
value=9.0,
|
| 52 |
+
step=0.1)
|
| 53 |
seed = gr.Slider(label='Seed',
|
| 54 |
minimum=-1,
|
| 55 |
maximum=2147483647,
|
| 56 |
step=1,
|
| 57 |
randomize=True)
|
| 58 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 59 |
a_prompt = gr.Textbox(
|
| 60 |
label='Added Prompt',
|
| 61 |
value='best quality, extremely detailed')
|
|
|
|
| 65 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 66 |
)
|
| 67 |
with gr.Column():
|
| 68 |
+
result_gallery = gr.Gallery(label='Output',
|
| 69 |
+
show_label=False,
|
| 70 |
+
elem_id='gallery').style(
|
| 71 |
+
grid=2, height='auto')
|
| 72 |
+
ips = [
|
| 73 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 74 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta,
|
| 75 |
+
value_threshold, distance_threshold
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
]
|
|
|
|
| 77 |
run_button.click(fn=process,
|
| 78 |
+
inputs=ips,
|
| 79 |
+
outputs=[result_gallery],
|
| 80 |
api_name='hough')
|
| 81 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_normal.py → gradio_normal2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_normal2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Normal Maps')
|
|
@@ -13,21 +13,19 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
| 16 |
-
is_normal_image = gr.Checkbox(label='Is normal image',
|
| 17 |
-
value=False)
|
| 18 |
num_samples = gr.Slider(label='Images',
|
| 19 |
minimum=1,
|
| 20 |
maximum=max_images,
|
| 21 |
-
value=
|
| 22 |
step=1)
|
| 23 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 24 |
minimum=256,
|
| 25 |
-
maximum=
|
| 26 |
value=512,
|
| 27 |
step=256)
|
| 28 |
detect_resolution = gr.Slider(label='Normal Resolution',
|
| 29 |
minimum=128,
|
| 30 |
-
maximum=
|
| 31 |
value=384,
|
| 32 |
step=1)
|
| 33 |
bg_threshold = gr.Slider(
|
|
@@ -36,21 +34,22 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 36 |
maximum=1.0,
|
| 37 |
value=0.4,
|
| 38 |
step=0.01)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
seed = gr.Slider(label='Seed',
|
| 50 |
minimum=-1,
|
| 51 |
maximum=2147483647,
|
| 52 |
step=1,
|
| 53 |
randomize=True)
|
|
|
|
| 54 |
a_prompt = gr.Textbox(
|
| 55 |
label='Added Prompt',
|
| 56 |
value='best quality, extremely detailed')
|
|
@@ -60,34 +59,17 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 60 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 61 |
)
|
| 62 |
with gr.Column():
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
input_image,
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
n_prompt,
|
| 72 |
-
num_samples,
|
| 73 |
-
image_resolution,
|
| 74 |
-
detect_resolution,
|
| 75 |
-
num_steps,
|
| 76 |
-
guidance_scale,
|
| 77 |
-
seed,
|
| 78 |
-
bg_threshold,
|
| 79 |
-
is_normal_image,
|
| 80 |
]
|
| 81 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 82 |
run_button.click(fn=process,
|
| 83 |
-
inputs=
|
| 84 |
-
outputs=
|
| 85 |
api_name='normal')
|
| 86 |
return demo
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
if __name__ == '__main__':
|
| 90 |
-
from model import Model
|
| 91 |
-
model = Model()
|
| 92 |
-
demo = create_demo(model.process_normal)
|
| 93 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_normal2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Normal Maps')
|
|
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
|
|
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='Normal Resolution',
|
| 27 |
minimum=128,
|
| 28 |
+
maximum=1024,
|
| 29 |
value=384,
|
| 30 |
step=1)
|
| 31 |
bg_threshold = gr.Slider(
|
|
|
|
| 34 |
maximum=1.0,
|
| 35 |
value=0.4,
|
| 36 |
step=0.01)
|
| 37 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 38 |
+
minimum=1,
|
| 39 |
+
maximum=100,
|
| 40 |
+
value=20,
|
| 41 |
+
step=1)
|
| 42 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 43 |
+
minimum=0.1,
|
| 44 |
+
maximum=30.0,
|
| 45 |
+
value=9.0,
|
| 46 |
+
step=0.1)
|
| 47 |
seed = gr.Slider(label='Seed',
|
| 48 |
minimum=-1,
|
| 49 |
maximum=2147483647,
|
| 50 |
step=1,
|
| 51 |
randomize=True)
|
| 52 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 53 |
a_prompt = gr.Textbox(
|
| 54 |
label='Added Prompt',
|
| 55 |
value='best quality, extremely detailed')
|
|
|
|
| 59 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 60 |
)
|
| 61 |
with gr.Column():
|
| 62 |
+
result_gallery = gr.Gallery(label='Output',
|
| 63 |
+
show_label=False,
|
| 64 |
+
elem_id='gallery').style(
|
| 65 |
+
grid=2, height='auto')
|
| 66 |
+
ips = [
|
| 67 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 68 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta,
|
| 69 |
+
bg_threshold
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
]
|
|
|
|
| 71 |
run_button.click(fn=process,
|
| 72 |
+
inputs=ips,
|
| 73 |
+
outputs=[result_gallery],
|
| 74 |
api_name='normal')
|
| 75 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_pose.py → gradio_pose2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_pose2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Human Pose')
|
|
@@ -13,41 +13,37 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
| 16 |
-
is_pose_image = gr.Checkbox(label='Is pose image',
|
| 17 |
-
value=False)
|
| 18 |
-
gr.Markdown(
|
| 19 |
-
'You can use [PoseMaker2](https://huggingface.co/spaces/jonigata/PoseMaker2) to create pose images.'
|
| 20 |
-
)
|
| 21 |
num_samples = gr.Slider(label='Images',
|
| 22 |
minimum=1,
|
| 23 |
maximum=max_images,
|
| 24 |
-
value=
|
| 25 |
step=1)
|
| 26 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 27 |
minimum=256,
|
| 28 |
-
maximum=
|
| 29 |
value=512,
|
| 30 |
step=256)
|
| 31 |
detect_resolution = gr.Slider(label='OpenPose Resolution',
|
| 32 |
minimum=128,
|
| 33 |
-
maximum=
|
| 34 |
value=512,
|
| 35 |
step=1)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
seed = gr.Slider(label='Seed',
|
| 47 |
minimum=-1,
|
| 48 |
maximum=2147483647,
|
| 49 |
step=1,
|
| 50 |
randomize=True)
|
|
|
|
| 51 |
a_prompt = gr.Textbox(
|
| 52 |
label='Added Prompt',
|
| 53 |
value='best quality, extremely detailed')
|
|
@@ -57,33 +53,16 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 57 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 58 |
)
|
| 59 |
with gr.Column():
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
input_image,
|
| 66 |
-
|
| 67 |
-
a_prompt,
|
| 68 |
-
n_prompt,
|
| 69 |
-
num_samples,
|
| 70 |
-
image_resolution,
|
| 71 |
-
detect_resolution,
|
| 72 |
-
num_steps,
|
| 73 |
-
guidance_scale,
|
| 74 |
-
seed,
|
| 75 |
-
is_pose_image,
|
| 76 |
]
|
| 77 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 78 |
run_button.click(fn=process,
|
| 79 |
-
inputs=
|
| 80 |
-
outputs=
|
| 81 |
api_name='pose')
|
| 82 |
return demo
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
if __name__ == '__main__':
|
| 86 |
-
from model import Model
|
| 87 |
-
model = Model()
|
| 88 |
-
demo = create_demo(model.process_pose)
|
| 89 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_pose2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Human Pose')
|
|
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(label='OpenPose Resolution',
|
| 27 |
minimum=128,
|
| 28 |
+
maximum=1024,
|
| 29 |
value=512,
|
| 30 |
step=1)
|
| 31 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 32 |
+
minimum=1,
|
| 33 |
+
maximum=100,
|
| 34 |
+
value=20,
|
| 35 |
+
step=1)
|
| 36 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 37 |
+
minimum=0.1,
|
| 38 |
+
maximum=30.0,
|
| 39 |
+
value=9.0,
|
| 40 |
+
step=0.1)
|
| 41 |
seed = gr.Slider(label='Seed',
|
| 42 |
minimum=-1,
|
| 43 |
maximum=2147483647,
|
| 44 |
step=1,
|
| 45 |
randomize=True)
|
| 46 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 47 |
a_prompt = gr.Textbox(
|
| 48 |
label='Added Prompt',
|
| 49 |
value='best quality, extremely detailed')
|
|
|
|
| 53 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 54 |
)
|
| 55 |
with gr.Column():
|
| 56 |
+
result_gallery = gr.Gallery(label='Output',
|
| 57 |
+
show_label=False,
|
| 58 |
+
elem_id='gallery').style(
|
| 59 |
+
grid=2, height='auto')
|
| 60 |
+
ips = [
|
| 61 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 62 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
]
|
|
|
|
| 64 |
run_button.click(fn=process,
|
| 65 |
+
inputs=ips,
|
| 66 |
+
outputs=[result_gallery],
|
| 67 |
api_name='pose')
|
| 68 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_scribble.py → gradio_scribble2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_scribble2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Scribble Maps')
|
|
@@ -16,28 +16,29 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
-
maximum=
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
seed = gr.Slider(label='Seed',
|
| 37 |
minimum=-1,
|
| 38 |
maximum=2147483647,
|
| 39 |
step=1,
|
| 40 |
randomize=True)
|
|
|
|
| 41 |
a_prompt = gr.Textbox(
|
| 42 |
label='Added Prompt',
|
| 43 |
value='best quality, extremely detailed')
|
|
@@ -47,31 +48,16 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 47 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 48 |
)
|
| 49 |
with gr.Column():
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
input_image,
|
| 56 |
-
|
| 57 |
-
a_prompt,
|
| 58 |
-
n_prompt,
|
| 59 |
-
num_samples,
|
| 60 |
-
image_resolution,
|
| 61 |
-
num_steps,
|
| 62 |
-
guidance_scale,
|
| 63 |
-
seed,
|
| 64 |
]
|
| 65 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 66 |
run_button.click(fn=process,
|
| 67 |
-
inputs=
|
| 68 |
-
outputs=
|
| 69 |
api_name='scribble')
|
| 70 |
return demo
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
if __name__ == '__main__':
|
| 74 |
-
from model import Model
|
| 75 |
-
model = Model()
|
| 76 |
-
demo = create_demo(model.process_scribble)
|
| 77 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_scribble2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Scribble Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 27 |
+
minimum=1,
|
| 28 |
+
maximum=100,
|
| 29 |
+
value=20,
|
| 30 |
+
step=1)
|
| 31 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 32 |
+
minimum=0.1,
|
| 33 |
+
maximum=30.0,
|
| 34 |
+
value=9.0,
|
| 35 |
+
step=0.1)
|
| 36 |
seed = gr.Slider(label='Seed',
|
| 37 |
minimum=-1,
|
| 38 |
maximum=2147483647,
|
| 39 |
step=1,
|
| 40 |
randomize=True)
|
| 41 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 42 |
a_prompt = gr.Textbox(
|
| 43 |
label='Added Prompt',
|
| 44 |
value='best quality, extremely detailed')
|
|
|
|
| 48 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 49 |
)
|
| 50 |
with gr.Column():
|
| 51 |
+
result_gallery = gr.Gallery(label='Output',
|
| 52 |
+
show_label=False,
|
| 53 |
+
elem_id='gallery').style(
|
| 54 |
+
grid=2, height='auto')
|
| 55 |
+
ips = [
|
| 56 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 57 |
+
image_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
]
|
|
|
|
| 59 |
run_button.click(fn=process,
|
| 60 |
+
inputs=ips,
|
| 61 |
+
outputs=[result_gallery],
|
| 62 |
api_name='scribble')
|
| 63 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_scribble_interactive.py → gradio_scribble2image_interactive.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_scribble2image_interactive.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
|
|
@@ -8,7 +8,7 @@ def create_canvas(w, h):
|
|
| 8 |
return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
|
| 9 |
|
| 10 |
|
| 11 |
-
def create_demo(process, max_images=12
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
with gr.Row():
|
| 14 |
gr.Markdown(
|
|
@@ -17,12 +17,12 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 17 |
with gr.Column():
|
| 18 |
canvas_width = gr.Slider(label='Canvas Width',
|
| 19 |
minimum=256,
|
| 20 |
-
maximum=
|
| 21 |
value=512,
|
| 22 |
step=1)
|
| 23 |
canvas_height = gr.Slider(label='Canvas Height',
|
| 24 |
minimum=256,
|
| 25 |
-
maximum=
|
| 26 |
value=512,
|
| 27 |
step=1)
|
| 28 |
create_button = gr.Button(label='Start',
|
|
@@ -37,36 +37,36 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 37 |
)
|
| 38 |
create_button.click(fn=create_canvas,
|
| 39 |
inputs=[canvas_width, canvas_height],
|
| 40 |
-
outputs=input_image
|
| 41 |
-
queue=False)
|
| 42 |
prompt = gr.Textbox(label='Prompt')
|
| 43 |
run_button = gr.Button(label='Run')
|
| 44 |
with gr.Accordion('Advanced options', open=False):
|
| 45 |
num_samples = gr.Slider(label='Images',
|
| 46 |
minimum=1,
|
| 47 |
maximum=max_images,
|
| 48 |
-
value=
|
| 49 |
step=1)
|
| 50 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 51 |
minimum=256,
|
| 52 |
-
maximum=
|
| 53 |
value=512,
|
| 54 |
step=256)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
seed = gr.Slider(label='Seed',
|
| 66 |
minimum=-1,
|
| 67 |
maximum=2147483647,
|
| 68 |
step=1,
|
| 69 |
randomize=True)
|
|
|
|
| 70 |
a_prompt = gr.Textbox(
|
| 71 |
label='Added Prompt',
|
| 72 |
value='best quality, extremely detailed')
|
|
@@ -76,28 +76,13 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 76 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 77 |
)
|
| 78 |
with gr.Column():
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
input_image,
|
| 85 |
-
|
| 86 |
-
a_prompt,
|
| 87 |
-
n_prompt,
|
| 88 |
-
num_samples,
|
| 89 |
-
image_resolution,
|
| 90 |
-
num_steps,
|
| 91 |
-
guidance_scale,
|
| 92 |
-
seed,
|
| 93 |
]
|
| 94 |
-
|
| 95 |
-
run_button.click(fn=process, inputs=inputs, outputs=result)
|
| 96 |
return demo
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
if __name__ == '__main__':
|
| 100 |
-
from model import Model
|
| 101 |
-
model = Model()
|
| 102 |
-
demo = create_demo(model.process_scribble_interactive)
|
| 103 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_scribble2image_interactive.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
|
|
|
|
| 8 |
return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
|
| 9 |
|
| 10 |
|
| 11 |
+
def create_demo(process, max_images=12):
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
with gr.Row():
|
| 14 |
gr.Markdown(
|
|
|
|
| 17 |
with gr.Column():
|
| 18 |
canvas_width = gr.Slider(label='Canvas Width',
|
| 19 |
minimum=256,
|
| 20 |
+
maximum=1024,
|
| 21 |
value=512,
|
| 22 |
step=1)
|
| 23 |
canvas_height = gr.Slider(label='Canvas Height',
|
| 24 |
minimum=256,
|
| 25 |
+
maximum=1024,
|
| 26 |
value=512,
|
| 27 |
step=1)
|
| 28 |
create_button = gr.Button(label='Start',
|
|
|
|
| 37 |
)
|
| 38 |
create_button.click(fn=create_canvas,
|
| 39 |
inputs=[canvas_width, canvas_height],
|
| 40 |
+
outputs=[input_image])
|
|
|
|
| 41 |
prompt = gr.Textbox(label='Prompt')
|
| 42 |
run_button = gr.Button(label='Run')
|
| 43 |
with gr.Accordion('Advanced options', open=False):
|
| 44 |
num_samples = gr.Slider(label='Images',
|
| 45 |
minimum=1,
|
| 46 |
maximum=max_images,
|
| 47 |
+
value=1,
|
| 48 |
step=1)
|
| 49 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 50 |
minimum=256,
|
| 51 |
+
maximum=768,
|
| 52 |
value=512,
|
| 53 |
step=256)
|
| 54 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 55 |
+
minimum=1,
|
| 56 |
+
maximum=100,
|
| 57 |
+
value=20,
|
| 58 |
+
step=1)
|
| 59 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 60 |
+
minimum=0.1,
|
| 61 |
+
maximum=30.0,
|
| 62 |
+
value=9.0,
|
| 63 |
+
step=0.1)
|
| 64 |
seed = gr.Slider(label='Seed',
|
| 65 |
minimum=-1,
|
| 66 |
maximum=2147483647,
|
| 67 |
step=1,
|
| 68 |
randomize=True)
|
| 69 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 70 |
a_prompt = gr.Textbox(
|
| 71 |
label='Added Prompt',
|
| 72 |
value='best quality, extremely detailed')
|
|
|
|
| 76 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 77 |
)
|
| 78 |
with gr.Column():
|
| 79 |
+
result_gallery = gr.Gallery(label='Output',
|
| 80 |
+
show_label=False,
|
| 81 |
+
elem_id='gallery').style(
|
| 82 |
+
grid=2, height='auto')
|
| 83 |
+
ips = [
|
| 84 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 85 |
+
image_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
]
|
| 87 |
+
run_button.click(fn=process, inputs=ips, outputs=[result_gallery])
|
|
|
|
| 88 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_seg.py → gradio_seg2image.py
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_seg2image.py
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Segmentation Maps')
|
|
@@ -13,39 +13,38 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
| 16 |
-
is_segmentation_map = gr.Checkbox(
|
| 17 |
-
label='Is segmentation map', value=False)
|
| 18 |
num_samples = gr.Slider(label='Images',
|
| 19 |
minimum=1,
|
| 20 |
maximum=max_images,
|
| 21 |
-
value=
|
| 22 |
step=1)
|
| 23 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 24 |
minimum=256,
|
| 25 |
-
maximum=
|
| 26 |
value=512,
|
| 27 |
step=256)
|
| 28 |
detect_resolution = gr.Slider(
|
| 29 |
label='Segmentation Resolution',
|
| 30 |
minimum=128,
|
| 31 |
-
maximum=
|
| 32 |
value=512,
|
| 33 |
step=1)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
seed = gr.Slider(label='Seed',
|
| 45 |
minimum=-1,
|
| 46 |
maximum=2147483647,
|
| 47 |
step=1,
|
| 48 |
randomize=True)
|
|
|
|
| 49 |
a_prompt = gr.Textbox(
|
| 50 |
label='Added Prompt',
|
| 51 |
value='best quality, extremely detailed')
|
|
@@ -55,33 +54,16 @@ def create_demo(process, max_images=12, default_num_images=3):
|
|
| 55 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 56 |
)
|
| 57 |
with gr.Column():
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
input_image,
|
| 64 |
-
|
| 65 |
-
a_prompt,
|
| 66 |
-
n_prompt,
|
| 67 |
-
num_samples,
|
| 68 |
-
image_resolution,
|
| 69 |
-
detect_resolution,
|
| 70 |
-
num_steps,
|
| 71 |
-
guidance_scale,
|
| 72 |
-
seed,
|
| 73 |
-
is_segmentation_map,
|
| 74 |
]
|
| 75 |
-
prompt.submit(fn=process, inputs=inputs, outputs=result)
|
| 76 |
run_button.click(fn=process,
|
| 77 |
-
inputs=
|
| 78 |
-
outputs=
|
| 79 |
api_name='seg')
|
| 80 |
return demo
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
if __name__ == '__main__':
|
| 84 |
-
from model import Model
|
| 85 |
-
model = Model()
|
| 86 |
-
demo = create_demo(model.process_seg)
|
| 87 |
-
demo.queue().launch()
|
|
|
|
| 1 |
# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_seg2image.py
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Segmentation Maps')
|
|
|
|
| 13 |
prompt = gr.Textbox(label='Prompt')
|
| 14 |
run_button = gr.Button(label='Run')
|
| 15 |
with gr.Accordion('Advanced options', open=False):
|
|
|
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=1,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
| 23 |
+
maximum=768,
|
| 24 |
value=512,
|
| 25 |
step=256)
|
| 26 |
detect_resolution = gr.Slider(
|
| 27 |
label='Segmentation Resolution',
|
| 28 |
minimum=128,
|
| 29 |
+
maximum=1024,
|
| 30 |
value=512,
|
| 31 |
step=1)
|
| 32 |
+
ddim_steps = gr.Slider(label='Steps',
|
| 33 |
+
minimum=1,
|
| 34 |
+
maximum=100,
|
| 35 |
+
value=20,
|
| 36 |
+
step=1)
|
| 37 |
+
scale = gr.Slider(label='Guidance Scale',
|
| 38 |
+
minimum=0.1,
|
| 39 |
+
maximum=30.0,
|
| 40 |
+
value=9.0,
|
| 41 |
+
step=0.1)
|
| 42 |
seed = gr.Slider(label='Seed',
|
| 43 |
minimum=-1,
|
| 44 |
maximum=2147483647,
|
| 45 |
step=1,
|
| 46 |
randomize=True)
|
| 47 |
+
eta = gr.Number(label='eta (DDIM)', value=0.0)
|
| 48 |
a_prompt = gr.Textbox(
|
| 49 |
label='Added Prompt',
|
| 50 |
value='best quality, extremely detailed')
|
|
|
|
| 54 |
'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
|
| 55 |
)
|
| 56 |
with gr.Column():
|
| 57 |
+
result_gallery = gr.Gallery(label='Output',
|
| 58 |
+
show_label=False,
|
| 59 |
+
elem_id='gallery').style(
|
| 60 |
+
grid=2, height='auto')
|
| 61 |
+
ips = [
|
| 62 |
+
input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 63 |
+
image_resolution, detect_resolution, ddim_steps, scale, seed, eta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
]
|
|
|
|
| 65 |
run_button.click(fn=process,
|
| 66 |
+
inputs=ips,
|
| 67 |
+
outputs=[result_gallery],
|
| 68 |
api_name='seg')
|
| 69 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.py
CHANGED
|
@@ -1,649 +1,725 @@
|
|
| 1 |
# This file is adapted from gradio_*.py in https://github.com/lllyasviel/ControlNet/tree/f4748e3630d8141d7765e2bd9b1e348f47847707
|
| 2 |
-
# The original license file is LICENSE.ControlNet
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
-
import gc
|
| 6 |
import pathlib
|
|
|
|
|
|
|
|
|
|
| 7 |
import sys
|
| 8 |
|
| 9 |
import cv2
|
|
|
|
| 10 |
import numpy as np
|
| 11 |
-
import PIL.Image
|
| 12 |
import torch
|
| 13 |
-
from
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
from annotator.util import HWC3, resize_image
|
| 29 |
-
except Exception:
|
| 30 |
-
pass
|
| 31 |
-
|
| 32 |
-
CONTROLNET_MODEL_IDS = {
|
| 33 |
-
'canny': 'lllyasviel/sd-controlnet-canny',
|
| 34 |
-
'hough': 'lllyasviel/sd-controlnet-mlsd',
|
| 35 |
-
'hed': 'lllyasviel/sd-controlnet-hed',
|
| 36 |
-
'scribble': 'lllyasviel/sd-controlnet-scribble',
|
| 37 |
-
'pose': 'lllyasviel/sd-controlnet-openpose',
|
| 38 |
-
'seg': 'lllyasviel/sd-controlnet-seg',
|
| 39 |
-
'depth': 'lllyasviel/sd-controlnet-depth',
|
| 40 |
-
'normal': 'lllyasviel/sd-controlnet-normal',
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def download_all_controlnet_weights() -> None:
|
| 45 |
-
for model_id in CONTROLNET_MODEL_IDS.values():
|
| 46 |
-
ControlNetModel.from_pretrained(model_id)
|
| 47 |
|
| 48 |
|
| 49 |
class Model:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def __init__(self,
|
| 51 |
-
|
| 52 |
-
|
| 53 |
self.device = torch.device(
|
| 54 |
'cuda:0' if torch.cuda.is_available() else 'cpu')
|
| 55 |
-
self.
|
|
|
|
| 56 |
self.task_name = ''
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
if base_model_id == self.base_model_id and task_name == self.task_name and hasattr(
|
| 63 |
-
self, 'pipe'):
|
| 64 |
-
return self.pipe
|
| 65 |
-
model_id = CONTROLNET_MODEL_IDS[task_name]
|
| 66 |
-
controlnet = ControlNetModel.from_pretrained(model_id,
|
| 67 |
-
torch_dtype=torch.float16)
|
| 68 |
-
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
| 69 |
-
base_model_id,
|
| 70 |
-
safety_checker=None,
|
| 71 |
-
controlnet=controlnet,
|
| 72 |
-
torch_dtype=torch.float16)
|
| 73 |
-
pipe.scheduler = UniPCMultistepScheduler.from_config(
|
| 74 |
-
pipe.scheduler.config)
|
| 75 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 76 |
-
pipe.to(self.device)
|
| 77 |
-
torch.cuda.empty_cache()
|
| 78 |
-
gc.collect()
|
| 79 |
-
self.base_model_id = base_model_id
|
| 80 |
-
self.task_name = task_name
|
| 81 |
-
return pipe
|
| 82 |
-
|
| 83 |
-
def set_base_model(self, base_model_id: str) -> str:
|
| 84 |
-
if not base_model_id or base_model_id == self.base_model_id:
|
| 85 |
-
return self.base_model_id
|
| 86 |
-
del self.pipe
|
| 87 |
-
torch.cuda.empty_cache()
|
| 88 |
-
gc.collect()
|
| 89 |
-
try:
|
| 90 |
-
self.pipe = self.load_pipe(base_model_id, self.task_name)
|
| 91 |
-
except Exception:
|
| 92 |
-
self.pipe = self.load_pipe(self.base_model_id, self.task_name)
|
| 93 |
-
return self.base_model_id
|
| 94 |
-
|
| 95 |
-
def load_controlnet_weight(self, task_name: str) -> None:
|
| 96 |
if task_name == self.task_name:
|
| 97 |
return
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
gc.collect()
|
| 102 |
-
model_id = CONTROLNET_MODEL_IDS[task_name]
|
| 103 |
-
controlnet = ControlNetModel.from_pretrained(model_id,
|
| 104 |
-
torch_dtype=torch.float16)
|
| 105 |
-
controlnet.to(self.device)
|
| 106 |
-
torch.cuda.empty_cache()
|
| 107 |
-
gc.collect()
|
| 108 |
-
self.pipe.controlnet = controlnet
|
| 109 |
self.task_name = task_name
|
| 110 |
|
| 111 |
-
def
|
| 112 |
-
if
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
if seed == -1:
|
| 130 |
-
seed =
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
@torch.inference_mode()
|
| 155 |
-
def
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
num_images: int,
|
| 162 |
-
image_resolution: int,
|
| 163 |
-
num_steps: int,
|
| 164 |
-
guidance_scale: float,
|
| 165 |
-
seed: int,
|
| 166 |
-
low_threshold: int,
|
| 167 |
-
high_threshold: int,
|
| 168 |
-
) -> list[PIL.Image.Image]:
|
| 169 |
-
control_image, vis_control_image = self.preprocess_canny(
|
| 170 |
-
input_image=input_image,
|
| 171 |
-
image_resolution=image_resolution,
|
| 172 |
-
low_threshold=low_threshold,
|
| 173 |
-
high_threshold=high_threshold,
|
| 174 |
-
)
|
| 175 |
-
self.load_controlnet_weight('canny')
|
| 176 |
-
results = self.run_pipe(
|
| 177 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 178 |
-
negative_prompt=negative_prompt,
|
| 179 |
-
control_image=control_image,
|
| 180 |
-
num_images=num_images,
|
| 181 |
-
num_steps=num_steps,
|
| 182 |
-
guidance_scale=guidance_scale,
|
| 183 |
-
seed=seed,
|
| 184 |
-
)
|
| 185 |
-
return [vis_control_image] + results
|
| 186 |
-
|
| 187 |
-
@staticmethod
|
| 188 |
-
def preprocess_hough(
|
| 189 |
-
input_image: np.ndarray,
|
| 190 |
-
image_resolution: int,
|
| 191 |
-
detect_resolution: int,
|
| 192 |
-
value_threshold: float,
|
| 193 |
-
distance_threshold: float,
|
| 194 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 195 |
input_image = HWC3(input_image)
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
H, W = image.shape[:2]
|
| 202 |
-
control_image = cv2.resize(control_image, (W, H),
|
| 203 |
-
interpolation=cv2.INTER_NEAREST)
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
@torch.inference_mode()
|
| 212 |
-
def
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
negative_prompt: str,
|
| 218 |
-
num_images: int,
|
| 219 |
-
image_resolution: int,
|
| 220 |
-
detect_resolution: int,
|
| 221 |
-
num_steps: int,
|
| 222 |
-
guidance_scale: float,
|
| 223 |
-
seed: int,
|
| 224 |
-
value_threshold: float,
|
| 225 |
-
distance_threshold: float,
|
| 226 |
-
) -> list[PIL.Image.Image]:
|
| 227 |
-
control_image, vis_control_image = self.preprocess_hough(
|
| 228 |
-
input_image=input_image,
|
| 229 |
-
image_resolution=image_resolution,
|
| 230 |
-
detect_resolution=detect_resolution,
|
| 231 |
-
value_threshold=value_threshold,
|
| 232 |
-
distance_threshold=distance_threshold,
|
| 233 |
-
)
|
| 234 |
-
self.load_controlnet_weight('hough')
|
| 235 |
-
results = self.run_pipe(
|
| 236 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 237 |
-
negative_prompt=negative_prompt,
|
| 238 |
-
control_image=control_image,
|
| 239 |
-
num_images=num_images,
|
| 240 |
-
num_steps=num_steps,
|
| 241 |
-
guidance_scale=guidance_scale,
|
| 242 |
-
seed=seed,
|
| 243 |
-
)
|
| 244 |
-
return [vis_control_image] + results
|
| 245 |
-
|
| 246 |
-
@staticmethod
|
| 247 |
-
def preprocess_hed(
|
| 248 |
-
input_image: np.ndarray,
|
| 249 |
-
image_resolution: int,
|
| 250 |
-
detect_resolution: int,
|
| 251 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 252 |
input_image = HWC3(input_image)
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
H, W =
|
| 257 |
-
control_image = cv2.resize(control_image, (W, H),
|
| 258 |
-
interpolation=cv2.INTER_LINEAR)
|
| 259 |
-
return PIL.Image.fromarray(control_image), PIL.Image.fromarray(
|
| 260 |
-
control_image)
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
@torch.inference_mode()
|
| 306 |
-
def process_scribble(
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
@torch.inference_mode()
|
| 348 |
-
def process_scribble_interactive(
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
additional_prompt: str,
|
| 353 |
-
negative_prompt: str,
|
| 354 |
-
num_images: int,
|
| 355 |
-
image_resolution: int,
|
| 356 |
-
num_steps: int,
|
| 357 |
-
guidance_scale: float,
|
| 358 |
-
seed: int,
|
| 359 |
-
) -> list[PIL.Image.Image]:
|
| 360 |
-
control_image, vis_control_image = self.preprocess_scribble_interactive(
|
| 361 |
-
input_image=input_image,
|
| 362 |
-
image_resolution=image_resolution,
|
| 363 |
-
)
|
| 364 |
-
self.load_controlnet_weight('scribble')
|
| 365 |
-
results = self.run_pipe(
|
| 366 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 367 |
-
negative_prompt=negative_prompt,
|
| 368 |
-
control_image=control_image,
|
| 369 |
-
num_images=num_images,
|
| 370 |
-
num_steps=num_steps,
|
| 371 |
-
guidance_scale=guidance_scale,
|
| 372 |
-
seed=seed,
|
| 373 |
-
)
|
| 374 |
-
return [vis_control_image] + results
|
| 375 |
-
|
| 376 |
-
@staticmethod
|
| 377 |
-
def preprocess_fake_scribble(
|
| 378 |
-
input_image: np.ndarray,
|
| 379 |
-
image_resolution: int,
|
| 380 |
-
detect_resolution: int,
|
| 381 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 382 |
-
input_image = HWC3(input_image)
|
| 383 |
-
control_image = apply_hed(resize_image(input_image, detect_resolution))
|
| 384 |
-
control_image = HWC3(control_image)
|
| 385 |
-
image = resize_image(input_image, image_resolution)
|
| 386 |
-
H, W = image.shape[:2]
|
| 387 |
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
control_image = cv2.GaussianBlur(control_image, (0, 0), 3.0)
|
| 392 |
-
control_image[control_image > 4] = 255
|
| 393 |
-
control_image[control_image < 255] = 0
|
| 394 |
|
| 395 |
-
|
|
|
|
| 396 |
|
| 397 |
-
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
@torch.inference_mode()
|
| 401 |
-
def process_fake_scribble(
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
negative_prompt: str,
|
| 407 |
-
num_images: int,
|
| 408 |
-
image_resolution: int,
|
| 409 |
-
detect_resolution: int,
|
| 410 |
-
num_steps: int,
|
| 411 |
-
guidance_scale: float,
|
| 412 |
-
seed: int,
|
| 413 |
-
) -> list[PIL.Image.Image]:
|
| 414 |
-
control_image, vis_control_image = self.preprocess_fake_scribble(
|
| 415 |
-
input_image=input_image,
|
| 416 |
-
image_resolution=image_resolution,
|
| 417 |
-
detect_resolution=detect_resolution,
|
| 418 |
-
)
|
| 419 |
-
self.load_controlnet_weight('scribble')
|
| 420 |
-
results = self.run_pipe(
|
| 421 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 422 |
-
negative_prompt=negative_prompt,
|
| 423 |
-
control_image=control_image,
|
| 424 |
-
num_images=num_images,
|
| 425 |
-
num_steps=num_steps,
|
| 426 |
-
guidance_scale=guidance_scale,
|
| 427 |
-
seed=seed,
|
| 428 |
-
)
|
| 429 |
-
return [vis_control_image] + results
|
| 430 |
-
|
| 431 |
-
@staticmethod
|
| 432 |
-
def preprocess_pose(
|
| 433 |
-
input_image: np.ndarray,
|
| 434 |
-
image_resolution: int,
|
| 435 |
-
detect_resolution: int,
|
| 436 |
-
is_pose_image: bool,
|
| 437 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 438 |
input_image = HWC3(input_image)
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
@torch.inference_mode()
|
| 454 |
-
def process_pose(
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
negative_prompt: str,
|
| 460 |
-
num_images: int,
|
| 461 |
-
image_resolution: int,
|
| 462 |
-
detect_resolution: int,
|
| 463 |
-
num_steps: int,
|
| 464 |
-
guidance_scale: float,
|
| 465 |
-
seed: int,
|
| 466 |
-
is_pose_image: bool,
|
| 467 |
-
) -> list[PIL.Image.Image]:
|
| 468 |
-
control_image, vis_control_image = self.preprocess_pose(
|
| 469 |
-
input_image=input_image,
|
| 470 |
-
image_resolution=image_resolution,
|
| 471 |
-
detect_resolution=detect_resolution,
|
| 472 |
-
is_pose_image=is_pose_image,
|
| 473 |
-
)
|
| 474 |
-
self.load_controlnet_weight('pose')
|
| 475 |
-
results = self.run_pipe(
|
| 476 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 477 |
-
negative_prompt=negative_prompt,
|
| 478 |
-
control_image=control_image,
|
| 479 |
-
num_images=num_images,
|
| 480 |
-
num_steps=num_steps,
|
| 481 |
-
guidance_scale=guidance_scale,
|
| 482 |
-
seed=seed,
|
| 483 |
-
)
|
| 484 |
-
return [vis_control_image] + results
|
| 485 |
-
|
| 486 |
-
@staticmethod
|
| 487 |
-
def preprocess_seg(
|
| 488 |
-
input_image: np.ndarray,
|
| 489 |
-
image_resolution: int,
|
| 490 |
-
detect_resolution: int,
|
| 491 |
-
is_segmentation_map: bool,
|
| 492 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 493 |
input_image = HWC3(input_image)
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
|
| 506 |
@torch.inference_mode()
|
| 507 |
-
def process_seg(
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
negative_prompt: str,
|
| 513 |
-
num_images: int,
|
| 514 |
-
image_resolution: int,
|
| 515 |
-
detect_resolution: int,
|
| 516 |
-
num_steps: int,
|
| 517 |
-
guidance_scale: float,
|
| 518 |
-
seed: int,
|
| 519 |
-
is_segmentation_map: bool,
|
| 520 |
-
) -> list[PIL.Image.Image]:
|
| 521 |
-
control_image, vis_control_image = self.preprocess_seg(
|
| 522 |
-
input_image=input_image,
|
| 523 |
-
image_resolution=image_resolution,
|
| 524 |
-
detect_resolution=detect_resolution,
|
| 525 |
-
is_segmentation_map=is_segmentation_map,
|
| 526 |
-
)
|
| 527 |
-
self.load_controlnet_weight('seg')
|
| 528 |
-
results = self.run_pipe(
|
| 529 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 530 |
-
negative_prompt=negative_prompt,
|
| 531 |
-
control_image=control_image,
|
| 532 |
-
num_images=num_images,
|
| 533 |
-
num_steps=num_steps,
|
| 534 |
-
guidance_scale=guidance_scale,
|
| 535 |
-
seed=seed,
|
| 536 |
-
)
|
| 537 |
-
return [vis_control_image] + results
|
| 538 |
-
|
| 539 |
-
@staticmethod
|
| 540 |
-
def preprocess_depth(
|
| 541 |
-
input_image: np.ndarray,
|
| 542 |
-
image_resolution: int,
|
| 543 |
-
detect_resolution: int,
|
| 544 |
-
is_depth_image: bool,
|
| 545 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 546 |
input_image = HWC3(input_image)
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
|
| 560 |
@torch.inference_mode()
|
| 561 |
-
def process_depth(
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
negative_prompt: str,
|
| 567 |
-
num_images: int,
|
| 568 |
-
image_resolution: int,
|
| 569 |
-
detect_resolution: int,
|
| 570 |
-
num_steps: int,
|
| 571 |
-
guidance_scale: float,
|
| 572 |
-
seed: int,
|
| 573 |
-
is_depth_image: bool,
|
| 574 |
-
) -> list[PIL.Image.Image]:
|
| 575 |
-
control_image, vis_control_image = self.preprocess_depth(
|
| 576 |
-
input_image=input_image,
|
| 577 |
-
image_resolution=image_resolution,
|
| 578 |
-
detect_resolution=detect_resolution,
|
| 579 |
-
is_depth_image=is_depth_image,
|
| 580 |
-
)
|
| 581 |
-
self.load_controlnet_weight('depth')
|
| 582 |
-
results = self.run_pipe(
|
| 583 |
-
prompt=self.get_prompt(prompt, additional_prompt),
|
| 584 |
-
negative_prompt=negative_prompt,
|
| 585 |
-
control_image=control_image,
|
| 586 |
-
num_images=num_images,
|
| 587 |
-
num_steps=num_steps,
|
| 588 |
-
guidance_scale=guidance_scale,
|
| 589 |
-
seed=seed,
|
| 590 |
-
)
|
| 591 |
-
return [vis_control_image] + results
|
| 592 |
-
|
| 593 |
-
@staticmethod
|
| 594 |
-
def preprocess_normal(
|
| 595 |
-
input_image: np.ndarray,
|
| 596 |
-
image_resolution: int,
|
| 597 |
-
detect_resolution: int,
|
| 598 |
-
bg_threshold: float,
|
| 599 |
-
is_normal_image: bool,
|
| 600 |
-
) -> tuple[PIL.Image.Image, PIL.Image.Image]:
|
| 601 |
input_image = HWC3(input_image)
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
|
| 616 |
@torch.inference_mode()
|
| 617 |
-
def process_normal(
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# This file is adapted from gradio_*.py in https://github.com/lllyasviel/ControlNet/tree/f4748e3630d8141d7765e2bd9b1e348f47847707
|
| 2 |
+
# The original license file is LICENSE.ControlNet this repo.
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 5 |
import pathlib
|
| 6 |
+
import random
|
| 7 |
+
import shlex
|
| 8 |
+
import subprocess
|
| 9 |
import sys
|
| 10 |
|
| 11 |
import cv2
|
| 12 |
+
import einops
|
| 13 |
import numpy as np
|
|
|
|
| 14 |
import torch
|
| 15 |
+
from pytorch_lightning import seed_everything
|
| 16 |
+
|
| 17 |
+
sys.path.append('ControlNet')
|
| 18 |
+
|
| 19 |
+
import config
|
| 20 |
+
from annotator.canny import apply_canny
|
| 21 |
+
from annotator.hed import apply_hed, nms
|
| 22 |
+
from annotator.midas import apply_midas
|
| 23 |
+
from annotator.mlsd import apply_mlsd
|
| 24 |
+
from annotator.openpose import apply_openpose
|
| 25 |
+
from annotator.uniformer import apply_uniformer
|
| 26 |
+
from annotator.util import HWC3, resize_image
|
| 27 |
+
from cldm.model import create_model, load_state_dict
|
| 28 |
+
from ldm.models.diffusion.ddim import DDIMSampler
|
| 29 |
+
from share import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
class Model:
|
| 33 |
+
WEIGHT_NAMES = {
|
| 34 |
+
'canny': 'control_sd15_canny.pth',
|
| 35 |
+
'hough': 'control_sd15_mlsd.pth',
|
| 36 |
+
'hed': 'control_sd15_hed.pth',
|
| 37 |
+
'scribble': 'control_sd15_scribble.pth',
|
| 38 |
+
'pose': 'control_sd15_openpose.pth',
|
| 39 |
+
'seg': 'control_sd15_seg.pth',
|
| 40 |
+
'depth': 'control_sd15_depth.pth',
|
| 41 |
+
'normal': 'control_sd15_normal.pth',
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
def __init__(self,
|
| 45 |
+
model_config_path: str = 'ControlNet/models/cldm_v15.yaml',
|
| 46 |
+
model_dir: str = 'models'):
|
| 47 |
self.device = torch.device(
|
| 48 |
'cuda:0' if torch.cuda.is_available() else 'cpu')
|
| 49 |
+
self.model = create_model(model_config_path).to(self.device)
|
| 50 |
+
self.ddim_sampler = DDIMSampler(self.model)
|
| 51 |
self.task_name = ''
|
| 52 |
+
|
| 53 |
+
self.model_dir = pathlib.Path(model_dir)
|
| 54 |
+
self.download_models()
|
| 55 |
+
|
| 56 |
+
def load_weight(self, task_name: str) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if task_name == self.task_name:
|
| 58 |
return
|
| 59 |
+
weight_path = self.get_weight_path(task_name)
|
| 60 |
+
self.model.load_state_dict(
|
| 61 |
+
load_state_dict(weight_path, location=self.device))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
self.task_name = task_name
|
| 63 |
|
| 64 |
+
def get_weight_path(self, task_name: str) -> str:
|
| 65 |
+
if 'scribble' in task_name:
|
| 66 |
+
task_name = 'scribble'
|
| 67 |
+
return f'{self.model_dir}/{self.WEIGHT_NAMES[task_name]}'
|
| 68 |
+
|
| 69 |
+
def download_models(self):
|
| 70 |
+
self.model_dir.mkdir(exist_ok=True, parents=True)
|
| 71 |
+
for name in self.WEIGHT_NAMES.values():
|
| 72 |
+
out_path = self.model_dir / name
|
| 73 |
+
if out_path.exists():
|
| 74 |
+
continue
|
| 75 |
+
subprocess.run(
|
| 76 |
+
shlex.split(
|
| 77 |
+
f'wget https://huggingface.co/ckpt/ControlNet/resolve/main/{name} -O {out_path}'
|
| 78 |
+
))
|
| 79 |
+
|
| 80 |
+
@torch.inference_mode()
|
| 81 |
+
def process_canny(self, input_image, prompt, a_prompt, n_prompt,
|
| 82 |
+
num_samples, image_resolution, ddim_steps, scale, seed,
|
| 83 |
+
eta, low_threshold, high_threshold):
|
| 84 |
+
self.load_weight('canny')
|
| 85 |
+
|
| 86 |
+
img = resize_image(HWC3(input_image), image_resolution)
|
| 87 |
+
H, W, C = img.shape
|
| 88 |
+
|
| 89 |
+
detected_map = apply_canny(img, low_threshold, high_threshold)
|
| 90 |
+
detected_map = HWC3(detected_map)
|
| 91 |
+
|
| 92 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 93 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 94 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 95 |
+
|
| 96 |
if seed == -1:
|
| 97 |
+
seed = random.randint(0, 65535)
|
| 98 |
+
seed_everything(seed)
|
| 99 |
+
|
| 100 |
+
if config.save_memory:
|
| 101 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 102 |
+
|
| 103 |
+
cond = {
|
| 104 |
+
'c_concat': [control],
|
| 105 |
+
'c_crossattn': [
|
| 106 |
+
self.model.get_learned_conditioning(
|
| 107 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 108 |
+
]
|
| 109 |
+
}
|
| 110 |
+
un_cond = {
|
| 111 |
+
'c_concat': [control],
|
| 112 |
+
'c_crossattn':
|
| 113 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 114 |
+
}
|
| 115 |
+
shape = (4, H // 8, W // 8)
|
| 116 |
+
|
| 117 |
+
if config.save_memory:
|
| 118 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 119 |
+
|
| 120 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 121 |
+
ddim_steps,
|
| 122 |
+
num_samples,
|
| 123 |
+
shape,
|
| 124 |
+
cond,
|
| 125 |
+
verbose=False,
|
| 126 |
+
eta=eta,
|
| 127 |
+
unconditional_guidance_scale=scale,
|
| 128 |
+
unconditional_conditioning=un_cond)
|
| 129 |
+
|
| 130 |
+
if config.save_memory:
|
| 131 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 132 |
+
|
| 133 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 134 |
+
x_samples = (
|
| 135 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 136 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 137 |
+
|
| 138 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 139 |
+
return [255 - detected_map] + results
|
| 140 |
|
| 141 |
@torch.inference_mode()
|
| 142 |
+
def process_hough(self, input_image, prompt, a_prompt, n_prompt,
|
| 143 |
+
num_samples, image_resolution, detect_resolution,
|
| 144 |
+
ddim_steps, scale, seed, eta, value_threshold,
|
| 145 |
+
distance_threshold):
|
| 146 |
+
self.load_weight('hough')
|
| 147 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
input_image = HWC3(input_image)
|
| 149 |
+
detected_map = apply_mlsd(resize_image(input_image, detect_resolution),
|
| 150 |
+
value_threshold, distance_threshold)
|
| 151 |
+
detected_map = HWC3(detected_map)
|
| 152 |
+
img = resize_image(input_image, image_resolution)
|
| 153 |
+
H, W, C = img.shape
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 156 |
+
interpolation=cv2.INTER_NEAREST)
|
| 157 |
|
| 158 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 159 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 160 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 161 |
+
|
| 162 |
+
if seed == -1:
|
| 163 |
+
seed = random.randint(0, 65535)
|
| 164 |
+
seed_everything(seed)
|
| 165 |
+
|
| 166 |
+
if config.save_memory:
|
| 167 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 168 |
+
|
| 169 |
+
cond = {
|
| 170 |
+
'c_concat': [control],
|
| 171 |
+
'c_crossattn': [
|
| 172 |
+
self.model.get_learned_conditioning(
|
| 173 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 174 |
+
]
|
| 175 |
+
}
|
| 176 |
+
un_cond = {
|
| 177 |
+
'c_concat': [control],
|
| 178 |
+
'c_crossattn':
|
| 179 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 180 |
+
}
|
| 181 |
+
shape = (4, H // 8, W // 8)
|
| 182 |
+
|
| 183 |
+
if config.save_memory:
|
| 184 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 185 |
+
|
| 186 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 187 |
+
ddim_steps,
|
| 188 |
+
num_samples,
|
| 189 |
+
shape,
|
| 190 |
+
cond,
|
| 191 |
+
verbose=False,
|
| 192 |
+
eta=eta,
|
| 193 |
+
unconditional_guidance_scale=scale,
|
| 194 |
+
unconditional_conditioning=un_cond)
|
| 195 |
+
|
| 196 |
+
if config.save_memory:
|
| 197 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 198 |
+
|
| 199 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 200 |
+
x_samples = (
|
| 201 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 202 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 203 |
+
|
| 204 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 205 |
+
return [
|
| 206 |
+
255 - cv2.dilate(detected_map,
|
| 207 |
+
np.ones(shape=(3, 3), dtype=np.uint8),
|
| 208 |
+
iterations=1)
|
| 209 |
+
] + results
|
| 210 |
|
| 211 |
@torch.inference_mode()
|
| 212 |
+
def process_hed(self, input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 213 |
+
image_resolution, detect_resolution, ddim_steps, scale,
|
| 214 |
+
seed, eta):
|
| 215 |
+
self.load_weight('hed')
|
| 216 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
input_image = HWC3(input_image)
|
| 218 |
+
detected_map = apply_hed(resize_image(input_image, detect_resolution))
|
| 219 |
+
detected_map = HWC3(detected_map)
|
| 220 |
+
img = resize_image(input_image, image_resolution)
|
| 221 |
+
H, W, C = img.shape
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 224 |
+
interpolation=cv2.INTER_LINEAR)
|
| 225 |
+
|
| 226 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 227 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 228 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 229 |
+
|
| 230 |
+
if seed == -1:
|
| 231 |
+
seed = random.randint(0, 65535)
|
| 232 |
+
seed_everything(seed)
|
| 233 |
+
|
| 234 |
+
if config.save_memory:
|
| 235 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 236 |
+
|
| 237 |
+
cond = {
|
| 238 |
+
'c_concat': [control],
|
| 239 |
+
'c_crossattn': [
|
| 240 |
+
self.model.get_learned_conditioning(
|
| 241 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 242 |
+
]
|
| 243 |
+
}
|
| 244 |
+
un_cond = {
|
| 245 |
+
'c_concat': [control],
|
| 246 |
+
'c_crossattn':
|
| 247 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 248 |
+
}
|
| 249 |
+
shape = (4, H // 8, W // 8)
|
| 250 |
+
|
| 251 |
+
if config.save_memory:
|
| 252 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 253 |
+
|
| 254 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 255 |
+
ddim_steps,
|
| 256 |
+
num_samples,
|
| 257 |
+
shape,
|
| 258 |
+
cond,
|
| 259 |
+
verbose=False,
|
| 260 |
+
eta=eta,
|
| 261 |
+
unconditional_guidance_scale=scale,
|
| 262 |
+
unconditional_conditioning=un_cond)
|
| 263 |
+
|
| 264 |
+
if config.save_memory:
|
| 265 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 266 |
+
|
| 267 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 268 |
+
x_samples = (
|
| 269 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 270 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 271 |
+
|
| 272 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 273 |
+
return [detected_map] + results
|
| 274 |
|
| 275 |
@torch.inference_mode()
|
| 276 |
+
def process_scribble(self, input_image, prompt, a_prompt, n_prompt,
|
| 277 |
+
num_samples, image_resolution, ddim_steps, scale,
|
| 278 |
+
seed, eta):
|
| 279 |
+
self.load_weight('scribble')
|
| 280 |
+
|
| 281 |
+
img = resize_image(HWC3(input_image), image_resolution)
|
| 282 |
+
H, W, C = img.shape
|
| 283 |
+
|
| 284 |
+
detected_map = np.zeros_like(img, dtype=np.uint8)
|
| 285 |
+
detected_map[np.min(img, axis=2) < 127] = 255
|
| 286 |
+
|
| 287 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 288 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 289 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 290 |
+
|
| 291 |
+
if seed == -1:
|
| 292 |
+
seed = random.randint(0, 65535)
|
| 293 |
+
seed_everything(seed)
|
| 294 |
+
|
| 295 |
+
if config.save_memory:
|
| 296 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 297 |
+
|
| 298 |
+
cond = {
|
| 299 |
+
'c_concat': [control],
|
| 300 |
+
'c_crossattn': [
|
| 301 |
+
self.model.get_learned_conditioning(
|
| 302 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 303 |
+
]
|
| 304 |
+
}
|
| 305 |
+
un_cond = {
|
| 306 |
+
'c_concat': [control],
|
| 307 |
+
'c_crossattn':
|
| 308 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 309 |
+
}
|
| 310 |
+
shape = (4, H // 8, W // 8)
|
| 311 |
+
|
| 312 |
+
if config.save_memory:
|
| 313 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 314 |
+
|
| 315 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 316 |
+
ddim_steps,
|
| 317 |
+
num_samples,
|
| 318 |
+
shape,
|
| 319 |
+
cond,
|
| 320 |
+
verbose=False,
|
| 321 |
+
eta=eta,
|
| 322 |
+
unconditional_guidance_scale=scale,
|
| 323 |
+
unconditional_conditioning=un_cond)
|
| 324 |
+
|
| 325 |
+
if config.save_memory:
|
| 326 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 327 |
+
|
| 328 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 329 |
+
x_samples = (
|
| 330 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 331 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 332 |
+
|
| 333 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 334 |
+
return [255 - detected_map] + results
|
| 335 |
|
| 336 |
@torch.inference_mode()
|
| 337 |
+
def process_scribble_interactive(self, input_image, prompt, a_prompt,
|
| 338 |
+
n_prompt, num_samples, image_resolution,
|
| 339 |
+
ddim_steps, scale, seed, eta):
|
| 340 |
+
self.load_weight('scribble')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
+
img = resize_image(HWC3(input_image['mask'][:, :, 0]),
|
| 343 |
+
image_resolution)
|
| 344 |
+
H, W, C = img.shape
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
+
detected_map = np.zeros_like(img, dtype=np.uint8)
|
| 347 |
+
detected_map[np.min(img, axis=2) > 127] = 255
|
| 348 |
|
| 349 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 350 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 351 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 352 |
+
|
| 353 |
+
if seed == -1:
|
| 354 |
+
seed = random.randint(0, 65535)
|
| 355 |
+
seed_everything(seed)
|
| 356 |
+
|
| 357 |
+
if config.save_memory:
|
| 358 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 359 |
+
|
| 360 |
+
cond = {
|
| 361 |
+
'c_concat': [control],
|
| 362 |
+
'c_crossattn': [
|
| 363 |
+
self.model.get_learned_conditioning(
|
| 364 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 365 |
+
]
|
| 366 |
+
}
|
| 367 |
+
un_cond = {
|
| 368 |
+
'c_concat': [control],
|
| 369 |
+
'c_crossattn':
|
| 370 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 371 |
+
}
|
| 372 |
+
shape = (4, H // 8, W // 8)
|
| 373 |
+
|
| 374 |
+
if config.save_memory:
|
| 375 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 376 |
+
|
| 377 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 378 |
+
ddim_steps,
|
| 379 |
+
num_samples,
|
| 380 |
+
shape,
|
| 381 |
+
cond,
|
| 382 |
+
verbose=False,
|
| 383 |
+
eta=eta,
|
| 384 |
+
unconditional_guidance_scale=scale,
|
| 385 |
+
unconditional_conditioning=un_cond)
|
| 386 |
+
|
| 387 |
+
if config.save_memory:
|
| 388 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 389 |
+
|
| 390 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 391 |
+
x_samples = (
|
| 392 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 393 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 394 |
+
|
| 395 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 396 |
+
return [255 - detected_map] + results
|
| 397 |
|
| 398 |
@torch.inference_mode()
|
| 399 |
+
def process_fake_scribble(self, input_image, prompt, a_prompt, n_prompt,
|
| 400 |
+
num_samples, image_resolution, detect_resolution,
|
| 401 |
+
ddim_steps, scale, seed, eta):
|
| 402 |
+
self.load_weight('scribble')
|
| 403 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
input_image = HWC3(input_image)
|
| 405 |
+
detected_map = apply_hed(resize_image(input_image, detect_resolution))
|
| 406 |
+
detected_map = HWC3(detected_map)
|
| 407 |
+
img = resize_image(input_image, image_resolution)
|
| 408 |
+
H, W, C = img.shape
|
| 409 |
+
|
| 410 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 411 |
+
interpolation=cv2.INTER_LINEAR)
|
| 412 |
+
detected_map = nms(detected_map, 127, 3.0)
|
| 413 |
+
detected_map = cv2.GaussianBlur(detected_map, (0, 0), 3.0)
|
| 414 |
+
detected_map[detected_map > 4] = 255
|
| 415 |
+
detected_map[detected_map < 255] = 0
|
| 416 |
+
|
| 417 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 418 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 419 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 420 |
+
|
| 421 |
+
if seed == -1:
|
| 422 |
+
seed = random.randint(0, 65535)
|
| 423 |
+
seed_everything(seed)
|
| 424 |
+
|
| 425 |
+
if config.save_memory:
|
| 426 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 427 |
+
|
| 428 |
+
cond = {
|
| 429 |
+
'c_concat': [control],
|
| 430 |
+
'c_crossattn': [
|
| 431 |
+
self.model.get_learned_conditioning(
|
| 432 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 433 |
+
]
|
| 434 |
+
}
|
| 435 |
+
un_cond = {
|
| 436 |
+
'c_concat': [control],
|
| 437 |
+
'c_crossattn':
|
| 438 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 439 |
+
}
|
| 440 |
+
shape = (4, H // 8, W // 8)
|
| 441 |
+
|
| 442 |
+
if config.save_memory:
|
| 443 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 444 |
+
|
| 445 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 446 |
+
ddim_steps,
|
| 447 |
+
num_samples,
|
| 448 |
+
shape,
|
| 449 |
+
cond,
|
| 450 |
+
verbose=False,
|
| 451 |
+
eta=eta,
|
| 452 |
+
unconditional_guidance_scale=scale,
|
| 453 |
+
unconditional_conditioning=un_cond)
|
| 454 |
+
|
| 455 |
+
if config.save_memory:
|
| 456 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 457 |
+
|
| 458 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 459 |
+
x_samples = (
|
| 460 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 461 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 462 |
+
|
| 463 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 464 |
+
return [255 - detected_map] + results
|
| 465 |
|
| 466 |
@torch.inference_mode()
|
| 467 |
+
def process_pose(self, input_image, prompt, a_prompt, n_prompt,
|
| 468 |
+
num_samples, image_resolution, detect_resolution,
|
| 469 |
+
ddim_steps, scale, seed, eta):
|
| 470 |
+
self.load_weight('pose')
|
| 471 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
input_image = HWC3(input_image)
|
| 473 |
+
detected_map, _ = apply_openpose(
|
| 474 |
+
resize_image(input_image, detect_resolution))
|
| 475 |
+
detected_map = HWC3(detected_map)
|
| 476 |
+
img = resize_image(input_image, image_resolution)
|
| 477 |
+
H, W, C = img.shape
|
| 478 |
+
|
| 479 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 480 |
+
interpolation=cv2.INTER_NEAREST)
|
| 481 |
+
|
| 482 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 483 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 484 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 485 |
+
|
| 486 |
+
if seed == -1:
|
| 487 |
+
seed = random.randint(0, 65535)
|
| 488 |
+
seed_everything(seed)
|
| 489 |
+
|
| 490 |
+
if config.save_memory:
|
| 491 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 492 |
+
|
| 493 |
+
cond = {
|
| 494 |
+
'c_concat': [control],
|
| 495 |
+
'c_crossattn': [
|
| 496 |
+
self.model.get_learned_conditioning(
|
| 497 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 498 |
+
]
|
| 499 |
+
}
|
| 500 |
+
un_cond = {
|
| 501 |
+
'c_concat': [control],
|
| 502 |
+
'c_crossattn':
|
| 503 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 504 |
+
}
|
| 505 |
+
shape = (4, H // 8, W // 8)
|
| 506 |
+
|
| 507 |
+
if config.save_memory:
|
| 508 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 509 |
+
|
| 510 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 511 |
+
ddim_steps,
|
| 512 |
+
num_samples,
|
| 513 |
+
shape,
|
| 514 |
+
cond,
|
| 515 |
+
verbose=False,
|
| 516 |
+
eta=eta,
|
| 517 |
+
unconditional_guidance_scale=scale,
|
| 518 |
+
unconditional_conditioning=un_cond)
|
| 519 |
+
|
| 520 |
+
if config.save_memory:
|
| 521 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 522 |
+
|
| 523 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 524 |
+
x_samples = (
|
| 525 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 526 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 527 |
+
|
| 528 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 529 |
+
return [detected_map] + results
|
| 530 |
|
| 531 |
@torch.inference_mode()
|
| 532 |
+
def process_seg(self, input_image, prompt, a_prompt, n_prompt, num_samples,
|
| 533 |
+
image_resolution, detect_resolution, ddim_steps, scale,
|
| 534 |
+
seed, eta):
|
| 535 |
+
self.load_weight('seg')
|
| 536 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
input_image = HWC3(input_image)
|
| 538 |
+
detected_map = apply_uniformer(
|
| 539 |
+
resize_image(input_image, detect_resolution))
|
| 540 |
+
img = resize_image(input_image, image_resolution)
|
| 541 |
+
H, W, C = img.shape
|
| 542 |
+
|
| 543 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 544 |
+
interpolation=cv2.INTER_NEAREST)
|
| 545 |
+
|
| 546 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 547 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 548 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 549 |
+
|
| 550 |
+
if seed == -1:
|
| 551 |
+
seed = random.randint(0, 65535)
|
| 552 |
+
seed_everything(seed)
|
| 553 |
+
|
| 554 |
+
if config.save_memory:
|
| 555 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 556 |
+
|
| 557 |
+
cond = {
|
| 558 |
+
'c_concat': [control],
|
| 559 |
+
'c_crossattn': [
|
| 560 |
+
self.model.get_learned_conditioning(
|
| 561 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 562 |
+
]
|
| 563 |
+
}
|
| 564 |
+
un_cond = {
|
| 565 |
+
'c_concat': [control],
|
| 566 |
+
'c_crossattn':
|
| 567 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 568 |
+
}
|
| 569 |
+
shape = (4, H // 8, W // 8)
|
| 570 |
+
|
| 571 |
+
if config.save_memory:
|
| 572 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 573 |
+
|
| 574 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 575 |
+
ddim_steps,
|
| 576 |
+
num_samples,
|
| 577 |
+
shape,
|
| 578 |
+
cond,
|
| 579 |
+
verbose=False,
|
| 580 |
+
eta=eta,
|
| 581 |
+
unconditional_guidance_scale=scale,
|
| 582 |
+
unconditional_conditioning=un_cond)
|
| 583 |
+
|
| 584 |
+
if config.save_memory:
|
| 585 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 586 |
+
|
| 587 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 588 |
+
x_samples = (
|
| 589 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 590 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 591 |
+
|
| 592 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 593 |
+
return [detected_map] + results
|
| 594 |
|
| 595 |
@torch.inference_mode()
|
| 596 |
+
def process_depth(self, input_image, prompt, a_prompt, n_prompt,
|
| 597 |
+
num_samples, image_resolution, detect_resolution,
|
| 598 |
+
ddim_steps, scale, seed, eta):
|
| 599 |
+
self.load_weight('depth')
|
| 600 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 601 |
input_image = HWC3(input_image)
|
| 602 |
+
detected_map, _ = apply_midas(
|
| 603 |
+
resize_image(input_image, detect_resolution))
|
| 604 |
+
detected_map = HWC3(detected_map)
|
| 605 |
+
img = resize_image(input_image, image_resolution)
|
| 606 |
+
H, W, C = img.shape
|
| 607 |
+
|
| 608 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 609 |
+
interpolation=cv2.INTER_LINEAR)
|
| 610 |
+
|
| 611 |
+
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 612 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 613 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 614 |
+
|
| 615 |
+
if seed == -1:
|
| 616 |
+
seed = random.randint(0, 65535)
|
| 617 |
+
seed_everything(seed)
|
| 618 |
+
|
| 619 |
+
if config.save_memory:
|
| 620 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 621 |
+
|
| 622 |
+
cond = {
|
| 623 |
+
'c_concat': [control],
|
| 624 |
+
'c_crossattn': [
|
| 625 |
+
self.model.get_learned_conditioning(
|
| 626 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 627 |
+
]
|
| 628 |
+
}
|
| 629 |
+
un_cond = {
|
| 630 |
+
'c_concat': [control],
|
| 631 |
+
'c_crossattn':
|
| 632 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 633 |
+
}
|
| 634 |
+
shape = (4, H // 8, W // 8)
|
| 635 |
+
|
| 636 |
+
if config.save_memory:
|
| 637 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 638 |
+
|
| 639 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 640 |
+
ddim_steps,
|
| 641 |
+
num_samples,
|
| 642 |
+
shape,
|
| 643 |
+
cond,
|
| 644 |
+
verbose=False,
|
| 645 |
+
eta=eta,
|
| 646 |
+
unconditional_guidance_scale=scale,
|
| 647 |
+
unconditional_conditioning=un_cond)
|
| 648 |
+
|
| 649 |
+
if config.save_memory:
|
| 650 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 651 |
+
|
| 652 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 653 |
+
x_samples = (
|
| 654 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 655 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 656 |
+
|
| 657 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 658 |
+
return [detected_map] + results
|
| 659 |
|
| 660 |
@torch.inference_mode()
|
| 661 |
+
def process_normal(self, input_image, prompt, a_prompt, n_prompt,
|
| 662 |
+
num_samples, image_resolution, detect_resolution,
|
| 663 |
+
ddim_steps, scale, seed, eta, bg_threshold):
|
| 664 |
+
self.load_weight('normal')
|
| 665 |
+
|
| 666 |
+
input_image = HWC3(input_image)
|
| 667 |
+
_, detected_map = apply_midas(resize_image(input_image,
|
| 668 |
+
detect_resolution),
|
| 669 |
+
bg_th=bg_threshold)
|
| 670 |
+
detected_map = HWC3(detected_map)
|
| 671 |
+
img = resize_image(input_image, image_resolution)
|
| 672 |
+
H, W, C = img.shape
|
| 673 |
+
|
| 674 |
+
detected_map = cv2.resize(detected_map, (W, H),
|
| 675 |
+
interpolation=cv2.INTER_LINEAR)
|
| 676 |
+
|
| 677 |
+
control = torch.from_numpy(
|
| 678 |
+
detected_map[:, :, ::-1].copy()).float().cuda() / 255.0
|
| 679 |
+
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 680 |
+
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 681 |
+
|
| 682 |
+
if seed == -1:
|
| 683 |
+
seed = random.randint(0, 65535)
|
| 684 |
+
seed_everything(seed)
|
| 685 |
+
|
| 686 |
+
if config.save_memory:
|
| 687 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 688 |
+
|
| 689 |
+
cond = {
|
| 690 |
+
'c_concat': [control],
|
| 691 |
+
'c_crossattn': [
|
| 692 |
+
self.model.get_learned_conditioning(
|
| 693 |
+
[prompt + ', ' + a_prompt] * num_samples)
|
| 694 |
+
]
|
| 695 |
+
}
|
| 696 |
+
un_cond = {
|
| 697 |
+
'c_concat': [control],
|
| 698 |
+
'c_crossattn':
|
| 699 |
+
[self.model.get_learned_conditioning([n_prompt] * num_samples)]
|
| 700 |
+
}
|
| 701 |
+
shape = (4, H // 8, W // 8)
|
| 702 |
+
|
| 703 |
+
if config.save_memory:
|
| 704 |
+
self.model.low_vram_shift(is_diffusing=True)
|
| 705 |
+
|
| 706 |
+
samples, intermediates = self.ddim_sampler.sample(
|
| 707 |
+
ddim_steps,
|
| 708 |
+
num_samples,
|
| 709 |
+
shape,
|
| 710 |
+
cond,
|
| 711 |
+
verbose=False,
|
| 712 |
+
eta=eta,
|
| 713 |
+
unconditional_guidance_scale=scale,
|
| 714 |
+
unconditional_conditioning=un_cond)
|
| 715 |
+
|
| 716 |
+
if config.save_memory:
|
| 717 |
+
self.model.low_vram_shift(is_diffusing=False)
|
| 718 |
+
|
| 719 |
+
x_samples = self.model.decode_first_stage(samples)
|
| 720 |
+
x_samples = (
|
| 721 |
+
einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 +
|
| 722 |
+
127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 723 |
+
|
| 724 |
+
results = [x_samples[i] for i in range(num_samples)]
|
| 725 |
+
return [detected_map] + results
|
notebooks/notebook.ipynb
DELETED
|
@@ -1,80 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": null,
|
| 6 |
-
"metadata": {
|
| 7 |
-
"id": "8CnkIPtjn8Dc"
|
| 8 |
-
},
|
| 9 |
-
"outputs": [],
|
| 10 |
-
"source": [
|
| 11 |
-
"!git clone --recursive https://huggingface.co/spaces/hysts/ControlNet"
|
| 12 |
-
]
|
| 13 |
-
},
|
| 14 |
-
{
|
| 15 |
-
"cell_type": "code",
|
| 16 |
-
"execution_count": null,
|
| 17 |
-
"metadata": {
|
| 18 |
-
"id": "IZlaYNTWoFPK"
|
| 19 |
-
},
|
| 20 |
-
"outputs": [],
|
| 21 |
-
"source": [
|
| 22 |
-
"%cd ControlNet"
|
| 23 |
-
]
|
| 24 |
-
},
|
| 25 |
-
{
|
| 26 |
-
"cell_type": "code",
|
| 27 |
-
"execution_count": null,
|
| 28 |
-
"metadata": {
|
| 29 |
-
"id": "0zhLFnZUoWdp"
|
| 30 |
-
},
|
| 31 |
-
"outputs": [],
|
| 32 |
-
"source": [
|
| 33 |
-
"!cd ControlNet && git apply ../patch && cd .."
|
| 34 |
-
]
|
| 35 |
-
},
|
| 36 |
-
{
|
| 37 |
-
"cell_type": "code",
|
| 38 |
-
"execution_count": null,
|
| 39 |
-
"metadata": {
|
| 40 |
-
"id": "P_fzYrLvoIcI"
|
| 41 |
-
},
|
| 42 |
-
"outputs": [],
|
| 43 |
-
"source": [
|
| 44 |
-
"!pip install -q -r requirements.txt"
|
| 45 |
-
]
|
| 46 |
-
},
|
| 47 |
-
{
|
| 48 |
-
"cell_type": "code",
|
| 49 |
-
"execution_count": null,
|
| 50 |
-
"metadata": {
|
| 51 |
-
"id": "GOfGng5Woktd"
|
| 52 |
-
},
|
| 53 |
-
"outputs": [],
|
| 54 |
-
"source": [
|
| 55 |
-
"import app"
|
| 56 |
-
]
|
| 57 |
-
},
|
| 58 |
-
{
|
| 59 |
-
"cell_type": "code",
|
| 60 |
-
"execution_count": null,
|
| 61 |
-
"metadata": {
|
| 62 |
-
"id": "7Cued230ol7T"
|
| 63 |
-
},
|
| 64 |
-
"outputs": [],
|
| 65 |
-
"source": []
|
| 66 |
-
}
|
| 67 |
-
],
|
| 68 |
-
"metadata": {
|
| 69 |
-
"accelerator": "GPU",
|
| 70 |
-
"colab": {
|
| 71 |
-
"provenance": []
|
| 72 |
-
},
|
| 73 |
-
"gpuClass": "standard",
|
| 74 |
-
"language_info": {
|
| 75 |
-
"name": "python"
|
| 76 |
-
}
|
| 77 |
-
},
|
| 78 |
-
"nbformat": 4,
|
| 79 |
-
"nbformat_minor": 0
|
| 80 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
patch
CHANGED
|
@@ -113,16 +113,3 @@ index 500e53c..4061dbe 100644
|
|
| 113 |
model = init_segmentor(config_file, checkpoint_file).cuda()
|
| 114 |
|
| 115 |
|
| 116 |
-
diff --git a/annotator/util.py b/annotator/util.py
|
| 117 |
-
index 7cde937..10a6d58 100644
|
| 118 |
-
--- a/annotator/util.py
|
| 119 |
-
+++ b/annotator/util.py
|
| 120 |
-
@@ -25,7 +25,7 @@ def resize_image(input_image, resolution):
|
| 121 |
-
H, W, C = input_image.shape
|
| 122 |
-
H = float(H)
|
| 123 |
-
W = float(W)
|
| 124 |
-
- k = float(resolution) / min(H, W)
|
| 125 |
-
+ k = float(resolution) / max(H, W)
|
| 126 |
-
H *= k
|
| 127 |
-
W *= k
|
| 128 |
-
H = int(np.round(H / 64.0)) * 64
|
|
|
|
| 113 |
model = init_segmentor(config_file, checkpoint_file).cuda()
|
| 114 |
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
addict==2.4.0
|
| 2 |
albumentations==1.3.0
|
| 3 |
einops==0.6.0
|
| 4 |
-
|
| 5 |
-
git+https://github.com/huggingface/diffusers@fa6d52d
|
| 6 |
-
gradio==3.36.1
|
| 7 |
imageio==2.25.0
|
| 8 |
imageio-ffmpeg==0.4.8
|
| 9 |
kornia==0.6.9
|
|
@@ -13,10 +11,8 @@ opencv-contrib-python==4.7.0.68
|
|
| 13 |
opencv-python-headless==4.7.0.68
|
| 14 |
prettytable==3.6.0
|
| 15 |
pytorch-lightning==1.9.0
|
| 16 |
-
safetensors==0.2.8
|
| 17 |
timm==0.6.12
|
| 18 |
torch==1.13.1
|
| 19 |
torchvision==0.14.1
|
| 20 |
transformers==4.26.1
|
| 21 |
-
xformers==0.0.16
|
| 22 |
yapf==0.32.0
|
|
|
|
| 1 |
addict==2.4.0
|
| 2 |
albumentations==1.3.0
|
| 3 |
einops==0.6.0
|
| 4 |
+
gradio==3.18.0
|
|
|
|
|
|
|
| 5 |
imageio==2.25.0
|
| 6 |
imageio-ffmpeg==0.4.8
|
| 7 |
kornia==0.6.9
|
|
|
|
| 11 |
opencv-python-headless==4.7.0.68
|
| 12 |
prettytable==3.6.0
|
| 13 |
pytorch-lightning==1.9.0
|
|
|
|
| 14 |
timm==0.6.12
|
| 15 |
torch==1.13.1
|
| 16 |
torchvision==0.14.1
|
| 17 |
transformers==4.26.1
|
|
|
|
| 18 |
yapf==0.32.0
|
style.css
CHANGED
|
@@ -1,8 +1,3 @@
|
|
| 1 |
h1 {
|
| 2 |
text-align: center;
|
| 3 |
}
|
| 4 |
-
|
| 5 |
-
.note {
|
| 6 |
-
text-align: center;
|
| 7 |
-
font-size: 150%;
|
| 8 |
-
}
|
|
|
|
| 1 |
h1 {
|
| 2 |
text-align: center;
|
| 3 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|