Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,187 +8,65 @@ from models.interface_types import InterfaceType
|
|
| 8 |
from constants import DEVICE
|
| 9 |
from state import get_settings
|
| 10 |
import traceback
|
| 11 |
-
|
| 12 |
-
|
| 13 |
from fastapi import FastAPI,Body
|
| 14 |
-
|
| 15 |
import uvicorn
|
| 16 |
import json
|
| 17 |
import logging
|
| 18 |
from PIL import Image
|
| 19 |
import time
|
| 20 |
-
|
| 21 |
from diffusers.utils import load_image
|
| 22 |
import base64
|
| 23 |
import io
|
| 24 |
from datetime import datetime
|
| 25 |
-
|
| 26 |
from typing import Any
|
| 27 |
from backend.models.lcmdiffusion_setting import DiffusionTask
|
| 28 |
-
|
| 29 |
from frontend.utils import is_reshape_required
|
| 30 |
from concurrent.futures import ThreadPoolExecutor
|
| 31 |
-
|
| 32 |
-
|
| 33 |
context = Context(InterfaceType.WEBUI)
|
| 34 |
previous_width = 0
|
| 35 |
previous_height = 0
|
| 36 |
previous_model_id = ""
|
| 37 |
previous_num_of_images = 0
|
| 38 |
-
|
| 39 |
parser = ArgumentParser(description=f"FAST SD CPU {constants.APP_VERSION}")
|
| 40 |
-
parser.add_argument(
|
| 41 |
-
"-s",
|
| 42 |
-
"--share",
|
| 43 |
-
action="store_true",
|
| 44 |
-
help="Create sharable link(Web UI)",
|
| 45 |
-
required=False,
|
| 46 |
-
)
|
| 47 |
group = parser.add_mutually_exclusive_group(required=False)
|
| 48 |
-
group.add_argument(
|
| 49 |
-
"-
|
| 50 |
-
"--
|
| 51 |
-
action="store_true",
|
| 52 |
-
help="
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
"
|
| 56 |
-
"--
|
| 57 |
-
|
| 58 |
-
help="
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
"
|
| 62 |
-
"--
|
| 63 |
-
action="
|
| 64 |
-
help="
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
"-
|
| 68 |
-
"--
|
| 69 |
-
action="store_true",
|
| 70 |
-
help="Version",
|
| 71 |
-
)
|
| 72 |
-
parser.add_argument(
|
| 73 |
-
"--lcm_model_id",
|
| 74 |
-
type=str,
|
| 75 |
-
help="Model ID or path,Default SimianLuo/LCM_Dreamshaper_v7",
|
| 76 |
-
default="advokat/UNLIMITED_PORN" #"SimianLuo/LCM_Dreamshaper_v7",
|
| 77 |
-
)
|
| 78 |
-
parser.add_argument(
|
| 79 |
-
"--prompt",
|
| 80 |
-
type=str,
|
| 81 |
-
help="Describe the image you want to generate",
|
| 82 |
-
)
|
| 83 |
-
parser.add_argument(
|
| 84 |
-
"--image_height",
|
| 85 |
-
type=int,
|
| 86 |
-
help="Height of the image",
|
| 87 |
-
default=512,
|
| 88 |
-
)
|
| 89 |
-
parser.add_argument(
|
| 90 |
-
"--image_width",
|
| 91 |
-
type=int,
|
| 92 |
-
help="Width of the image",
|
| 93 |
-
default=512,
|
| 94 |
-
)
|
| 95 |
-
parser.add_argument(
|
| 96 |
-
"--inference_steps",
|
| 97 |
-
type=int,
|
| 98 |
-
help="Number of steps,default : 4",
|
| 99 |
-
default=4,
|
| 100 |
-
)
|
| 101 |
-
parser.add_argument(
|
| 102 |
-
"--guidance_scale",
|
| 103 |
-
type=int,
|
| 104 |
-
help="Guidance scale,default : 1.0",
|
| 105 |
-
default=1.0,
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
parser.add_argument(
|
| 109 |
-
"--number_of_images",
|
| 110 |
-
type=int,
|
| 111 |
-
help="Number of images to generate ,default : 1",
|
| 112 |
-
default=1,
|
| 113 |
-
)
|
| 114 |
-
parser.add_argument(
|
| 115 |
-
"--seed",
|
| 116 |
-
type=int,
|
| 117 |
-
help="Seed,default : -1 (disabled) ",
|
| 118 |
-
default=-1,
|
| 119 |
-
)
|
| 120 |
-
parser.add_argument(
|
| 121 |
-
"--use_openvino",
|
| 122 |
-
action="store_true",
|
| 123 |
-
help="Use OpenVINO model",
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
parser.add_argument(
|
| 127 |
-
"--use_offline_model",
|
| 128 |
-
action="store_true",
|
| 129 |
-
help="Use offline model",
|
| 130 |
-
)
|
| 131 |
-
parser.add_argument(
|
| 132 |
-
"--use_safety_checker",
|
| 133 |
-
action="store_false",
|
| 134 |
-
help="Use safety checker",
|
| 135 |
-
)
|
| 136 |
-
parser.add_argument(
|
| 137 |
-
"--use_lcm_lora",
|
| 138 |
-
action="store_true",
|
| 139 |
-
help="Use LCM-LoRA",
|
| 140 |
-
)
|
| 141 |
-
parser.add_argument(
|
| 142 |
-
"--base_model_id",
|
| 143 |
-
type=str,
|
| 144 |
-
help="LCM LoRA base model ID,Default Lykon/dreamshaper-8",
|
| 145 |
-
default="Lykon/dreamshaper-8",
|
| 146 |
-
)
|
| 147 |
-
parser.add_argument(
|
| 148 |
-
"--lcm_lora_id",
|
| 149 |
-
type=str,
|
| 150 |
-
help="LCM LoRA model ID,Default latent-consistency/lcm-lora-sdv1-5",
|
| 151 |
-
default="advokat/Illustrious_x_Pony",#"latent-consistency/lcm-lora-sdv1-5",
|
| 152 |
-
)
|
| 153 |
-
parser.add_argument(
|
| 154 |
-
"-i",
|
| 155 |
-
"--interactive",
|
| 156 |
-
action="store_true",
|
| 157 |
-
help="Interactive CLI mode",
|
| 158 |
-
)
|
| 159 |
-
parser.add_argument(
|
| 160 |
-
"--use_tiny_auto_encoder",
|
| 161 |
-
action="store_true",
|
| 162 |
-
help="Use tiny auto encoder for SD (TAESD)",
|
| 163 |
-
)
|
| 164 |
args = parser.parse_args()
|
| 165 |
-
|
| 166 |
if args.version:
|
| 167 |
print(APP_VERSION)
|
| 168 |
exit()
|
| 169 |
-
|
| 170 |
parser.print_help()
|
| 171 |
show_system_info()
|
| 172 |
print(f"Using device : {constants.DEVICE}")
|
| 173 |
app_settings = get_settings()
|
| 174 |
-
|
| 175 |
print(f"Found {len(app_settings.lcm_models)} LCM models in config/lcm-models.txt")
|
| 176 |
-
print(
|
| 177 |
-
f"Found {len(app_settings.
|
| 178 |
-
)
|
| 179 |
-
print(
|
| 180 |
-
f"Found {len(app_settings.lcm_lora_models)} LCM-LoRA models in config/lcm-lora-models.txt"
|
| 181 |
-
)
|
| 182 |
-
print(
|
| 183 |
-
f"Found {len(app_settings.openvino_lcm_models)} OpenVINO LCM models in config/openvino-lcm-models.txt"
|
| 184 |
-
)
|
| 185 |
app_settings.settings.lcm_diffusion_setting.use_openvino = True
|
| 186 |
from frontend.webui.ui import start_webui
|
| 187 |
-
|
| 188 |
print("Starting web UI mode")
|
| 189 |
-
start_webui(
|
| 190 |
-
args.share,
|
| 191 |
-
)
|
| 192 |
|
| 193 |
# app = FastAPI(name="mutilParam")
|
| 194 |
# print("我执行了")
|
|
|
|
| 8 |
from constants import DEVICE
|
| 9 |
from state import get_settings
|
| 10 |
import traceback
|
|
|
|
|
|
|
| 11 |
from fastapi import FastAPI,Body
|
|
|
|
| 12 |
import uvicorn
|
| 13 |
import json
|
| 14 |
import logging
|
| 15 |
from PIL import Image
|
| 16 |
import time
|
|
|
|
| 17 |
from diffusers.utils import load_image
|
| 18 |
import base64
|
| 19 |
import io
|
| 20 |
from datetime import datetime
|
|
|
|
| 21 |
from typing import Any
|
| 22 |
from backend.models.lcmdiffusion_setting import DiffusionTask
|
|
|
|
| 23 |
from frontend.utils import is_reshape_required
|
| 24 |
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
|
|
| 25 |
context = Context(InterfaceType.WEBUI)
|
| 26 |
previous_width = 0
|
| 27 |
previous_height = 0
|
| 28 |
previous_model_id = ""
|
| 29 |
previous_num_of_images = 0
|
|
|
|
| 30 |
parser = ArgumentParser(description=f"FAST SD CPU {constants.APP_VERSION}")
|
| 31 |
+
parser.add_argument( "-s", "--share", action="store_true", help="Create sharable link(Web UI)", required=False,)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
group = parser.add_mutually_exclusive_group(required=False)
|
| 33 |
+
group.add_argument( "-g", "--gui", action="store_true", help="Start desktop GUI",)
|
| 34 |
+
group.add_argument( "-w", "--webui", action="store_true", help="Start Web UI",)
|
| 35 |
+
group.add_argument( "-r", "--realtime", action="store_true", help="Start realtime inference UI(experimental)",)
|
| 36 |
+
group.add_argument( "-v", "--version", action="store_true", help="Version",)
|
| 37 |
+
parser.add_argument( "--lcm_model_id", type=str, help="Model ID or path,Default SimianLuo/LCM_Dreamshaper_v7", default="advokat/UNLIMITED_PORN" #"SimianLuo/LCM_Dreamshaper_v7",
|
| 38 |
+
)
|
| 39 |
+
parser.add_argument( "--prompt", type=str, help="Describe the image you want to generate",)
|
| 40 |
+
parser.add_argument( "--image_height", type=int, help="Height of the image", default=512,)
|
| 41 |
+
parser.add_argument( "--image_width", type=int, help="Width of the image", default=512,)
|
| 42 |
+
parser.add_argument( "--inference_steps", type=int, help="Number of steps,default : 4", default=4,)
|
| 43 |
+
parser.add_argument( "--guidance_scale", type=int, help="Guidance scale,default : 1.0", default=1.0,)
|
| 44 |
+
parser.add_argument( "--number_of_images", type=int, help="Number of images to generate ,default : 1", default=1,)
|
| 45 |
+
parser.add_argument( "--seed", type=int, help="Seed,default : -1 (disabled) ", default=-1,)
|
| 46 |
+
parser.add_argument( "--use_openvino", action="store_true", help="Use OpenVINO model",)
|
| 47 |
+
parser.add_argument( "--use_offline_model", action="store_true", help="Use offline model",)
|
| 48 |
+
parser.add_argument( "--use_safety_checker", action="store_false", help="Use safety checker",)
|
| 49 |
+
parser.add_argument( "--use_lcm_lora", action="store_true", help="Use LCM-LoRA",)
|
| 50 |
+
parser.add_argument( "--base_model_id", type=str, help="LCM LoRA base model ID,Default Lykon/dreamshaper-8", default="Lykon/dreamshaper-8",)
|
| 51 |
+
parser.add_argument( "--lcm_lora_id", type=str, help="LCM LoRA model ID,Default latent-consistency/lcm-lora-sdv1-5", default="advokat/Illustrious_x_Pony")
|
| 52 |
+
parser.add_argument( "-i", "--interactive", action="store_true", help="Interactive CLI mode",)
|
| 53 |
+
parser.add_argument( "--use_tiny_auto_encoder", action="store_true", help="Use tiny auto encoder for SD (TAESD)",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
args = parser.parse_args()
|
|
|
|
| 55 |
if args.version:
|
| 56 |
print(APP_VERSION)
|
| 57 |
exit()
|
|
|
|
| 58 |
parser.print_help()
|
| 59 |
show_system_info()
|
| 60 |
print(f"Using device : {constants.DEVICE}")
|
| 61 |
app_settings = get_settings()
|
|
|
|
| 62 |
print(f"Found {len(app_settings.lcm_models)} LCM models in config/lcm-models.txt")
|
| 63 |
+
print( f"Found {len(app_settings.stable_diffsuion_models)} stable diffusion models in config/stable-diffusion-models.txt")
|
| 64 |
+
print( f"Found {len(app_settings.lcm_lora_models)} LCM-LoRA models in config/lcm-lora-models.txt")
|
| 65 |
+
print( f"Found {len(app_settings.openvino_lcm_models)} OpenVINO LCM models in config/openvino-lcm-models.txt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
app_settings.settings.lcm_diffusion_setting.use_openvino = True
|
| 67 |
from frontend.webui.ui import start_webui
|
|
|
|
| 68 |
print("Starting web UI mode")
|
| 69 |
+
start_webui( args.share,)
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# app = FastAPI(name="mutilParam")
|
| 72 |
# print("我执行了")
|