init
Browse files- app.py +92 -0
- requirements.txt +229 -0
app.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import DiffusionPipeline, ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
|
| 2 |
+
from diffusers.utils import load_image
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import os, time
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
| 7 |
+
import cv2
|
| 8 |
+
import gradio as gr
|
| 9 |
+
from torchvision import transforms
|
| 10 |
+
|
| 11 |
+
lora_path = "/home/user/lora"
|
| 12 |
+
output_dir = "/home/user/output"
|
| 13 |
+
|
| 14 |
+
model = DiffusionPipeline.from_pretrained(
|
| 15 |
+
"SimianLuo/LCM_Dreamshaper_v7",
|
| 16 |
+
safety_checker = None,
|
| 17 |
+
)
|
| 18 |
+
model.to(torch_device="cpu", torch_dtype=torch.float32).to("mps")
|
| 19 |
+
|
| 20 |
+
low_threshold = 100
|
| 21 |
+
high_threshold = 200
|
| 22 |
+
|
| 23 |
+
safetensors_files_without_suffix = []
|
| 24 |
+
|
| 25 |
+
def process(prompt, negative_prompt, width, height, steps, scale, number, loras):
|
| 26 |
+
if len(loras) > 0:
|
| 27 |
+
for item in loras:
|
| 28 |
+
model.load_lora_weights(lora_path, weight_name=f"{item}.safetensors")
|
| 29 |
+
|
| 30 |
+
for _ in range(number):
|
| 31 |
+
_seed = int.from_bytes(os.urandom(2), "big")
|
| 32 |
+
generator = torch.manual_seed(_seed)
|
| 33 |
+
image = model(
|
| 34 |
+
prompt=prompt,
|
| 35 |
+
negative_prompt=negative_prompt,
|
| 36 |
+
width=width,
|
| 37 |
+
height=height,
|
| 38 |
+
num_inference_steps=steps,
|
| 39 |
+
generator=generator,
|
| 40 |
+
guidance_scale=scale
|
| 41 |
+
).images[0]
|
| 42 |
+
|
| 43 |
+
timestamp = time.strftime("%Y%m%d-%H%M%S")
|
| 44 |
+
output_path = os.path.join(output_dir, f"{timestamp}.png")
|
| 45 |
+
image.save(output_path)
|
| 46 |
+
|
| 47 |
+
# images.append(image)
|
| 48 |
+
# return images
|
| 49 |
+
|
| 50 |
+
block = gr.Blocks().queue()
|
| 51 |
+
|
| 52 |
+
def update_loras_list():
|
| 53 |
+
filenames = os.listdir(lora_path)
|
| 54 |
+
safetensors_files = [filename for filename in filenames if filename.endswith(".safetensors")]
|
| 55 |
+
safetensors_files_without_suffix = [filename[:-len(".safetensors")] for filename in safetensors_files]
|
| 56 |
+
return gr.Dropdown.update(choices=safetensors_files_without_suffix)
|
| 57 |
+
|
| 58 |
+
with gr.Blocks(css="style.css") as block:
|
| 59 |
+
with gr.Row():
|
| 60 |
+
with gr.Column():
|
| 61 |
+
prompt = gr.Textbox(label="正向提示词", lines=3, value="Warhammer 40k, a new robot in Armor, god of empire detailed face octane painting, Devian art, concept art, The gate of the medieval castle")
|
| 62 |
+
negative_prompt = gr.Textbox(label="反向提示词", value="low quality")
|
| 63 |
+
loras = gr.Dropdown(safetensors_files_without_suffix, multiselect=True, label="Loras", info="增加Loras风格")
|
| 64 |
+
with gr.Row():
|
| 65 |
+
load_loras_btn = gr.Button(value="加载")
|
| 66 |
+
clear_btn = gr.ClearButton(components=[loras], value="清空")
|
| 67 |
+
|
| 68 |
+
with gr.Column():
|
| 69 |
+
with gr.Row():
|
| 70 |
+
steps = gr.Slider(label="迭代步数", minimum=1, maximum=50, value=4, step=1)
|
| 71 |
+
scale = gr.Slider(label="引导系数", minimum=1, maximum=50, value=4, step=0.5)
|
| 72 |
+
number = gr.Slider(label="生成数量", minimum=1, maximum=10, value=1, step=1)
|
| 73 |
+
|
| 74 |
+
with gr.Row():
|
| 75 |
+
width = gr.Slider(label="宽度", minimum=384, maximum=1024, value=512, step=128)
|
| 76 |
+
height = gr.Slider(label="高度", minimum=384, maximum=1024, value=512, step=128)
|
| 77 |
+
|
| 78 |
+
with gr.Row():
|
| 79 |
+
# result_gallery = gr.Gallery(label='输出', show_label=True, elem_id="gallery", columns=[2], height='auto')
|
| 80 |
+
run_button = gr.Button(value="运行", elem_id="blue-button",)
|
| 81 |
+
|
| 82 |
+
ips = [prompt, negative_prompt, width, height, steps, scale, number, loras]
|
| 83 |
+
run_button.click(fn=process, inputs=ips)
|
| 84 |
+
load_loras_btn.click(fn=update_loras_list, outputs=loras)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def main():
|
| 88 |
+
block.launch(debug=True, share=False)
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
main()
|
| 92 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
absl-py==2.0.0
|
| 2 |
+
accelerate==0.23.0
|
| 3 |
+
addict==2.4.0
|
| 4 |
+
aenum==3.1.15
|
| 5 |
+
aiofiles==23.2.1
|
| 6 |
+
aiohttp==3.9.1
|
| 7 |
+
aiosignal==1.3.1
|
| 8 |
+
albumentations==1.3.1
|
| 9 |
+
altair==5.2.0
|
| 10 |
+
altgraph==0.17.3
|
| 11 |
+
antlr4-python3-runtime==4.9.3
|
| 12 |
+
anyio==3.7.1
|
| 13 |
+
argostranslate==1.9.1
|
| 14 |
+
attrs==23.1.0
|
| 15 |
+
basicsr==1.4.2
|
| 16 |
+
beautifulsoup4==4.12.2
|
| 17 |
+
blendmodes==2022
|
| 18 |
+
blessed==1.20.0
|
| 19 |
+
blinker==1.6.2
|
| 20 |
+
cachetools==5.3.2
|
| 21 |
+
certifi==2023.11.17
|
| 22 |
+
cffi==1.16.0
|
| 23 |
+
chardet==5.2.0
|
| 24 |
+
charset-normalizer==3.3.2
|
| 25 |
+
clean-fid==0.1.35
|
| 26 |
+
click==8.1.5
|
| 27 |
+
clip @ https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip#sha256=b5842c25da441d6c581b53a5c60e0c2127ebafe0f746f8e15561a006c6c3be6a
|
| 28 |
+
clip-interrogator==0.6.0
|
| 29 |
+
cmake==3.28.1
|
| 30 |
+
coloredlogs==15.0.1
|
| 31 |
+
colorlog==6.8.0
|
| 32 |
+
contourpy==1.2.0
|
| 33 |
+
cssselect2==0.7.0
|
| 34 |
+
cstr @ git+https://github.com/WASasquatch/cstr@0520c29a18a7a869a6e5983861d6f7a4c86f8e9b
|
| 35 |
+
ctranslate2==3.20.0
|
| 36 |
+
cycler==0.12.1
|
| 37 |
+
Cython==3.0.7
|
| 38 |
+
deep-translator==1.11.4
|
| 39 |
+
deprecation==2.1.0
|
| 40 |
+
diffusers==0.23.0
|
| 41 |
+
easydict==1.11
|
| 42 |
+
einops==0.4.1
|
| 43 |
+
enlighten==1.12.2
|
| 44 |
+
facexlib==0.3.0
|
| 45 |
+
fairscale==0.4.13
|
| 46 |
+
fastapi==0.94.0
|
| 47 |
+
ffmpy @ git+https://github.com/WASasquatch/ffmpy.git@f000737698b387ffaeab7cd871b0e9185811230d
|
| 48 |
+
filelock==3.13.1
|
| 49 |
+
filterpy==1.4.5
|
| 50 |
+
Flask==2.3.2
|
| 51 |
+
Flask-JWT-Extended==4.5.2
|
| 52 |
+
Flask-SQLAlchemy==3.0.5
|
| 53 |
+
Flask-WTF==1.1.1
|
| 54 |
+
flatbuffers==23.5.26
|
| 55 |
+
fonttools==4.47.0
|
| 56 |
+
frozenlist==1.4.1
|
| 57 |
+
fsspec==2023.12.2
|
| 58 |
+
ftfy==6.1.3
|
| 59 |
+
future==0.18.3
|
| 60 |
+
fvcore==0.1.5.post20221221
|
| 61 |
+
gdown==4.7.1
|
| 62 |
+
gevent==23.7.0
|
| 63 |
+
gfpgan==1.3.8
|
| 64 |
+
gitdb==4.0.11
|
| 65 |
+
GitPython==3.1.32
|
| 66 |
+
google-auth==2.25.2
|
| 67 |
+
google-auth-oauthlib==1.2.0
|
| 68 |
+
googletrans-py==4.0.0
|
| 69 |
+
gradio==3.41.2
|
| 70 |
+
gradio_client==0.5.0
|
| 71 |
+
greenlet==2.0.2
|
| 72 |
+
grpcio==1.60.0
|
| 73 |
+
h11==0.12.0
|
| 74 |
+
h2==4.1.0
|
| 75 |
+
hpack==4.0.0
|
| 76 |
+
httpcore==0.15.0
|
| 77 |
+
httpx==0.24.1
|
| 78 |
+
huggingface-hub==0.17.3
|
| 79 |
+
humanfriendly==10.0
|
| 80 |
+
hyperframe==6.0.1
|
| 81 |
+
idna==3.6
|
| 82 |
+
imageio==2.33.1
|
| 83 |
+
imageio-ffmpeg==0.4.9
|
| 84 |
+
img2texture @ git+https://github.com/WASasquatch/img2texture.git@a546609a915caf1dcb84a15bf44b5b639ad924e6
|
| 85 |
+
importlib-metadata==7.0.1
|
| 86 |
+
importlib-resources==6.1.1
|
| 87 |
+
inflection==0.5.1
|
| 88 |
+
insightface==0.7.3
|
| 89 |
+
iopath==0.1.9
|
| 90 |
+
itsdangerous==2.1.2
|
| 91 |
+
Jinja2==3.1.2
|
| 92 |
+
joblib==1.3.2
|
| 93 |
+
jsonmerge==1.8.0
|
| 94 |
+
jsonschema==4.20.0
|
| 95 |
+
jsonschema-specifications==2023.12.1
|
| 96 |
+
kiwisolver==1.4.5
|
| 97 |
+
kornia==0.6.7
|
| 98 |
+
lark==1.1.2
|
| 99 |
+
lazy_loader==0.3
|
| 100 |
+
lightning-utilities==0.10.0
|
| 101 |
+
llvmlite==0.41.1
|
| 102 |
+
lmdb==1.4.1
|
| 103 |
+
lpips==0.1.4
|
| 104 |
+
lxml==4.9.4
|
| 105 |
+
macholib==1.16.2
|
| 106 |
+
mapbox-earcut==1.0.1
|
| 107 |
+
Markdown==3.5.1
|
| 108 |
+
MarkupSafe==2.1.3
|
| 109 |
+
matplotlib==3.8.2
|
| 110 |
+
mediapipe==0.10.9
|
| 111 |
+
mpmath==1.3.0
|
| 112 |
+
multidict==6.0.4
|
| 113 |
+
networkx==3.2.1
|
| 114 |
+
nsz==4.5.0
|
| 115 |
+
numba==0.58.1
|
| 116 |
+
numpy==1.24.4
|
| 117 |
+
oauthlib==3.2.2
|
| 118 |
+
omegaconf==2.2.3
|
| 119 |
+
onnx==1.15.0
|
| 120 |
+
onnxruntime==1.16.3
|
| 121 |
+
open-clip-torch==2.20.0
|
| 122 |
+
opencv-contrib-python==4.8.1.78
|
| 123 |
+
opencv-python==4.8.1.78
|
| 124 |
+
opencv-python-headless==4.7.0.72
|
| 125 |
+
orjson==3.9.10
|
| 126 |
+
packaging==23.2
|
| 127 |
+
pandas==2.1.4
|
| 128 |
+
piexif==1.1.3
|
| 129 |
+
pilgram==1.2.1
|
| 130 |
+
Pillow==10.1.0
|
| 131 |
+
platformdirs==4.1.0
|
| 132 |
+
pooch==1.8.0
|
| 133 |
+
portalocker==2.8.2
|
| 134 |
+
prefixed==0.7.0
|
| 135 |
+
prettytable==3.9.0
|
| 136 |
+
protobuf==3.20.3
|
| 137 |
+
psutil==5.9.5
|
| 138 |
+
pyasn1==0.5.1
|
| 139 |
+
pyasn1-modules==0.3.0
|
| 140 |
+
pycollada==0.7.2
|
| 141 |
+
pycparser==2.21
|
| 142 |
+
pycryptodome==3.19.0
|
| 143 |
+
pydantic==1.10.13
|
| 144 |
+
pydub==0.25.1
|
| 145 |
+
pyinstaller==5.13.0
|
| 146 |
+
pyinstaller-hooks-contrib==2023.5
|
| 147 |
+
PyJWT==2.7.0
|
| 148 |
+
PyMatting==1.1.12
|
| 149 |
+
PyMySQL==1.1.0
|
| 150 |
+
pyparsing==3.1.1
|
| 151 |
+
PySocks==1.7.1
|
| 152 |
+
python-dateutil==2.8.2
|
| 153 |
+
python-multipart==0.0.6
|
| 154 |
+
pytorch-lightning==1.9.4
|
| 155 |
+
pytz==2023.3.post1
|
| 156 |
+
pywatchman==1.4.1
|
| 157 |
+
PyWavelets==1.5.0
|
| 158 |
+
PyYAML==6.0.1
|
| 159 |
+
qudida==0.0.4
|
| 160 |
+
realesrgan==0.3.0
|
| 161 |
+
referencing==0.32.0
|
| 162 |
+
regex==2023.12.25
|
| 163 |
+
rembg==2.0.53
|
| 164 |
+
reportlab==4.0.8
|
| 165 |
+
requests==2.31.0
|
| 166 |
+
requests-oauthlib==1.3.1
|
| 167 |
+
resize-right==0.0.2
|
| 168 |
+
rpds-py==0.16.2
|
| 169 |
+
rsa==4.9
|
| 170 |
+
Rtree==1.1.0
|
| 171 |
+
sacremoses==0.0.53
|
| 172 |
+
safetensors==0.3.1
|
| 173 |
+
scikit-image==0.20.0
|
| 174 |
+
scikit-learn==1.3.2
|
| 175 |
+
scipy==1.11.4
|
| 176 |
+
semantic-version==2.10.0
|
| 177 |
+
sentencepiece==0.1.99
|
| 178 |
+
shapely==2.0.2
|
| 179 |
+
simpleeval==0.9.13
|
| 180 |
+
six==1.16.0
|
| 181 |
+
smmap==5.0.1
|
| 182 |
+
sniffio==1.3.0
|
| 183 |
+
sounddevice==0.4.6
|
| 184 |
+
soupsieve==2.5
|
| 185 |
+
SQLAlchemy==2.0.18
|
| 186 |
+
stanza==1.1.1
|
| 187 |
+
starlette==0.26.1
|
| 188 |
+
svg.path==6.3
|
| 189 |
+
svglib==1.5.1
|
| 190 |
+
sympy==1.12
|
| 191 |
+
tabulate==0.9.0
|
| 192 |
+
tb-nightly==2.16.0a20231229
|
| 193 |
+
tensorboard-data-server==0.7.2
|
| 194 |
+
termcolor==2.4.0
|
| 195 |
+
tf_keras-nightly==2.16.0.dev2023122910
|
| 196 |
+
threadpoolctl==3.2.0
|
| 197 |
+
tifffile==2023.12.9
|
| 198 |
+
timm==0.9.2
|
| 199 |
+
tinycss2==1.2.1
|
| 200 |
+
tokenizers==0.14.1
|
| 201 |
+
tomesd==0.1.3
|
| 202 |
+
tomli==2.0.1
|
| 203 |
+
toolz==0.12.0
|
| 204 |
+
torch==2.0.1
|
| 205 |
+
torchdiffeq==0.2.3
|
| 206 |
+
torchmetrics==1.2.1
|
| 207 |
+
torchsde==0.2.6
|
| 208 |
+
torchvision==0.15.2
|
| 209 |
+
tqdm==4.66.1
|
| 210 |
+
trampoline==0.1.2
|
| 211 |
+
transformers==4.34.1
|
| 212 |
+
trimesh==3.21.7
|
| 213 |
+
typing_extensions==4.7.1
|
| 214 |
+
tzdata==2023.4
|
| 215 |
+
urllib3==2.1.0
|
| 216 |
+
uvicorn==0.25.0
|
| 217 |
+
wcwidth==0.2.12
|
| 218 |
+
webencodings==0.5.1
|
| 219 |
+
websockets==11.0.3
|
| 220 |
+
Werkzeug==2.3.6
|
| 221 |
+
WTForms==3.0.1
|
| 222 |
+
xxhash==3.4.1
|
| 223 |
+
yacs==0.1.8
|
| 224 |
+
yapf==0.40.2
|
| 225 |
+
yarl==1.9.4
|
| 226 |
+
zipp==3.17.0
|
| 227 |
+
zope.event==5.0
|
| 228 |
+
zope.interface==6.0
|
| 229 |
+
zstandard==0.22.0
|