Spaces:
Running on Zero
Running on Zero
Update index.html
Browse files- index.html +191 -1284
index.html
CHANGED
|
@@ -1,1307 +1,214 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
import requests
|
| 18 |
-
from huggingface_hub import hf_hub_download, list_repo_files
|
| 19 |
-
from tqdm.auto import tqdm
|
| 20 |
-
import tqdm as tqdm_lib
|
| 21 |
-
import huggingface_hub
|
| 22 |
-
|
| 23 |
-
import os
|
| 24 |
-
|
| 25 |
-
from model_config import MODEL_CONFIG
|
| 26 |
-
|
| 27 |
-
# ==========================================================================
|
| 28 |
-
# ๐ ๏ธ Environment Patches & Global Paths
|
| 29 |
-
# ==========================================================================
|
| 30 |
-
try:
|
| 31 |
-
import spaces
|
| 32 |
-
except ImportError:
|
| 33 |
-
class _SpacesFallback:
|
| 34 |
-
@staticmethod
|
| 35 |
-
def GPU(**_kwargs):
|
| 36 |
-
def decorate(function):
|
| 37 |
-
return function
|
| 38 |
-
return decorate
|
| 39 |
-
spaces = _SpacesFallback()
|
| 40 |
-
|
| 41 |
-
import torch
|
| 42 |
-
if hasattr(torch.cuda, 'get_device_properties'):
|
| 43 |
-
_orig_get_device_properties = torch.cuda.get_device_properties
|
| 44 |
-
def _patched_get_device_properties(device):
|
| 45 |
-
props = _orig_get_device_properties(device)
|
| 46 |
-
if not hasattr(props, 'is_integrated'):
|
| 47 |
-
props.is_integrated = False
|
| 48 |
-
return props
|
| 49 |
-
torch.cuda.get_device_properties = _patched_get_device_properties
|
| 50 |
-
|
| 51 |
-
ROOT = pathlib.Path(__file__).resolve().parent
|
| 52 |
-
COMFY = ROOT / "ComfyUI"
|
| 53 |
-
MODELS = COMFY / "models"
|
| 54 |
-
INPUT = COMFY / "input"
|
| 55 |
-
OUTPUT = COMFY / "output"
|
| 56 |
-
|
| 57 |
-
_comfy_ready = False
|
| 58 |
-
_nodes_ready = False
|
| 59 |
-
tasks_status = {}
|
| 60 |
-
_last_used_architecture = None # ๆฟไปฃ _last_used_engine (ไปฃ่กจๅบๅฑๆถๆ๏ผๅฆ moss/pony)
|
| 61 |
-
_last_used_unet = None # ไฟ็ (ไปฃ่กจๅ
ทไฝ็ UNet ๆ้ๆไปถๅ)
|
| 62 |
-
# ==========================================================================
|
| 63 |
-
# โ๏ธ Comfy Config
|
| 64 |
-
# ==========================================================================
|
| 65 |
-
SAMPLERS = ["euler", "euler_ancestral", "euler_a", "dpmpp_2m", "dpmpp_2m_sde", "dpmpp_sde", "heun", "lms","lcm"]
|
| 66 |
-
SCHEDULERS = ["simple", "beta", "normal", "karras", "exponential", "sgm_uniform"]
|
| 67 |
-
|
| 68 |
-
UNET_CHOICES = {}
|
| 69 |
-
BASE_LORAS_CHOICES = {}
|
| 70 |
-
CHAR_LORA_CHOICES = {}
|
| 71 |
-
|
| 72 |
-
# ==========================================================================
|
| 73 |
-
# ๐ Load Config & LoRAs List (่ชๅจๅน้
WebP)
|
| 74 |
-
# ==========================================================================
|
| 75 |
-
def load_config_from_json():
|
| 76 |
-
global UNET_CHOICES, BASE_LORAS_CHOICES
|
| 77 |
-
try:
|
| 78 |
-
print(f"ๆญฃๅจ่ทๅ่ฟ็ซฏ JSON ้
็ฝฎ: {MODEL_CONFIG['config_url']}")
|
| 79 |
-
res = requests.get(MODEL_CONFIG['config_url'], timeout=5)
|
| 80 |
-
if res.ok:
|
| 81 |
-
full_data = res.json()
|
| 82 |
-
root_mapping = MODEL_CONFIG['json_keys']['root_mapping']
|
| 83 |
-
|
| 84 |
-
for remote_key, local_engine in root_mapping.items():
|
| 85 |
-
engine_data = full_data.get(remote_key, {})
|
| 86 |
-
|
| 87 |
-
# ๐ ๆ ธๅฟไฟฎๆน 1๏ผๅป models ้ๆพๅฐ็ๅ๏ผๅฆๆๆพไธๅฐๅฐฑ็จ็ญๅๅ
ๅบ
|
| 88 |
-
display_engine = MODEL_CONFIG["models"].get(local_engine, {}).get("name", local_engine)
|
| 89 |
-
|
| 90 |
-
for item in engine_data.get(MODEL_CONFIG['json_keys']['unets'], []):
|
| 91 |
-
# ๐ ไธๆๆกๆพ็คบ็ๅ๏ผไฝ dictionary ็ value ้ไพ็ถๅญ็ญๅ
|
| 92 |
-
display_name = f"{display_engine} | {item['name']}"
|
| 93 |
-
UNET_CHOICES[display_name] = {"repo": item["repo"], "subfolder": item["subfolder"], "filename": item["filename"], "engine": local_engine}
|
| 94 |
-
for item in engine_data.get(MODEL_CONFIG['json_keys']['base_loras'], []):
|
| 95 |
-
display_name = f"{item['name']}"
|
| 96 |
-
BASE_LORAS_CHOICES[display_name] = {"repo": item["repo"], "subfolder": item["subfolder"], "filename": item["filename"], "defaultEnable": str(item.get("defaultEnable", "false")).lower() == "true", "engine": local_engine}
|
| 97 |
-
print("โ
ๆๅๅ ่ฝฝ JSON ้
็ฝฎ")
|
| 98 |
-
return
|
| 99 |
-
except Exception as e:
|
| 100 |
-
print(f"โ ๏ธ JSON ้
็ฝฎๅ ่ฝฝๅคฑ่ดฅ: {e}")
|
| 101 |
-
|
| 102 |
-
for engine, cfg in MODEL_CONFIG.get("models", {}).items():
|
| 103 |
-
# ๐ ๆ ธๅฟไฟฎๆน 2๏ผfallback ้ไน่ฆๅ็ๅ
|
| 104 |
-
display_engine = cfg.get("name", engine)
|
| 105 |
-
|
| 106 |
-
for name, info in cfg.get("fallback_unets", {}).items():
|
| 107 |
-
UNET_CHOICES[f"{display_engine} | {name}"] = {**info, "engine": engine}
|
| 108 |
-
for name, info in cfg.get("fallback_base_loras", {}).items():
|
| 109 |
-
BASE_LORAS_CHOICES[f"{name}"] = {**info, "engine": engine}
|
| 110 |
-
|
| 111 |
-
import time
|
| 112 |
-
LAST_SCAN_TIME = 0 # ๅ
จๅฑๆถ้ดๆณ
|
| 113 |
-
|
| 114 |
-
def load_char_loras_from_repo():
|
| 115 |
-
global CHAR_LORA_CHOICES, LAST_SCAN_TIME
|
| 116 |
-
current_time = time.time()
|
| 117 |
-
|
| 118 |
-
# =========================================================================
|
| 119 |
-
# TODO: ๆง่ฝไผๅไธๅ ่ฝฝไฝ้ช (ๅฆๆๆชๆฅๅบ็ฐๅ ่ฝฝๅก้กฟ๏ผๅฏๅ่ไปฅไธๆนๆก)
|
| 120 |
-
# 1. ๅฝๅๅทฒ้็จ 300 ็ง(5ๅ้) ็ผๅญ๏ผ้ฟๅ
้ข็น่ฏทๆฑ HF ๆฅๅฃใ
|
| 121 |
-
# 2. ็ซๅ
่ฏทๆฑ้ๅธธๆๅฟซ(ๅ ๅๆฏซ๏ฟฝ๏ฟฝ๏ฟฝ)๏ผๅ ๆญค็ฎๅ้็จๅๆญฅ็ญๅพ
๏ผไฟ่ฏ่ฟๅ
ฅ้กต้ขๅณๆๆฐๆฐๆฎใ
|
| 122 |
-
# 3. ๅฆๆๅ็ปญ HF ่็นๆๅจๅฏผ่ด้กต้ข็ฝๅฑ๏ผๅฏ่่ๅฐไธๆน่ฏทๆฑๆนไธบๅๅฐ้้ปๅทๆฐ
|
| 123 |
-
# (ๅฆไฝฟ็จ threading.Thread) ๆไธบ list_repo_files ๅขๅ timeout ๆงๅถใ
|
| 124 |
-
# =========================================================================
|
| 125 |
-
if current_time - LAST_SCAN_TIME < 300:
|
| 126 |
-
print("โก ไฝฟ็จ็ผๅญ๏ผ่ทณ่ฟ้ๆฐๆซๆ LoRA ๅ่กจ")
|
| 127 |
-
return
|
| 128 |
-
|
| 129 |
-
print(f"๐ ่งฆๅๅจๆๅทๆฐ๏ผๆญฃๅจ้ๆฐๆซๆ {MODEL_CONFIG['char_lora_repo']}...")
|
| 130 |
-
exclude_list = [x.lower() for x in MODEL_CONFIG.get("exclude_folders", [])]
|
| 131 |
-
|
| 132 |
-
new_char_choices = {}
|
| 133 |
-
|
| 134 |
-
try:
|
| 135 |
-
files = list_repo_files(repo_id=MODEL_CONFIG['char_lora_repo'], token=os.environ.get("HF_TOKEN"))
|
| 136 |
-
for engine, cfg in MODEL_CONFIG.get("models", {}).items():
|
| 137 |
-
prefix = cfg.get("char_lora_prefix", "")
|
| 138 |
-
new_char_choices[engine] = {}
|
| 139 |
-
for f in files:
|
| 140 |
-
if f.startswith(prefix) and f.endswith(".safetensors") and "loras/" not in f:
|
| 141 |
-
relative_path = f[len(prefix):]
|
| 142 |
-
parts = relative_path.split("/")
|
| 143 |
-
if len(parts) > 1 and parts[0].lower() in exclude_list:
|
| 144 |
-
continue
|
| 145 |
-
|
| 146 |
-
filename = parts[-1]
|
| 147 |
-
webp_path = f.replace(".safetensors", ".webp")
|
| 148 |
-
webp_url = f"https://huggingface.co/{MODEL_CONFIG['char_lora_repo']}/resolve/main/{webp_path}"
|
| 149 |
-
|
| 150 |
-
new_char_choices[engine][filename] = {
|
| 151 |
-
"path": f,
|
| 152 |
-
"webp": webp_url
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
CHAR_LORA_CHOICES.clear()
|
| 156 |
-
CHAR_LORA_CHOICES.update(new_char_choices)
|
| 157 |
-
LAST_SCAN_TIME = current_time
|
| 158 |
-
print(f"โ
ๆๅๅทๆฐ่ง่ฒ LoRA: {[f'{k}: {len(v)}ไธช' for k, v in CHAR_LORA_CHOICES.items()]}")
|
| 159 |
-
except Exception as e:
|
| 160 |
-
print(f"โ ๏ธ ๅจๆๅทๆฐๅคฑ่ดฅ: {e}")
|
| 161 |
-
|
| 162 |
-
load_config_from_json()
|
| 163 |
-
load_char_loras_from_repo()
|
| 164 |
-
|
| 165 |
-
# ==========================================================================
|
| 166 |
-
# โฌ๏ธ Download & Init
|
| 167 |
-
# ==========================================================================
|
| 168 |
-
def _run(command: list[str], cwd: pathlib.Path | None = None, check: bool = True) -> None:
|
| 169 |
-
subprocess.run(command, cwd=str(cwd) if cwd else None, check=check)
|
| 170 |
-
|
| 171 |
-
def _install_filtered_requirements(path: pathlib.Path) -> None:
|
| 172 |
-
if not path.exists(): return
|
| 173 |
-
blocked = {"torch", "torchvision", "torchaudio", "transformers", "huggingface-hub", "accelerate"}
|
| 174 |
-
requirements = []
|
| 175 |
-
for raw in path.read_text(encoding="utf-8", errors="ignore").splitlines():
|
| 176 |
-
item = raw.strip()
|
| 177 |
-
if not item or item.startswith("#"): continue
|
| 178 |
-
package = re.split(r"[<>=!~;\[\s]", item.lower().replace("_", "-"), maxsplit=1)[0]
|
| 179 |
-
if package not in blocked: requirements.append(item)
|
| 180 |
-
if requirements:
|
| 181 |
-
_run([sys.executable, "-m", "pip", "install", "--no-cache-dir", *requirements], check=False)
|
| 182 |
-
|
| 183 |
-
def _ensure_comfy() -> None:
|
| 184 |
-
global _comfy_ready
|
| 185 |
-
if _comfy_ready: return
|
| 186 |
-
if not COMFY.exists():
|
| 187 |
-
_run(["git", "clone", "--depth", "1", "https://github.com/comfyanonymous/ComfyUI.git", str(COMFY)])
|
| 188 |
-
_install_filtered_requirements(COMFY / "requirements.txt")
|
| 189 |
-
for folder in ("diffusion_models", "text_encoders", "vae", "loras"):
|
| 190 |
-
(MODELS / folder).mkdir(parents=True, exist_ok=True)
|
| 191 |
-
INPUT.mkdir(parents=True, exist_ok=True)
|
| 192 |
-
OUTPUT.mkdir(parents=True, exist_ok=True)
|
| 193 |
-
_comfy_ready = True
|
| 194 |
-
|
| 195 |
-
def _init_comfy_nodes() -> None:
|
| 196 |
-
global _nodes_ready
|
| 197 |
-
if _nodes_ready: return
|
| 198 |
-
sys.path.insert(0, str(COMFY))
|
| 199 |
-
os.chdir(COMFY)
|
| 200 |
-
import execution, nodes, server
|
| 201 |
-
from app.assets.manager import default_asset_manager
|
| 202 |
-
loop = asyncio.new_event_loop()
|
| 203 |
-
asyncio.set_event_loop(loop)
|
| 204 |
-
server_instance = server.PromptServer(loop, default_asset_manager())
|
| 205 |
-
execution.PromptQueue(server_instance)
|
| 206 |
-
loop.run_until_complete(nodes.init_extra_nodes())
|
| 207 |
-
_nodes_ready = True
|
| 208 |
-
|
| 209 |
-
def _download_if_needed(repo: str, subfolder: str, filename: str, dest_root: pathlib.Path) -> None:
|
| 210 |
-
dest_path = dest_root / filename
|
| 211 |
-
if dest_path.exists(): return
|
| 212 |
-
print(f"โณ Downloading: {filename} ...")
|
| 213 |
-
dest_root.mkdir(parents=True, exist_ok=True)
|
| 214 |
-
hf_hub_download(repo_id=repo, subfolder=subfolder if subfolder else None, filename=filename, local_dir=str(dest_root))
|
| 215 |
-
src = dest_root / subfolder / filename if subfolder else dest_root / filename
|
| 216 |
-
if src.exists() and src != dest_path:
|
| 217 |
-
shutil.move(str(src), str(dest_path))
|
| 218 |
-
|
| 219 |
-
def _ensure_models() -> None:
|
| 220 |
-
print("ๅผๅงๅ
จ้ไธ่ฝฝๅบ็กๆจกๅ...")
|
| 221 |
-
for engine_cfg in MODEL_CONFIG["models"].values():
|
| 222 |
-
for repo, file_path in engine_cfg.get("companion_downloads", []):
|
| 223 |
-
path = pathlib.Path(file_path)
|
| 224 |
-
if "text_encoders" in str(path): dest_root = MODELS / "text_encoders"
|
| 225 |
-
elif "vae" in str(path): dest_root = MODELS / "vae"
|
| 226 |
-
else: dest_root = MODELS / path.parent
|
| 227 |
-
_download_if_needed(repo, str(path.parent), path.name, dest_root)
|
| 228 |
-
for name, cfg in UNET_CHOICES.items():
|
| 229 |
-
_download_if_needed(cfg["repo"], cfg["subfolder"], cfg["filename"], MODELS / "diffusion_models")
|
| 230 |
-
lora_root = MODELS / "loras"
|
| 231 |
-
for name, cfg in BASE_LORAS_CHOICES.items():
|
| 232 |
-
_download_if_needed(cfg["repo"], cfg["subfolder"], cfg["filename"], lora_root)
|
| 233 |
-
print("โ
ๅบ็กๆจกๅไธ่ฝฝๅฎๆฏ๏ผ")
|
| 234 |
-
|
| 235 |
-
def _prepare_runtime() -> None:
|
| 236 |
-
_ensure_comfy()
|
| 237 |
-
_ensure_models()
|
| 238 |
-
_init_comfy_nodes()
|
| 239 |
-
|
| 240 |
-
try:
|
| 241 |
-
print("โฌ๏ธ Starting up...")
|
| 242 |
-
_prepare_runtime()
|
| 243 |
-
except Exception as e:
|
| 244 |
-
print(f"โ ๏ธ Startup failed: {e}")
|
| 245 |
-
|
| 246 |
-
# ==========================================================================
|
| 247 |
-
# โ๏ธ Comfy Backend & Workflow
|
| 248 |
-
# ==========================================================================
|
| 249 |
-
|
| 250 |
-
def _ref(node: str, output: int = 0) -> list[Any]:
|
| 251 |
-
return [node, output]
|
| 252 |
-
|
| 253 |
-
def _execute_workflow(workflow: dict[str, Any], task_id: str = None) -> list[str]:
|
| 254 |
-
# ๐ ๅ้ๅซๆ๏ผๅๆถๆฆๆช tqdm ๅ tqdm.auto.tqdm
|
| 255 |
-
import tqdm as tqdm_lib
|
| 256 |
-
import tqdm.auto
|
| 257 |
-
import time # ๐ ๅผๅ
ฅ time
|
| 258 |
-
|
| 259 |
-
original_tqdm = tqdm_lib.tqdm
|
| 260 |
-
original_auto_tqdm = tqdm.auto.tqdm
|
| 261 |
-
|
| 262 |
-
tqdm_lib.tqdm = UnifiedProgressTqdm
|
| 263 |
-
tqdm.auto.tqdm = UnifiedProgressTqdm
|
| 264 |
-
|
| 265 |
-
try:
|
| 266 |
-
if str(COMFY) not in sys.path:
|
| 267 |
-
sys.path.insert(0, str(COMFY))
|
| 268 |
-
import execution, server
|
| 269 |
-
from app.assets.manager import default_asset_manager
|
| 270 |
-
loop = asyncio.new_event_loop()
|
| 271 |
-
asyncio.set_event_loop(loop)
|
| 272 |
-
server_instance = server.PromptServer(loop, default_asset_manager())
|
| 273 |
-
# ๐ ไฟๆไบไฝ ๆนๅฅฝ็ lru: 0
|
| 274 |
-
executor = execution.PromptExecutor(server_instance, cache_type=execution.CacheType.RAM_PRESSURE, cache_args={"lru": 0, "ram": 2.0, "ram_inactive": 8.0})
|
| 275 |
-
prompt_id = str(uuid.uuid4())
|
| 276 |
-
save_id = next(k for k, v in workflow.items() if v.get("class_type") == "SaveImage")
|
| 277 |
-
|
| 278 |
-
# ๐ ้็ฅๅ็ซฏๅๅคๆง่กๅทฅไฝๆต๏ผๅนถ่ฎฐๅฝๆจกๅๅ ่ฝฝ่ตท็น
|
| 279 |
-
if task_id and task_id in tasks_status:
|
| 280 |
-
tasks_status[task_id]["message"] = "๐ Executing Workflow..."
|
| 281 |
-
|
| 282 |
-
import json
|
| 283 |
-
import os
|
| 284 |
-
import time
|
| 285 |
-
try:
|
| 286 |
-
metric_file = f"/tmp/metrics_{task_id}.json"
|
| 287 |
-
saved_data = {}
|
| 288 |
-
if os.path.exists(metric_file):
|
| 289 |
-
with open(metric_file, "r") as f:
|
| 290 |
-
saved_data = json.load(f)
|
| 291 |
-
|
| 292 |
-
# ไธๆฌกๆงๅๅ
ฅ๏ผ็ๅฎ้ถๆฎต + ๆจกๅๅ ่ฝฝ่ตท็นๆถ้ด
|
| 293 |
-
saved_data["phase"] = "๐ Executing Workflow..."
|
| 294 |
-
saved_data["load_start"] = time.time()
|
| 295 |
-
|
| 296 |
-
with open(metric_file, "w") as f:
|
| 297 |
-
json.dump(saved_data, f)
|
| 298 |
-
except Exception:
|
| 299 |
-
pass
|
| 300 |
-
|
| 301 |
-
print(f"[ๆง่กๅจ] ๐ ๅผๅงๆง่ก ComfyUI Workflow...", flush=True)
|
| 302 |
-
|
| 303 |
-
# ๐ ๆ ธๅฟๆฐๅข๏ผ่ฎฐๅฝๅผๅงๆถ้ด (็จไบๆๅ็ฎ workflow ๆป่ๆถ)
|
| 304 |
-
workflow_start = time.time()
|
| 305 |
-
# ๆง่กๅทฅไฝๆต
|
| 306 |
-
executor.execute(workflow, prompt_id, extra_data={}, execute_outputs=[save_id])
|
| 307 |
-
|
| 308 |
-
# ๐ ็ปๆๆนๆก๏ผๅๅ
ฅๆฌๅฐไธดๆถๆไปถ
|
| 309 |
-
import json
|
| 310 |
-
import os
|
| 311 |
-
wf_time = round(time.time() - workflow_start, 2)
|
| 312 |
-
|
| 313 |
-
if task_id:
|
| 314 |
-
try:
|
| 315 |
-
metric_file = f"/tmp/metrics_{task_id}.json"
|
| 316 |
-
saved_data = {}
|
| 317 |
-
if os.path.exists(metric_file):
|
| 318 |
-
with open(metric_file, "r") as f:
|
| 319 |
-
saved_data = json.load(f)
|
| 320 |
-
|
| 321 |
-
saved_data["workflow"] = wf_time
|
| 322 |
-
|
| 323 |
-
# ๐ ็ปๅฝๅ
ๅบ๏ผๅฆๆๅ ไธบ่ทณๆญฅ๏ผๆข้ๆฒกๆๅฐ load_time๏ผๅฐฑๅจ่ฟ้ๅผบ่ก่กฅ็ฎ๏ผ
|
| 324 |
-
if "load_time" not in saved_data:
|
| 325 |
-
load_start = saved_data.get("load_start", workflow_start)
|
| 326 |
-
# ็จๆปๆต็จ่ๆถๅๅป็บฏ่ทๅพ่ๆถไฝไธบๅ
ๅบ
|
| 327 |
-
saved_data["load_time"] = round(wf_time * 0.8, 2) # ๆ่
็ดๆฅ round(wf_time, 2)
|
| 328 |
-
print(f"[ๆข้] โ ๏ธ ๅ
ๅบ่กฅๅฝ load_time: {saved_data['load_time']}s", flush=True)
|
| 329 |
-
|
| 330 |
-
with open(metric_file, "w") as f:
|
| 331 |
-
json.dump(saved_data, f)
|
| 332 |
-
except Exception as e:
|
| 333 |
-
print(f"ๅๅ
ฅ workflow ๆๆ ๅคฑ่ดฅ: {e}")
|
| 334 |
-
|
| 335 |
-
print(f"[ๆง่กๅจ] โ
ComfyUI Workflow ๆง่กๅฎๆฏ๏ผ่ๆถ: {wf_time}s", flush=True)
|
| 336 |
-
|
| 337 |
-
if not executor.success:
|
| 338 |
-
message = executor.status_messages[-1] if executor.status_messages else "ComfyUI execution failed"
|
| 339 |
-
raise RuntimeError(str(message))
|
| 340 |
-
|
| 341 |
-
paths = []
|
| 342 |
-
for output in executor.history_result.get("outputs", {}).values():
|
| 343 |
-
for items in output.values():
|
| 344 |
-
if not isinstance(items, list): continue
|
| 345 |
-
for item in items:
|
| 346 |
-
if not isinstance(item, dict) or not item.get("filename"): continue
|
| 347 |
-
candidate = OUTPUT / item.get("subfolder", "") / item["filename"]
|
| 348 |
-
if candidate.exists(): paths.append(str(candidate))
|
| 349 |
-
if not paths:
|
| 350 |
-
paths = sorted([p for p in glob.glob(str(OUTPUT / "**" / "*.png"), recursive=True)], key=lambda p: os.path.getmtime(p), reverse=True)
|
| 351 |
-
return paths[:1]
|
| 352 |
-
finally:
|
| 353 |
-
# ๐ ไธฅๆ ผ่ฟๅ
|
| 354 |
-
tqdm_lib.tqdm = original_tqdm
|
| 355 |
-
tqdm.auto.tqdm = original_auto_tqdm
|
| 356 |
-
|
| 357 |
-
# ๐ ๆฐๅข๏ผไธปๅจๅ
ณ้ญ event loop๏ผ้ฒๆญข Python 3.12 ็ GC ๆฅ้
|
| 358 |
-
if 'loop' in locals() and not loop.is_closed():
|
| 359 |
-
try:
|
| 360 |
-
loop.close()
|
| 361 |
-
except Exception:
|
| 362 |
-
pass
|
| 363 |
-
|
| 364 |
-
# ==========================================================================
|
| 365 |
-
# ๐ ็ปไธ่ฟๅบฆๆฆๆชๅจ๏ผๅๆถๆฅ็ฎกไธ่ฝฝ & ่ทๅพ่ฟๅบฆ
|
| 366 |
-
# ==========================================================================
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
_current_download_task_id = None
|
| 370 |
-
_current_generation_task_id = None
|
| 371 |
-
|
| 372 |
-
class UnifiedProgressTqdm(tqdm):
|
| 373 |
-
def update(self, n=1):
|
| 374 |
-
super().update(n)
|
| 375 |
-
|
| 376 |
-
# ========================================================
|
| 377 |
-
# ๐ 1. ไธ่ฝฝ LoRA ่ฟๅบฆ (ไฟๆๅๆ ท)
|
| 378 |
-
# ========================================================
|
| 379 |
-
if _current_download_task_id and _current_download_task_id in tasks_status:
|
| 380 |
-
if self.total and self.total > 0:
|
| 381 |
-
percent = int((self.n / self.total) * 100)
|
| 382 |
-
tasks_status[_current_download_task_id]["message"] = f"๐ฅ Downloading LoRA: {percent}%..."
|
| 383 |
-
else:
|
| 384 |
-
# ๅฆๆ total ๆฟไธๅฐ๏ผ่ณๅฐๆๅฝๅไธ่ฝฝไบๅคๅฐๅญ่ๅ่ฏๅ็ซฏ
|
| 385 |
-
tasks_status[_current_download_task_id]["message"] = f"๐ฅ Downloading LoRA: {self.n} units..."
|
| 386 |
-
return # ๐ ไธ่ฝฝๅฎๆฏ็ดๆฅ return๏ผ็ปไธๅพไธ่ตฐๅป็ขฐ่ทๅพ้ป่พ
|
| 387 |
-
|
| 388 |
-
# ========================================================
|
| 389 |
-
# ๐ 2. ComfyUI ่ทๅพ่ฟๅบฆ
|
| 390 |
-
# ========================================================
|
| 391 |
-
if _current_generation_task_id and _current_generation_task_id in tasks_status:
|
| 392 |
-
if self.total and self.total > 1:
|
| 393 |
-
# ๐ ไฟฎๅค้ฒ่ทณๆญฅ๏ผๅช่ฆ็ๅฐ่ฟๅบฆๆก๏ผไธ่ฟๆฒก็ฎ่ฟ๏ผๅฐฑ็ซๅป็ฎไธๆฌก
|
| 394 |
-
import json
|
| 395 |
-
import os
|
| 396 |
-
import time
|
| 397 |
-
try:
|
| 398 |
-
metric_file = f"/tmp/metrics_{_current_generation_task_id}.json"
|
| 399 |
-
if os.path.exists(metric_file):
|
| 400 |
-
with open(metric_file, "r") as f:
|
| 401 |
-
saved_data = json.load(f)
|
| 402 |
-
|
| 403 |
-
# ๐ 1. ่ฎก็ฎๅนถๅๅ
ฅ load_time๏ผๅชๅจ็ฌฌไธๆฌกๆฆๆชๆถ่ฎก็ฎ๏ผ
|
| 404 |
-
if "load_time" not in saved_data:
|
| 405 |
-
load_start = saved_data.get("load_start", time.time())
|
| 406 |
-
load_time = round(time.time() - load_start, 2)
|
| 407 |
-
|
| 408 |
-
saved_data["load_time"] = load_time
|
| 409 |
-
print(f"[ๆข้] ๐ฏ ๆๅ่ฎก็ฎๅนถๅๅ
ฅ load_time: {load_time}s", flush=True)
|
| 410 |
-
|
| 411 |
-
# ๐ 2. ๅผบๅถๆดๆฐ็ฉ็ๆไปถ็ phase ็ถๆไธบ Sampling
|
| 412 |
-
# ๅช่ฆ่ฟๅจๆง่กๆต้ถๆฎต๏ผๅฐฑๅผบ่กๅๅฐ Sampling๏ผ่ฎฉๅ็ซฏ UI ็ซๅปๅๅบ
|
| 413 |
-
saved_data["phase"] = "๐จ Running KSampler..."
|
| 414 |
-
|
| 415 |
-
with open(metric_file, "w") as f:
|
| 416 |
-
json.dump(saved_data, f)
|
| 417 |
-
except Exception as e:
|
| 418 |
-
print(f"[ๆข้] โ ๆดๆฐ็ฉ็ๆไปถๅคฑ่ดฅ: {e}", flush=True)
|
| 419 |
-
# ๐๐๐ ๆ ธๅฟ่กฅไธ็ปๆ ๐๐๐
|
| 420 |
-
|
| 421 |
-
percent = int((self.n / self.total) * 100)
|
| 422 |
-
current_step_msg = f"๐จ Rendering: {self.n}/{self.total} steps ({percent}%)"
|
| 423 |
-
tasks_status[_current_generation_task_id]["message"] = current_step_msg
|
| 424 |
-
|
| 425 |
-
# ๐ ๆ ธๅฟไฟฎๅค๏ผๆ็ๅฎ็่ฟๅบฆๅ่ฟ็ฉ็ๆไปถ๏ผ่ไธๆฏๅชๅไธๅฅๅนฒๅทดๅทด็ KSampler๏ผ
|
| 426 |
-
try:
|
| 427 |
-
import json
|
| 428 |
-
import os
|
| 429 |
-
metric_file = f"/tmp/metrics_{_current_generation_task_id}.json"
|
| 430 |
-
if os.path.exists(metric_file):
|
| 431 |
-
with open(metric_file, "r") as f:
|
| 432 |
-
saved_data = json.load(f)
|
| 433 |
-
|
| 434 |
-
# ็ดๆฅๆๅฝๅๆญฅๆฐไฝไธบ phase ๅๅบๅป
|
| 435 |
-
saved_data["phase"] = current_step_msg
|
| 436 |
-
|
| 437 |
-
with open(metric_file, "w") as f:
|
| 438 |
-
json.dump(saved_data, f)
|
| 439 |
-
except Exception:
|
| 440 |
-
pass
|
| 441 |
-
|
| 442 |
-
print(f"[่ฟๅบฆๆฆๆช] Task {_current_generation_task_id[:8]} | {self.n}/{self.total} steps ({percent}%)")
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
def prepare_env(char_enable: bool, char_lora: str, unet_choice: str, task_id: str = None):
|
| 446 |
-
global _current_download_task_id
|
| 447 |
-
_current_download_task_id = task_id
|
| 448 |
-
|
| 449 |
-
# ๐ ๆ ธๅฟ๏ผ็ดๆฅๅซๆๅ
จๅฑ็ tqdm ๆจกๅ๏ผ่ไธๆฏๅป็ huggingface_hub ๆ tqdm ๆพๅจไบๅช
|
| 450 |
-
import tqdm.auto
|
| 451 |
-
original_tqdm = tqdm.auto.tqdm
|
| 452 |
-
tqdm.auto.tqdm = UnifiedProgressTqdm
|
| 453 |
-
|
| 454 |
-
try:
|
| 455 |
-
engine = UNET_CHOICES.get(unet_choice, {}).get("engine", "MOSS")
|
| 456 |
-
if char_enable and char_lora:
|
| 457 |
-
lora_root = MODELS / "loras"
|
| 458 |
-
dest = lora_root / char_lora
|
| 459 |
-
if not dest.exists():
|
| 460 |
-
file_path = CHAR_LORA_CHOICES.get(engine, {}).get(char_lora, {}).get("path")
|
| 461 |
-
if file_path:
|
| 462 |
-
if task_id and task_id in tasks_status:
|
| 463 |
-
tasks_status[task_id]["message"] = f"๐ฅ Downloading LoRA ({char_lora})..."
|
| 464 |
-
|
| 465 |
-
hf_hub_download(repo_id=MODEL_CONFIG['char_lora_repo'], filename=file_path, local_dir=str(lora_root))
|
| 466 |
-
src = lora_root / file_path
|
| 467 |
-
if src.exists(): shutil.move(str(src), str(dest))
|
| 468 |
-
|
| 469 |
-
if task_id and task_id in tasks_status:
|
| 470 |
-
tasks_status[task_id]["message"] = "๐ฆ LoRA downloaded, loading..."
|
| 471 |
-
finally:
|
| 472 |
-
# ๐ ่ฟๅๅ
จๅฑ็ tqdm ๆจกๅ
|
| 473 |
-
tqdm.auto.tqdm = original_tqdm
|
| 474 |
-
_current_download_task_id = None
|
| 475 |
-
|
| 476 |
-
@spaces.GPU(duration=30)
|
| 477 |
-
def generate(
|
| 478 |
-
prompt: str, unet_choice: str, custom_w: int, custom_h: int,
|
| 479 |
-
steps: int, cfg: float, seed: int, sampler: str, scheduler: str,
|
| 480 |
-
char_enable: bool, char_lora: str, char_strength: float,
|
| 481 |
-
*lora_states,
|
| 482 |
-
task_id: str = None, # ๐ ๅฟ
้กปๆ = None
|
| 483 |
-
) -> str:
|
| 484 |
-
|
| 485 |
-
import time
|
| 486 |
-
import json
|
| 487 |
-
import os
|
| 488 |
-
|
| 489 |
-
# ๐ ๅฎๅ
จๅ
ๅบ๏ผ้ฒๆญข ZeroGPU ่ทๅพๅคชๅฟซๅฏผ่ดๅญๅ
ธ่ฟๆฒกๅปบๅฅฝ
|
| 490 |
-
if task_id:
|
| 491 |
-
if task_id not in tasks_status:
|
| 492 |
-
tasks_status[task_id] = {}
|
| 493 |
-
|
| 494 |
-
#q_time = max(0.0, round(time.time() - tasks_status[task_id].get("queue_start_time", time.time()), 2))
|
| 495 |
-
|
| 496 |
-
# ๐ ๆ่งฃ่ฎก็ฎๆ้ๆถ้ด
|
| 497 |
-
now_ts = time.time()
|
| 498 |
-
start_ts = tasks_status[task_id].get("queue_start_time", now_ts)
|
| 499 |
-
raw_diff = now_ts - start_ts
|
| 500 |
-
|
| 501 |
-
print(f"[ๆ้ๆข้] ๆฟๅฐๅกๆถ้ด: {now_ts:.2f}, ๆ้่ตท็นๆถ้ด: {start_ts:.2f}, ๅๅงๅทฎๅผ: {raw_diff:.2f}s", flush=True)
|
| 502 |
-
|
| 503 |
-
q_time = max(0.0, round(raw_diff, 2))
|
| 504 |
-
|
| 505 |
-
tasks_status[task_id]["metrics_queue"] = q_time
|
| 506 |
-
tasks_status[task_id]["message"] = "โ๏ธ Allocating GPU..."
|
| 507 |
-
|
| 508 |
-
# ๐ ๆๆ้ๆถ้ดๅๅ
ฅ็ฉ็ๆไปถ
|
| 509 |
-
try:
|
| 510 |
-
saved_data = {}
|
| 511 |
-
metric_file = f"/tmp/metrics_{task_id}.json"
|
| 512 |
-
if os.path.exists(metric_file):
|
| 513 |
-
with open(metric_file, "r") as f:
|
| 514 |
-
saved_data = json.load(f)
|
| 515 |
-
|
| 516 |
-
saved_data["queue"] = q_time
|
| 517 |
-
saved_data["phase"] = "Allocating GPU..."
|
| 518 |
-
with open(metric_file, "w") as f:
|
| 519 |
-
json.dump(saved_data, f)
|
| 520 |
-
except Exception as e:
|
| 521 |
-
print(f"ๅๅ
ฅ queue ๆๆ ๅคฑ่ดฅ: {e}")
|
| 522 |
-
|
| 523 |
-
print(f"[GPU ๆข้] ๐ข ๆๅ่ทๅ GPU๏ผๆ้่ๆถ: {q_time}s", flush=True)
|
| 524 |
-
|
| 525 |
-
effective_seed = int(seed) # ็ดๆฅไฝฟ็จๅค้ขไผ ่ฟๆฅ็ๆ็ป seed
|
| 526 |
-
width, height = int(custom_w), int(custom_h)
|
| 527 |
-
unet_info = UNET_CHOICES[unet_choice]
|
| 528 |
-
unet_name = unet_info["filename"]
|
| 529 |
-
engine = unet_info["engine"]
|
| 530 |
-
engine_cfg = MODEL_CONFIG["models"].get(engine, {})
|
| 531 |
-
base_lora_inputs = []
|
| 532 |
-
base_choices_list = list(BASE_LORAS_CHOICES.items())
|
| 533 |
-
for i in range(0, len(lora_states), 2):
|
| 534 |
-
enable = lora_states[i]
|
| 535 |
-
strength = float(lora_states[i+1])
|
| 536 |
-
if enable and strength > 0:
|
| 537 |
-
lora_name, lora_cfg = base_choices_list[i // 2]
|
| 538 |
-
if lora_cfg["engine"] == engine:
|
| 539 |
-
base_lora_inputs.append((lora_cfg["filename"], strength))
|
| 540 |
-
try:
|
| 541 |
-
current_model_node = "1"
|
| 542 |
-
nodes = MODEL_CONFIG["node_types"]
|
| 543 |
-
clip_loader_node = engine_cfg.get("clip_loader_override", nodes["clip_loader"])
|
| 544 |
-
clip_type = engine_cfg.get("clip_type", "moss_image")
|
| 545 |
-
clip_inputs = {"type": clip_type}
|
| 546 |
-
te_filenames = engine_cfg.get("local_te_filename", [])
|
| 547 |
-
if clip_loader_node == "DualCLIPLoader":
|
| 548 |
-
if len(te_filenames) >= 2:
|
| 549 |
-
if "clip_l" in te_filenames[0].lower():
|
| 550 |
-
clip_inputs["clip_name1"] = te_filenames[0]
|
| 551 |
-
clip_inputs["clip_name2"] = te_filenames[1]
|
| 552 |
-
else:
|
| 553 |
-
clip_inputs["clip_name1"] = te_filenames[1]
|
| 554 |
-
clip_inputs["clip_name2"] = te_filenames[0]
|
| 555 |
-
elif len(te_filenames) == 1:
|
| 556 |
-
clip_inputs["clip_name1"] = te_filenames[0]
|
| 557 |
-
else:
|
| 558 |
-
if te_filenames: clip_inputs["clip_name"] = te_filenames[0]
|
| 559 |
-
if "clip_device" in MODEL_CONFIG.get("loader_args", {}):
|
| 560 |
-
clip_inputs["device"] = MODEL_CONFIG["loader_args"]["clip_device"]
|
| 561 |
-
vae_filename = engine_cfg.get("local_vae_filename", "")
|
| 562 |
-
workflow = {
|
| 563 |
-
"1": {"class_type": nodes["unet_loader"], "inputs": {"unet_name": unet_name, "weight_dtype": "default"}},
|
| 564 |
-
"2": {"class_type": clip_loader_node, "inputs": clip_inputs},
|
| 565 |
-
"3": {"class_type": nodes["vae_loader"], "inputs": {"vae_name": vae_filename}},
|
| 566 |
}
|
| 567 |
-
node_idx = 4
|
| 568 |
-
for lora_file, strength in base_lora_inputs:
|
| 569 |
-
workflow[str(node_idx)] = {"class_type": nodes["lora_loader"], "inputs": {"model": _ref(current_model_node), "lora_name": lora_file, "strength_model": strength}}
|
| 570 |
-
current_model_node = str(node_idx)
|
| 571 |
-
node_idx += 1
|
| 572 |
-
if char_enable and char_lora:
|
| 573 |
-
workflow[str(node_idx)] = {"class_type": nodes["lora_loader"], "inputs": {"model": _ref(current_model_node), "lora_name": char_lora, "strength_model": char_strength}}
|
| 574 |
-
current_model_node = str(node_idx)
|
| 575 |
-
node_idx += 1
|
| 576 |
-
final_prompt = prompt.strip()
|
| 577 |
-
workflow[str(node_idx)] = {"class_type": "CLIPTextEncode", "inputs": {"clip": _ref("2"), "text": final_prompt}}
|
| 578 |
-
workflow[str(node_idx+1)] = {"class_type": "ConditioningZeroOut", "inputs": {"conditioning": _ref(str(node_idx))}}
|
| 579 |
-
workflow[str(node_idx+2)] = {"class_type": "EmptyLatentImage", "inputs": {"width": width, "height": height, "batch_size": 1}}
|
| 580 |
-
workflow[str(node_idx+3)] = {"class_type": "KSampler", "inputs": {"model": _ref(current_model_node), "positive": _ref(str(node_idx)), "negative": _ref(str(node_idx+1)), "latent_image": _ref(str(node_idx+2)), "seed": effective_seed, "steps": steps, "cfg": cfg, "sampler_name": sampler, "scheduler": scheduler, "denoise": 1.0}}
|
| 581 |
-
workflow[str(node_idx+4)] = {"class_type": "VAEDecode", "inputs": {"samples": _ref(str(node_idx+3)), "vae": _ref("3")}}
|
| 582 |
-
workflow[str(node_idx+5)] = {"class_type": "SaveImage", "inputs": {"images": _ref(str(node_idx+4)), "filename_prefix": MODEL_CONFIG["name"].lower()}}
|
| 583 |
-
|
| 584 |
-
print(f"[GPU ๆข้] ๐ฆ ๆจกๅ่็นๆๅปบๅฎๆฏ๏ผๅๅค่ฐ็จ ComfyUI ๆง่กๅผๆ...", flush=True)
|
| 585 |
-
|
| 586 |
-
# ๐ 2. ๅฐ metrics ไผ ้่ฟๆง่กๅจ
|
| 587 |
-
return _execute_workflow(workflow, task_id)[0]
|
| 588 |
-
except Exception as exc:
|
| 589 |
-
print(traceback.format_exc(), flush=True)
|
| 590 |
-
raise gr.Error(f"generation failed: {str(exc)[:500]}") from exc
|
| 591 |
-
|
| 592 |
-
# ==========================================================================
|
| 593 |
-
# ๐ฅ๏ธ GUI (ๅฎๅ
จ้ๆญปๅฎฝๅบฆ๏ผๅปๆๆๆๅจๆ CSS ๆณจๅ
ฅ)
|
| 594 |
-
# ==========================================================================
|
| 595 |
-
custom_css = """
|
| 596 |
-
/* ๅบ็ก้็ฝฎไธ้ๆ */
|
| 597 |
-
.gradio-container {
|
| 598 |
-
max-width: 100% !important;
|
| 599 |
-
width: 100% !important;
|
| 600 |
-
}
|
| 601 |
-
.gradio-container .gr-group {
|
| 602 |
-
background: transparent !important;
|
| 603 |
-
padding: 16px !important;
|
| 604 |
-
gap: 12px !important;
|
| 605 |
-
}
|
| 606 |
-
.gradio-container .gr-group > div,
|
| 607 |
-
.gradio-container .form,
|
| 608 |
-
.gradio-container .block {
|
| 609 |
-
background: transparent !important;
|
| 610 |
-
border: none !important;
|
| 611 |
-
box-shadow: none !important;
|
| 612 |
-
}
|
| 613 |
-
.lora-row {
|
| 614 |
-
flex-wrap: nowrap !important;
|
| 615 |
-
align-items: center !important;
|
| 616 |
-
}
|
| 617 |
-
.label-textbox {
|
| 618 |
-
min-width: 80px !important;
|
| 619 |
-
max-width: 80px !important;
|
| 620 |
-
white-space: nowrap !important;
|
| 621 |
-
text-align: right !important;
|
| 622 |
-
display: flex !important;
|
| 623 |
-
justify-content: flex-end !important;
|
| 624 |
-
align-items: center !important;
|
| 625 |
-
color: var(--block-title-text-color);
|
| 626 |
-
}
|
| 627 |
-
|
| 628 |
-
.label-textbox textarea,
|
| 629 |
-
.label-textbox input {
|
| 630 |
-
line-height: var(--line-lg) !important;;
|
| 631 |
-
font-weight: var(--prose-text-weight) !important;
|
| 632 |
-
font-size: var(--text-md) !important !important;;
|
| 633 |
-
color: var(--block-title-text-color) !important;;
|
| 634 |
-
-webkit-text-fill-color: var(--block-title-text-color) !important; /* ่งฃๅณ Safari/Chrome ็้ข่ฒ่ฆ็้ฎ้ข */
|
| 635 |
-
opacity: 1 !important; /* ๆไบ disabled ็ถๆไผ้ไฝ้ๆๅบฆ */
|
| 636 |
-
}
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
.readonly-name-box {
|
| 640 |
-
border: 1px solid var(--border-color-primary) !important;
|
| 641 |
-
border-radius: 8px !important;
|
| 642 |
-
background: var(--background-fill-secondary) !important;
|
| 643 |
-
}
|
| 644 |
-
.lora-row input[type="checkbox"] {
|
| 645 |
-
width: 20px !important;
|
| 646 |
-
height: 20px !important;
|
| 647 |
-
min-width: 20px !important;
|
| 648 |
-
max-width: 20px !important;
|
| 649 |
-
}
|
| 650 |
-
.lora_checkbox { max-width: 36px !important; }
|
| 651 |
-
.lora_strength_input {
|
| 652 |
-
min-width: 100px !important;
|
| 653 |
-
max-width: 100px !important;
|
| 654 |
-
flex-shrink: 0 !important;
|
| 655 |
-
}
|
| 656 |
-
.output-group {
|
| 657 |
-
border: 1px solid var(--border-color-primary) !important;
|
| 658 |
-
border-radius: 8px !important;
|
| 659 |
-
padding: 16px !important;
|
| 660 |
-
background: transparent !important;
|
| 661 |
-
height: 100%;
|
| 662 |
-
}
|
| 663 |
-
.output-group .gr-image { border: none !important; }
|
| 664 |
-
|
| 665 |
-
.selected-status-text {
|
| 666 |
-
color: var(--body-text-color) !important;
|
| 667 |
-
font-weight: var(--input-text-weight);
|
| 668 |
-
font-size: clamp(8px, 1.2vw, 14px) !important;
|
| 669 |
-
line-height: 1.2 !important;
|
| 670 |
-
text-align: left !important;
|
| 671 |
-
white-space: nowrap !important;
|
| 672 |
-
overflow: hidden !important;
|
| 673 |
-
text-overflow: ellipsis !important;
|
| 674 |
-
margin: 0 !important;
|
| 675 |
-
padding: 0 !important;
|
| 676 |
-
}
|
| 677 |
-
.selected-status-text .highlight { color: #FF7F50 !important; }
|
| 678 |
-
|
| 679 |
-
/* ็ปๅปๅบๅ */
|
| 680 |
-
.gallery-wrapper {
|
| 681 |
-
border: 1px solid var(--border-color-primary) !important;
|
| 682 |
-
border-radius: 8px !important;
|
| 683 |
-
padding: 12px !important;
|
| 684 |
-
box-sizing: border-box !important;
|
| 685 |
-
background: transparent !important;
|
| 686 |
-
}
|
| 687 |
-
.super-gallery {
|
| 688 |
-
background: transparent !important;
|
| 689 |
-
border: none !important;
|
| 690 |
-
}
|
| 691 |
-
.super-gallery .grid-wrap {
|
| 692 |
-
gap: 12px !important;
|
| 693 |
-
max-height: 600px !important;
|
| 694 |
-
overflow-y: auto !important;
|
| 695 |
-
overflow-x: hidden !important;
|
| 696 |
-
border: none !important;
|
| 697 |
-
padding: 0 !important;
|
| 698 |
-
box-sizing: border-box !important;
|
| 699 |
-
background: transparent !important;
|
| 700 |
-
}
|
| 701 |
-
.super-gallery .grid-wrap::-webkit-scrollbar { width: 6px !important; background: transparent !important; }
|
| 702 |
-
.super-gallery .grid-wrap::-webkit-scrollbar-thumb { background: rgba(150, 150, 150, 0.3) !important; border-radius: 10px !important; }
|
| 703 |
-
.super-gallery .grid-wrap:hover::-webkit-scrollbar-thumb { background: rgba(150, 150, 150, 0.7) !important; }
|
| 704 |
-
|
| 705 |
-
.super-gallery .icon-button-wrapper,
|
| 706 |
-
.super-gallery button[title="Download"],
|
| 707 |
-
.super-gallery .tooltip,
|
| 708 |
-
.super-gallery [role="tooltip"],
|
| 709 |
-
.gallery-wrapper .wrap > div[style*="position: absolute"] {
|
| 710 |
-
display: none !important;
|
| 711 |
-
opacity: 0 !important;
|
| 712 |
-
pointer-events: none !important;
|
| 713 |
-
}
|
| 714 |
-
|
| 715 |
-
.super-gallery .thumbnail-item {
|
| 716 |
-
border-radius: 8px !important;
|
| 717 |
-
overflow: hidden !important;
|
| 718 |
-
aspect-ratio: 3 / 4 !important;
|
| 719 |
-
background: var(--background-fill-secondary) !important;
|
| 720 |
-
border: 3px solid transparent !important;
|
| 721 |
-
position: relative !important;
|
| 722 |
-
box-sizing: border-box !important;
|
| 723 |
-
transition: border-color 0.2s ease !important;
|
| 724 |
-
}
|
| 725 |
-
.super-gallery .thumbnail-item img {
|
| 726 |
-
display: block !important;
|
| 727 |
-
width: 100% !important;
|
| 728 |
-
height: 100% !important;
|
| 729 |
-
object-fit: cover !important;
|
| 730 |
-
object-position: top center !important;
|
| 731 |
-
border: none !important;
|
| 732 |
-
outline: none !important;
|
| 733 |
-
}
|
| 734 |
-
.super-gallery .thumbnail-item.selected {
|
| 735 |
-
border: 3px solid #FF7F50 !important;
|
| 736 |
-
z-index: 10 !important;
|
| 737 |
-
}
|
| 738 |
-
.super-gallery .caption-wrap {
|
| 739 |
-
background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%) !important;
|
| 740 |
-
border: none !important;
|
| 741 |
-
position: absolute !important;
|
| 742 |
-
bottom: 0 !important;
|
| 743 |
-
left: 0 !important;
|
| 744 |
-
right: 0 !important;
|
| 745 |
-
padding: 20px 8px 8px 8px !important;
|
| 746 |
-
z-index: 3 !important;
|
| 747 |
-
box-sizing: border-box !important;
|
| 748 |
-
}
|
| 749 |
-
.super-gallery .caption-wrap .caption {
|
| 750 |
-
color: #fff !important;
|
| 751 |
-
font-size: 10px !important;
|
| 752 |
-
text-align: left !important;
|
| 753 |
-
white-space: nowrap !important;
|
| 754 |
-
overflow: hidden !important;
|
| 755 |
-
text-overflow: ellipsis !important;
|
| 756 |
-
}
|
| 757 |
-
.super-gallery .preview { display: none !important; }
|
| 758 |
-
|
| 759 |
-
a:hover {
|
| 760 |
-
opacity: 0.8 !important;
|
| 761 |
-
text-decoration: underline !important;
|
| 762 |
-
}
|
| 763 |
-
"""
|
| 764 |
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
unet_choice = gr.Dropdown(choices=list(UNET_CHOICES.keys()), value=initial_unet, label="Base Model")
|
| 780 |
-
prompt = gr.Textbox(
|
| 781 |
-
value=MODEL_CONFIG.get("default_prompt", ""),
|
| 782 |
-
label="Prompt", lines=5
|
| 783 |
-
)
|
| 784 |
-
|
| 785 |
-
with gr.Row():
|
| 786 |
-
custom_w = gr.Slider(1, 1536, value=1024, step=16, label="Width")
|
| 787 |
-
custom_h = gr.Slider(1, 1536, value=1024, step=16, label="Height")
|
| 788 |
-
|
| 789 |
-
with gr.Row():
|
| 790 |
-
steps = gr.Slider(4, 50, value=MODEL_CONFIG["models"][initial_engine]["defaults"]["steps"], step=1, label="steps")
|
| 791 |
-
cfg = gr.Slider(1.0, 10.0, value=MODEL_CONFIG["models"][initial_engine]["defaults"]["cfg"], step=0.1, label="CFG")
|
| 792 |
-
|
| 793 |
-
with gr.Row():
|
| 794 |
-
sampler = gr.Dropdown(choices=SAMPLERS, value=MODEL_CONFIG["models"][initial_engine]["defaults"]["sampler"], label="Sampler")
|
| 795 |
-
scheduler = gr.Dropdown(choices=SCHEDULERS, value=MODEL_CONFIG["models"][initial_engine]["defaults"]["scheduler"], label="Scheduler")
|
| 796 |
-
seed = gr.Number(value=-1, precision=0, label="Seed")
|
| 797 |
-
|
| 798 |
-
#base_lora_title = gr.Markdown("โ๏ธ Base / Turbo LoRAs")
|
| 799 |
-
|
| 800 |
-
base_lora_title_html = f'''
|
| 801 |
-
<div style="line-height: var(--line-lg); font-weight: var(--prose-text-weight) !important; font-size: var(--text-md) !important; color: var(--block-title-text-color); margin-bottom: -4px !important;">
|
| 802 |
-
โ๏ธ Base / Turbo LoRAs
|
| 803 |
-
</div>
|
| 804 |
-
'''
|
| 805 |
-
base_lora_title = gr.HTML(value=base_lora_title_html)
|
| 806 |
-
|
| 807 |
-
base_lora_components = []
|
| 808 |
-
if BASE_LORAS_CHOICES:
|
| 809 |
-
for name, cfg_item in BASE_LORAS_CHOICES.items():
|
| 810 |
-
is_visible = (cfg_item["engine"] == initial_engine)
|
| 811 |
-
with gr.Row(elem_classes="lora-row", visible=is_visible) as row:
|
| 812 |
-
cb = gr.Checkbox(value=cfg_item["defaultEnable"], container=False, scale=0, min_width=30, elem_classes="lora_checkbox")
|
| 813 |
-
name_box = gr.Textbox(value=name, show_label=False, container=False, interactive=False, scale=8)
|
| 814 |
-
gr.Textbox(value="Strength", show_label=False, container=False, interactive=False, text_align="right", elem_classes="label-textbox", scale=1, min_width=80)
|
| 815 |
-
num = gr.Number(value=1.0, show_label=False, container=True, step=0.05, scale=0, elem_classes="lora_strength_input", min_width=100)
|
| 816 |
-
|
| 817 |
-
base_lora_components.extend([cb, num])
|
| 818 |
-
all_base_lora_rows.append((cfg_item["engine"], row))
|
| 819 |
-
|
| 820 |
-
# ๐ก 2. ไธญ้ด็ปๅปๅบ
|
| 821 |
-
with gr.Column(scale=6):
|
| 822 |
-
with gr.Group():
|
| 823 |
-
link_url = "https://huggingface.co/spaces/waveshaker/loras_gallery"
|
| 824 |
-
|
| 825 |
-
gallery_title_html = f'''
|
| 826 |
-
<div style="line-height: var(--line-lg); font-weight: var(--prose-text-weight) !important; font-size: var(--text-md) !important; color: var(--block-title-text-color); margin-bottom: -4px !important;">
|
| 827 |
-
๐ญ Character LoRA (Click to select)
|
| 828 |
-
<span style="color: var(--border-color-primary); margin: 0 8px;">|</span>
|
| 829 |
-
<a href="{link_url}" target="_blank" style="color: #FF7F50; text-decoration: none; transition: opacity 0.2s;" onmouseover="this.style.opacity=0.8" onmouseout="this.style.opacity=1">
|
| 830 |
-
Browse in ๐ผ๏ธ Gallery โ
|
| 831 |
-
</a>
|
| 832 |
-
</div>
|
| 833 |
-
'''
|
| 834 |
-
gr.HTML(value=gallery_title_html)
|
| 835 |
-
|
| 836 |
-
with gr.Row(elem_classes="lora-row", visible=False) as selected_row:
|
| 837 |
-
char_enable = gr.Checkbox(value=True, container=False, scale=0, min_width=30, elem_classes="lora_checkbox")
|
| 838 |
-
selected_text = gr.HTML(value='<div class="selected-status-text">None</div>', scale=1)
|
| 839 |
-
gr.Textbox(value="Strength", show_label=False, container=False, interactive=False, text_align="right", elem_classes="label-textbox", scale=0, min_width=80)
|
| 840 |
-
char_strength = gr.Number(value=initial_char_strength, show_label=False, container=True, step=0.05, scale=0, elem_classes="lora_strength_input", min_width=100)
|
| 841 |
-
|
| 842 |
-
with gr.Column(elem_classes="gallery-wrapper"):
|
| 843 |
-
char_gallery = gr.Gallery(
|
| 844 |
-
label="",
|
| 845 |
-
show_label=False,
|
| 846 |
-
columns=5,
|
| 847 |
-
height=400,
|
| 848 |
-
object_fit="cover",
|
| 849 |
-
allow_preview=False,
|
| 850 |
-
elem_classes="super-gallery"
|
| 851 |
-
)
|
| 852 |
-
|
| 853 |
-
char_lora_state = gr.State(value="")
|
| 854 |
-
url_lora_state = gr.State(value="")
|
| 855 |
-
|
| 856 |
-
# ๐ต 3. ๅณไพงๅบๅพๅบ
|
| 857 |
-
with gr.Column(scale=5):
|
| 858 |
-
with gr.Group(elem_classes="output-group"):
|
| 859 |
-
output = gr.Image(label="output", height=600)
|
| 860 |
-
status_text = gr.Markdown("", visible=False)
|
| 861 |
-
button = gr.Button("generate", variant="primary", size="lg")
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
# ==========================================
|
| 865 |
-
# UNet ๅๆข่ๅจ
|
| 866 |
-
# ==========================================
|
| 867 |
-
def on_unet_change(selected_unet, preferred_lora=None):
|
| 868 |
-
engine = UNET_CHOICES.get(selected_unet, {}).get("engine", "MOSS")
|
| 869 |
-
row_updates = [gr.update(visible=(re == engine)) for re, _ in all_base_lora_rows]
|
| 870 |
-
has_base_lora = any(cfg["engine"] == engine for cfg in BASE_LORAS_CHOICES.values())
|
| 871 |
-
title_update = gr.update(visible=has_base_lora)
|
| 872 |
-
|
| 873 |
-
new_char_dict = CHAR_LORA_CHOICES.get(engine, {})
|
| 874 |
-
gallery_items = []
|
| 875 |
-
for filename, info in new_char_dict.items():
|
| 876 |
-
display_name = filename.replace(".safetensors", "")
|
| 877 |
-
gallery_items.append((info["webp"], display_name))
|
| 878 |
-
|
| 879 |
-
engine_defaults = MODEL_CONFIG["models"].get(engine, {}).get("defaults", {})
|
| 880 |
-
steps_update = gr.update(value=engine_defaults.get("steps", 8))
|
| 881 |
-
cfg_update = gr.update(value=engine_defaults.get("cfg", 1.0))
|
| 882 |
-
sampler_update = gr.update(value=engine_defaults.get("sampler", "euler"))
|
| 883 |
-
scheduler_update = gr.update(value=engine_defaults.get("scheduler", "simple"))
|
| 884 |
-
char_strength_update = gr.update(value=engine_defaults.get("char_lora_strength", 1.0))
|
| 885 |
-
|
| 886 |
-
default_lora = None
|
| 887 |
-
if preferred_lora and preferred_lora in new_char_dict:
|
| 888 |
-
default_lora = preferred_lora
|
| 889 |
-
elif gallery_items:
|
| 890 |
-
default_lora = list(new_char_dict.keys())[0]
|
| 891 |
-
|
| 892 |
-
# ๐ ๆ ธๅฟไฟฎๅค๏ผไธ่ฆๆณจๅ
ฅ CSS๏ผ่ๆฏๅ่ฏ Gallery ๅชไธช index ่ขซ้ไธญไบ๏ผ
|
| 893 |
-
selected_index = None
|
| 894 |
-
if default_lora:
|
| 895 |
-
selected_index = list(new_char_dict.keys()).index(default_lora)
|
| 896 |
-
|
| 897 |
-
gallery_update = gr.update(value=gallery_items, selected_index=selected_index)
|
| 898 |
-
|
| 899 |
-
if default_lora:
|
| 900 |
-
display_name = default_lora.replace(".safetensors", "")
|
| 901 |
-
card_update = gr.update(visible=True)
|
| 902 |
-
text_html = f'<div class="selected-status-text"><span class="highlight">{display_name}</span></div>'
|
| 903 |
-
text_update = gr.update(value=text_html)
|
| 904 |
-
state_update = gr.update(value=default_lora)
|
| 905 |
-
else:
|
| 906 |
-
card_update = gr.update(visible=False)
|
| 907 |
-
text_update = gr.update(value='<div class="selected-status-text">None</div>')
|
| 908 |
-
state_update = gr.update(value="")
|
| 909 |
-
|
| 910 |
-
# ๆณจๆ๏ผ่ฟ้ๅปๆไบๅจๆ CSS ้ฃไธช่ฟๅ้กน
|
| 911 |
-
return [title_update, *row_updates, gallery_update, steps_update, cfg_update, sampler_update, scheduler_update, char_strength_update, card_update, text_update, state_update]
|
| 912 |
-
|
| 913 |
-
unet_choice.change(
|
| 914 |
-
fn=on_unet_change,
|
| 915 |
-
inputs=[unet_choice, url_lora_state],
|
| 916 |
-
# ๅปๆไบ dynamic_highlight_css
|
| 917 |
-
outputs=[base_lora_title,*[row for _, row in all_base_lora_rows], char_gallery, steps, cfg, sampler, scheduler, char_strength, selected_row, selected_text, char_lora_state]
|
| 918 |
-
)
|
| 919 |
-
|
| 920 |
-
# ==========================================
|
| 921 |
-
# Gallery ็นๅป้ไธญไบไปถ
|
| 922 |
-
# ==========================================
|
| 923 |
-
def on_gallery_select(evt: gr.SelectData, selected_unet):
|
| 924 |
-
engine = UNET_CHOICES.get(selected_unet, {}).get("engine", "MOSS")
|
| 925 |
-
char_list = list(CHAR_LORA_CHOICES.get(engine, {}).keys())
|
| 926 |
-
|
| 927 |
-
if evt.index < len(char_list):
|
| 928 |
-
selected_lora = char_list[evt.index]
|
| 929 |
-
display_name = selected_lora.replace(".safetensors", "")
|
| 930 |
-
text_html = f'<div class="selected-status-text"><span class="highlight">{display_name}</span></div>'
|
| 931 |
-
return gr.update(visible=True), gr.update(value=text_html), gr.update(value=selected_lora)
|
| 932 |
-
return gr.update(visible=False), gr.update(value='<div class="selected-status-text">None</div>'), gr.update(value="")
|
| 933 |
-
|
| 934 |
-
char_gallery.select(
|
| 935 |
-
fn=on_gallery_select, inputs=[unet_choice],
|
| 936 |
-
outputs=[selected_row, selected_text, char_lora_state]
|
| 937 |
-
)
|
| 938 |
-
|
| 939 |
-
# ==========================================
|
| 940 |
-
# URL ไผ ๅ่งฃๆ
|
| 941 |
-
# ==========================================
|
| 942 |
-
def on_page_load(request: gr.Request):
|
| 943 |
-
try:
|
| 944 |
-
load_char_loras_from_repo()
|
| 945 |
-
except Exception as e:
|
| 946 |
-
print(f"โ ๏ธ ้กต้ขๅ ่ฝฝๆถๅทๆฐ LoRA ๅคฑ่ดฅ๏ผๅฐไฝฟ็จๆง็ผๅญๆฐๆฎ: {e}")
|
| 947 |
-
|
| 948 |
-
model_param = request.query_params.get("model", "")
|
| 949 |
-
lora_param = request.query_params.get("lora", "")
|
| 950 |
-
target_unet = initial_unet
|
| 951 |
-
if model_param:
|
| 952 |
-
mapped_engine = MODEL_CONFIG["json_keys"]["root_mapping"].get(model_param.lower(), model_param)
|
| 953 |
-
for k, v in UNET_CHOICES.items():
|
| 954 |
-
if v["engine"] == mapped_engine:
|
| 955 |
-
target_unet = k
|
| 956 |
-
break
|
| 957 |
-
|
| 958 |
-
return target_unet, lora_param
|
| 959 |
-
|
| 960 |
-
demo.load(
|
| 961 |
-
fn=on_page_load, inputs=None, outputs=[unet_choice, url_lora_state]
|
| 962 |
-
).then(
|
| 963 |
-
fn=on_unet_change, inputs=[unet_choice, url_lora_state],
|
| 964 |
-
# ๅปๆไบ dynamic_highlight_css
|
| 965 |
-
outputs=[
|
| 966 |
-
base_lora_title, *[row for _, row in all_base_lora_rows],
|
| 967 |
-
char_gallery, steps, cfg, sampler, scheduler,
|
| 968 |
-
char_strength, selected_row, selected_text, char_lora_state
|
| 969 |
-
]
|
| 970 |
-
)
|
| 971 |
-
|
| 972 |
-
# ==========================================
|
| 973 |
-
# ็ถๆๆบ๏ผไธคๆญฅ่ตฐ (ไธ่ฝฝ -> ็ๆ)
|
| 974 |
-
# ==========================================
|
| 975 |
-
button.click(
|
| 976 |
-
fn=lambda: (gr.update(visible=True, value="โณ Selected LoRA is Downloading..."), gr.update(interactive=False)),
|
| 977 |
-
inputs=[], outputs=[status_text, button]
|
| 978 |
-
).then(
|
| 979 |
-
fn=prepare_env, inputs=[char_enable, char_lora_state, unet_choice], outputs=[],
|
| 980 |
-
).then(
|
| 981 |
-
fn=lambda: gr.update(visible=True, value="๐ Generating..."), inputs=[], outputs=[status_text]
|
| 982 |
-
).then(
|
| 983 |
-
fn=generate,
|
| 984 |
-
inputs=[
|
| 985 |
-
prompt, unet_choice, custom_w, custom_h,
|
| 986 |
-
steps, cfg, seed, sampler, scheduler,
|
| 987 |
-
char_enable, char_lora_state, char_strength,
|
| 988 |
-
*base_lora_components
|
| 989 |
-
],
|
| 990 |
-
outputs=[output]
|
| 991 |
-
).then(
|
| 992 |
-
fn=lambda: (gr.update(visible=True, value="โ
Done!"), gr.update(interactive=True)),
|
| 993 |
-
inputs=[], outputs=[status_text, button]
|
| 994 |
-
)
|
| 995 |
-
|
| 996 |
-
demo.queue()
|
| 997 |
-
|
| 998 |
-
# ==========================================================================
|
| 999 |
-
# ๐ API ่ทฏ็ฑไธๆ้ๆ่ฝฝ
|
| 1000 |
-
# ==========================================================================
|
| 1001 |
-
import uuid
|
| 1002 |
-
import base64
|
| 1003 |
-
import uvicorn
|
| 1004 |
-
import os
|
| 1005 |
-
from fastapi.responses import RedirectResponse
|
| 1006 |
-
from fastapi import FastAPI, BackgroundTasks
|
| 1007 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 1008 |
-
from fastapi.responses import HTMLResponse
|
| 1009 |
-
from pydantic import BaseModel
|
| 1010 |
-
from gradio.routes import mount_gradio_app
|
| 1011 |
-
|
| 1012 |
-
class GenerateRequest(BaseModel):
|
| 1013 |
-
prompt: str
|
| 1014 |
-
unet_choice: str
|
| 1015 |
-
custom_w: int = 1024
|
| 1016 |
-
custom_h: int = 1024
|
| 1017 |
-
steps: int = 8
|
| 1018 |
-
cfg: float = 1.0
|
| 1019 |
-
seed: int = -1
|
| 1020 |
-
sampler: str = "euler"
|
| 1021 |
-
scheduler: str = "simple"
|
| 1022 |
-
char_enable: bool = True
|
| 1023 |
-
char_lora: str = ""
|
| 1024 |
-
char_strength: float = 1.0
|
| 1025 |
-
base_lora_states: list = []
|
| 1026 |
|
| 1027 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
|
| 1029 |
-
|
| 1030 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1038 |
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
# ๐ 1. ่ฎฐๅฝไธ่ฝฝ่ๆถ
|
| 1044 |
-
download_start = time.time()
|
| 1045 |
-
prepare_env(req.char_enable, req.char_lora, req.unet_choice, task_id=task_id)
|
| 1046 |
-
real_download_time = round(time.time() - download_start, 2)
|
| 1047 |
-
|
| 1048 |
-
current_arch = UNET_CHOICES.get(req.unet_choice, {}).get("engine", "unknown")
|
| 1049 |
-
|
| 1050 |
-
# 2. ๅคๆญๆฏๅฆ้่ฆ้่ฝฝๆจกๅ
|
| 1051 |
-
need_heavy_load = (_last_used_architecture != current_arch) or (_last_used_unet != req.unet_choice)
|
| 1052 |
-
|
| 1053 |
-
if need_heavy_load:
|
| 1054 |
-
with _model_switch_lock:
|
| 1055 |
-
# ๅ้ๆฃๆฅ๏ผ้ฒๆญขๆ้ๆ้ดๅซ็็บฟ็จๅทฒ็ปๅ ่ฝฝๅฅฝไบ
|
| 1056 |
-
if _last_used_architecture != current_arch:
|
| 1057 |
-
tasks_status[task_id]["message"] = f"๐ฆ Queue for GPU... (Loading Base Model: {current_arch.upper()})"
|
| 1058 |
-
_last_used_architecture = current_arch
|
| 1059 |
-
_last_used_unet = req.unet_choice
|
| 1060 |
-
elif _last_used_unet != req.unet_choice:
|
| 1061 |
-
tasks_status[task_id]["message"] = "๐ Queue for GPU... (Swapping Model Checkpoint)"
|
| 1062 |
-
_last_used_unet = req.unet_choice
|
| 1063 |
-
else:
|
| 1064 |
-
# ๅบๆฏ 3๏ผLoRA ๅๆข๏ผ็งๅผ๏ผ็ดๆฅๆธฒๆ๏ผไธๆ้๏ผ
|
| 1065 |
-
tasks_status[task_id]["message"] = "๐จ Rendering image (GPU processing)..."
|
| 1066 |
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
print(f"[GPU ๆข้] ๐ด ๅ่ตท Request๏ผ็ณ่ฏท GPU ่ตๆบ...", flush=True)
|
| 1075 |
|
| 1076 |
-
|
| 1077 |
-
|
| 1078 |
-
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
-
|
| 1082 |
-
|
| 1083 |
-
|
| 1084 |
-
|
| 1085 |
-
|
| 1086 |
-
|
| 1087 |
-
|
| 1088 |
|
| 1089 |
-
|
| 1090 |
-
|
| 1091 |
-
|
| 1092 |
-
|
| 1093 |
-
|
| 1094 |
-
|
| 1095 |
-
|
| 1096 |
-
|
| 1097 |
-
if os.path.exists(metric_file):
|
| 1098 |
-
try:
|
| 1099 |
-
with open(metric_file, "r") as f:
|
| 1100 |
-
saved_metrics = json.load(f)
|
| 1101 |
-
final_queue = saved_metrics.get("queue", 0)
|
| 1102 |
-
final_workflow = saved_metrics.get("workflow", 0)
|
| 1103 |
-
final_load_time = saved_metrics.get("load_time", 0) # ๐ ๆ ธๅฟๆฐๅข
|
| 1104 |
-
os.remove(metric_file) # ็จๅฎๅ ๆ
|
| 1105 |
-
except Exception as e:
|
| 1106 |
-
print(f"่ฏปๅๆๆ ๆไปถๅคฑ่ดฅ: {e}")
|
| 1107 |
-
|
| 1108 |
-
# ==========================================================
|
| 1109 |
-
# ๐ 6. ๆๅ
ๆ็ป็ปๆ่ฟๅ
|
| 1110 |
-
# ==========================================================
|
| 1111 |
-
tasks_status[task_id] = {
|
| 1112 |
-
"status": "success",
|
| 1113 |
-
"image": f"data:image/png;base64,{img_base64}",
|
| 1114 |
-
"seed": final_seed,
|
| 1115 |
-
"metrics": {
|
| 1116 |
-
"download": real_download_time,
|
| 1117 |
-
"queue": final_queue,
|
| 1118 |
-
"workflow": final_workflow,
|
| 1119 |
-
"load_time": final_load_time, # ๐ ๆ ธๅฟๆฐๅข๏ผๅ็ปๅ็ซฏ
|
| 1120 |
-
"steps": req.steps
|
| 1121 |
-
}
|
| 1122 |
}
|
| 1123 |
-
except Exception as e:
|
| 1124 |
-
tasks_status[task_id] = {"status": "error", "message": str(e)}
|
| 1125 |
-
finally:
|
| 1126 |
-
_current_generation_task_id = None
|
| 1127 |
|
| 1128 |
-
|
| 1129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1130 |
|
| 1131 |
-
|
| 1132 |
-
|
| 1133 |
-
|
| 1134 |
-
|
| 1135 |
-
allow_methods=["*"],
|
| 1136 |
-
allow_headers=["*"],
|
| 1137 |
-
)
|
| 1138 |
|
| 1139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1140 |
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
html_content = f.read()
|
| 1147 |
-
|
| 1148 |
-
html_content = html_content.replace("__FRONTEND_URL__", frontend_url)
|
| 1149 |
-
html_content = html_content.replace("__DEV_MODE__", "True" if CORE_STATUS["dev_mode"] else "False")
|
| 1150 |
-
html_content = html_content.replace("__TARGET_MODEL__", CORE_STATUS["target_model"])
|
| 1151 |
-
html_content = html_content.replace("__GRADIO_UI__", "Enabled" if CORE_STATUS["gradio_ui"] else "Disabled")
|
| 1152 |
-
|
| 1153 |
-
return HTMLResponse(content=html_content)
|
| 1154 |
-
|
| 1155 |
-
|
| 1156 |
-
# 2. ๆ่ฝฝ API ่ทฏ็ฑ๏ผไธฅๆ ผๅธฆไธ /api ๅ็ผ๏ผ
|
| 1157 |
-
@app.post("/api/generate")
|
| 1158 |
-
async def handle_generate(req: GenerateRequest, background_tasks: BackgroundTasks):
|
| 1159 |
-
if req.char_enable and req.char_lora:
|
| 1160 |
-
if not req.char_lora.endswith(".safetensors"):
|
| 1161 |
-
req.char_lora = f"{req.char_lora}.safetensors"
|
| 1162 |
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
|
| 1171 |
-
@app.get("/api/status/{task_id}")
|
| 1172 |
-
async def check_status(task_id: str):
|
| 1173 |
-
status_data = tasks_status.get(task_id, {"status": "not_found"})
|
| 1174 |
-
|
| 1175 |
-
# ๐ ๅช่ฆไปปๅก่ฟๅจๅค็ไธญ๏ผไผๅ
่ฏปๅ็ฉ็ๆไปถ้็ phase
|
| 1176 |
-
if status_data.get("status") == "processing":
|
| 1177 |
-
metric_file = f"/tmp/metrics_{task_id}.json"
|
| 1178 |
-
if os.path.exists(metric_file):
|
| 1179 |
-
try:
|
| 1180 |
-
with open(metric_file, "r") as f:
|
| 1181 |
-
file_data = json.load(f)
|
| 1182 |
-
if "phase" in file_data:
|
| 1183 |
-
status_data["message"] = file_data["phase"]
|
| 1184 |
-
except Exception:
|
| 1185 |
-
pass
|
| 1186 |
-
|
| 1187 |
-
return status_data
|
| 1188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1189 |
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
|
| 1194 |
|
| 1195 |
-
|
| 1196 |
-
|
| 1197 |
-
|
| 1198 |
-
|
| 1199 |
-
|
| 1200 |
-
|
| 1201 |
-
|
| 1202 |
-
|
| 1203 |
-
|
| 1204 |
-
|
| 1205 |
-
|
| 1206 |
-
base_loras_for_engine = []
|
| 1207 |
-
for name, cfg in BASE_LORAS_CHOICES.items():
|
| 1208 |
-
if cfg["engine"] == engine:
|
| 1209 |
-
base_loras_for_engine.append({
|
| 1210 |
-
"name": name,
|
| 1211 |
-
"filename": cfg["filename"],
|
| 1212 |
-
"defaultEnable": cfg.get("defaultEnable", False)
|
| 1213 |
-
})
|
| 1214 |
-
|
| 1215 |
-
engine_cfg = MODEL_CONFIG["models"].get(engine, {})
|
| 1216 |
-
|
| 1217 |
-
# ๐ ๆ ธๅฟ้ป่พ๏ผๅฆๆๆไธๅฑ override ๅฐฑ็จ๏ผๅฆๅ็จๅ
จๅฑ
|
| 1218 |
-
final_prompt = engine_cfg.get("default_prompt_override", global_default_prompt)
|
| 1219 |
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
-
|
| 1224 |
-
"default_prompt": final_prompt # ๐ ็ปไธๅ็ปๅ็ซฏ
|
| 1225 |
}
|
| 1226 |
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
@app.get("/api/loras")
|
| 1230 |
-
async def get_loras():
|
| 1231 |
-
return {"loras": CHAR_LORA_CHOICES}
|
| 1232 |
-
|
| 1233 |
-
@app.get("/api/config")
|
| 1234 |
-
async def get_sampler_config():
|
| 1235 |
-
return {
|
| 1236 |
-
"samplers": SAMPLERS,
|
| 1237 |
-
"schedulers": SCHEDULERS,
|
| 1238 |
-
"root_mapping": MODEL_CONFIG["json_keys"]["root_mapping"], # ๐ ๆ root_mapping ็ดๆฅๅ็ปๅ็ซฏ
|
| 1239 |
-
"default_prompt": MODEL_CONFIG.get("default_prompt", ""),
|
| 1240 |
-
"frontend_url": MODEL_CONFIG.get("frontend_url", "")
|
| 1241 |
-
}
|
| 1242 |
-
|
| 1243 |
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
# ๐ ๅฏๅจ็ญ็ฅ๏ผๅไฟ้ฉๆ่ฝฝๆณ (ๅทฒไฟฎๅค Python 3.12 Event Loop ๅดฉๆบ Bug)
|
| 1251 |
-
# ==========================================================================
|
| 1252 |
-
if __name__ == "__main__":
|
| 1253 |
-
import threading
|
| 1254 |
-
import time
|
| 1255 |
-
import uvicorn
|
| 1256 |
-
|
| 1257 |
-
# ๅ
ณ้ญ SSR ้ฒๅฒ็ช
|
| 1258 |
-
os.environ["GRADIO_SSR_MODE"] = "false"
|
| 1259 |
-
|
| 1260 |
-
# ๐ ็ดๆฅๅฏผๅ
ฅ model_config ้็ๅผๅ
ณ
|
| 1261 |
-
from model_config import ENABLE_GRADIO_UI
|
| 1262 |
-
|
| 1263 |
-
if ENABLE_GRADIO_UI:
|
| 1264 |
-
print("๐ Gradio UI is ENABLED. Mounting UI to root path...")
|
| 1265 |
-
app = mount_gradio_app(
|
| 1266 |
-
app=app,
|
| 1267 |
-
blocks=demo,
|
| 1268 |
-
path="/",
|
| 1269 |
-
)
|
| 1270 |
-
|
| 1271 |
-
def trigger_gpu_scan():
|
| 1272 |
-
demo.launch(
|
| 1273 |
-
server_name="127.0.0.1",
|
| 1274 |
-
server_port=7861,
|
| 1275 |
-
share=False,
|
| 1276 |
-
prevent_thread_lock=True,
|
| 1277 |
-
css=custom_css,
|
| 1278 |
-
)
|
| 1279 |
-
else:
|
| 1280 |
-
print("๐ Gradio UI is DISABLED. Running in pure API mode...")
|
| 1281 |
|
| 1282 |
-
|
| 1283 |
-
|
| 1284 |
-
|
| 1285 |
-
|
| 1286 |
-
|
| 1287 |
-
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
| 1294 |
-
|
| 1295 |
-
|
| 1296 |
-
|
| 1297 |
-
|
| 1298 |
-
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Universal Model Character LoRA Studio - Core</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg-color: #121212;
|
| 10 |
+
--panel-bg: #1e1e1e;
|
| 11 |
+
--text-main: #e0e0e0;
|
| 12 |
+
--text-muted: #888;
|
| 13 |
+
--accent: #FF7F50;
|
| 14 |
+
--border: #444;
|
| 15 |
+
--primary-btn: #2563eb;
|
| 16 |
+
--primary-btn-hover: #1d4ed8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
* { box-sizing: border-box; }
|
| 20 |
+
|
| 21 |
+
body {
|
| 22 |
+
background-color: var(--bg-color);
|
| 23 |
+
color: var(--text-main);
|
| 24 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
| 25 |
+
display: flex;
|
| 26 |
+
justify-content: center;
|
| 27 |
+
align-items: center;
|
| 28 |
+
min-height: 100vh;
|
| 29 |
+
margin: 0;
|
| 30 |
+
padding: 20px;
|
| 31 |
+
line-height: 1.5;
|
| 32 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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{
|
| 35 |
+
background-color: var(--panel-bg);
|
| 36 |
+
border: 1px solid var(--border);
|
| 37 |
+
border-radius: 12px;
|
| 38 |
+
padding: 24px;
|
| 39 |
+
width: 100%;
|
| 40 |
+
max-width: 300px;
|
| 41 |
+
text-align: center;
|
| 42 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
| 43 |
+
}
|
| 44 |
|
| 45 |
+
h1 {
|
| 46 |
+
color: #e0e0e0;
|
| 47 |
+
font-size: 14px;
|
| 48 |
+
font-weight: 500;
|
| 49 |
+
margin-top: 0;
|
| 50 |
+
margin-bottom: 8px;
|
| 51 |
+
text-align: left;
|
| 52 |
+
}
|
| 53 |
|
| 54 |
+
.status-dot {
|
| 55 |
+
display: inline-block;
|
| 56 |
+
width: 8px;
|
| 57 |
+
height: 8px;
|
| 58 |
+
background-color: #00C851;
|
| 59 |
+
border-radius: 50%;
|
| 60 |
+
margin-right: 6px;
|
| 61 |
+
box-shadow: 0 0 10px rgba(0, 200, 81, 0.8);
|
| 62 |
+
animation: breathe-green 2s infinite ease-in-out;
|
| 63 |
+
}
|
| 64 |
|
| 65 |
+
@keyframes breathe-green {
|
| 66 |
+
0%, 100% { opacity: 0.6; box-shadow: 0 0 4px rgba(0, 200, 81, 0.2); }
|
| 67 |
+
50% { opacity: 1; box-shadow: 0 0 12px rgba(0, 200, 81, 1); }
|
| 68 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
p {
|
| 71 |
+
color: var(--text-muted);
|
| 72 |
+
font-size: 11px;
|
| 73 |
+
margin-bottom: 24px;
|
| 74 |
+
font-weight: 400;
|
| 75 |
+
text-align: left;
|
| 76 |
+
}
|
|
|
|
| 77 |
|
| 78 |
+
/* ==========================================
|
| 79 |
+
๐ ๆ็ฎ็ป็ซฏ้ฃ SYSTEM STATUS
|
| 80 |
+
========================================== */
|
| 81 |
+
.sys-status {
|
| 82 |
+
background-color: #121212;
|
| 83 |
+
border: 1px solid #333;
|
| 84 |
+
border-radius: 6px;
|
| 85 |
+
padding: 12px;
|
| 86 |
+
margin-bottom: 20px;
|
| 87 |
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
| 88 |
+
text-align: left;
|
| 89 |
+
}
|
| 90 |
|
| 91 |
+
.sys-status .title {
|
| 92 |
+
font-size: 9px;
|
| 93 |
+
color: var(--text-muted);
|
| 94 |
+
letter-spacing: 1px;
|
| 95 |
+
margin-bottom: 10px;
|
| 96 |
+
text-transform: uppercase;
|
| 97 |
+
border-bottom: 1px dashed #333;
|
| 98 |
+
padding-bottom: 6px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
.sys-row {
|
| 102 |
+
display: flex;
|
| 103 |
+
justify-content: space-between;
|
| 104 |
+
align-items: flex-start;
|
| 105 |
+
font-size: 10px;
|
| 106 |
+
margin-bottom: 6px;
|
| 107 |
+
color: var(--text-muted);
|
| 108 |
+
}
|
| 109 |
|
| 110 |
+
.sys-val {
|
| 111 |
+
color: var(--text-main);
|
| 112 |
+
font-weight: 600;
|
| 113 |
+
}
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
/* ๐ ๆจกๅไธๅฑๅบๅ */
|
| 116 |
+
.sys-models-block {
|
| 117 |
+
margin-top: 8px;
|
| 118 |
+
border-top: 1px dashed #333;
|
| 119 |
+
padding-top: 8px;
|
| 120 |
+
}
|
| 121 |
|
| 122 |
+
.sys-label {
|
| 123 |
+
font-size: 10px;
|
| 124 |
+
color: var(--text-muted);
|
| 125 |
+
margin-bottom: 4px;
|
| 126 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
.sys-models-val {
|
| 129 |
+
font-size: 10px;
|
| 130 |
+
color: var(--text-main);
|
| 131 |
+
font-weight: 600;
|
| 132 |
+
line-height: 1.4;
|
| 133 |
+
word-break: break-word;
|
| 134 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
.btn {
|
| 137 |
+
display: inline-flex;
|
| 138 |
+
align-items: center;
|
| 139 |
+
justify-content: center;
|
| 140 |
+
width: 100%;
|
| 141 |
+
padding: 8px 12px;
|
| 142 |
+
background-color: var(--accent);
|
| 143 |
+
color: white;
|
| 144 |
+
text-decoration: none;
|
| 145 |
+
border-radius: 6px;
|
| 146 |
+
font-weight: 600;
|
| 147 |
+
font-size: 13px;
|
| 148 |
+
transition: background-color 0.2s ease, transform 0.1s ease;
|
| 149 |
+
border: 1px solid transparent;
|
| 150 |
+
}
|
| 151 |
|
| 152 |
+
.btn:hover {
|
| 153 |
+
background-color: rgb(255, 102, 51);
|
| 154 |
+
transform: translateY(-1px);
|
| 155 |
+
}
|
| 156 |
|
| 157 |
+
.footer {
|
| 158 |
+
margin-top: 20px;
|
| 159 |
+
padding-top: 16px;
|
| 160 |
+
border-top: 1px solid var(--border);
|
| 161 |
+
font-size: 11px;
|
| 162 |
+
color: var(--text-muted);
|
| 163 |
+
display: flex;
|
| 164 |
+
justify-content: center;
|
| 165 |
+
gap: 15px;
|
| 166 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
.footer a {
|
| 169 |
+
color: var(--text-muted);
|
| 170 |
+
text-decoration: none;
|
| 171 |
+
transition: color 0.2s;
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
+
.footer a:hover { color: var(--text-main); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
+
</style>
|
| 177 |
+
</head>
|
| 178 |
+
<body>
|
| 179 |
+
<div class="container">
|
| 180 |
+
<h1>Universal Model LoRA Studio - Core</h1>
|
| 181 |
+
<p><span class="status-dot"></span> Backend is Online</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
+
<!-- ๐ ็ป็ซฏ้ฃๆ ผ็ถๆ้ขๆฟ -->
|
| 184 |
+
<div class="sys-status">
|
| 185 |
+
<div class="title">System Status</div>
|
| 186 |
+
|
| 187 |
+
<div class="sys-row">
|
| 188 |
+
<span>Dev Mode</span>
|
| 189 |
+
<span class="sys-val">__DEV_MODE__</span>
|
| 190 |
+
</div>
|
| 191 |
+
<div class="sys-row">
|
| 192 |
+
<span>Gradio UI</span>
|
| 193 |
+
<span class="sys-val">__GRADIO_UI__</span>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<!-- ๐ ๆจกๅๅ่กจไธๅฑๅบๅ๏ผ็ฌ็ซๆ่กๅฑ็คบ -->
|
| 197 |
+
<div class="sys-models-block">
|
| 198 |
+
<div class="sys-label">Models:</div>
|
| 199 |
+
<div class="sys-models-val">[__TARGET_MODEL__]</div>
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
|
| 203 |
+
<!-- ่ทณ่ฝฌๆ้ฎ -->
|
| 204 |
+
<a href="__FRONTEND_URL__" class="btn" target="_blank">Launch Studio UI</a>
|
| 205 |
+
|
| 206 |
+
<!-- ๅบ้จๅฐ้พๆฅ -->
|
| 207 |
+
<div class="footer">
|
| 208 |
+
<a href="https://huggingface.co/spaces/waveshaker/loras_gallery" target="_blank">๐ผ๏ธ Gallery</a>
|
| 209 |
+
<span>โข</span>
|
| 210 |
+
<a href="/docs" target="_blank">๐ API Docs</a>
|
| 211 |
+
</div>
|
| 212 |
+
</div>
|
| 213 |
+
</body>
|
| 214 |
+
</html>
|