novelai-bot 共享实例整合包

本贴仅作为信息整合手段,如有任何异议请与我联系

原帖:

食用方法,在 novelai 插件中选择 sd-webui,地址填入 http://42.193.147.60:4243/


同时,由于为共享实例,切忌长期占用导致影响他人使用
请确保最大出图尺寸不大于 1024,同时最大迭代步数不超过 64

gpt 写的,不知道写的啥
import threading
import time
import requests
from fastapi import FastAPI, Request
from pydantic import BaseModel
from typing import List
from fastapi.responses import RedirectResponse

app = FastAPI()

backends =[
"http://region-9.seetacloud.com:12558",
"http://region-9.seetacloud.com:17256",
"http://region-9.seetacloud.com:13435",
"http://region-9.seetacloud.com:15672",
"http://region-9.seetacloud.com:19857",
"http://region-9.seetacloud.com:19854",
"http://region-9.seetacloud.com:20095",
"http://region-9.seetacloud.com:17520",
"http://region-9.seetacloud.com:24491",
"http://region-9.seetacloud.com:23321",
"http://region-9.seetacloud.com:28286",
"http://region-9.seetacloud.com:29893",
"http://region-9.seetacloud.com:24626",
"http://region-9.seetacloud.com:29330",
"http://region-9.seetacloud.com:31083",
"http://region-9.seetacloud.com:32467",
"http://region-9.seetacloud.com:21921",
"http://region-9.seetacloud.com:33472",
"http://region-9.seetacloud.com:31398",
"http://region-9.seetacloud.com:38329",
"http://region-9.seetacloud.com:35979",
"http://region-9.seetacloud.com:37661",
"http://region-9.seetacloud.com:44529",
"http://region-9.seetacloud.com:39459",
"http://region-9.seetacloud.com:40383",
"http://region-9.seetacloud.com:54866",
"http://region-8.seetacloud.com:14322",
"http://region-8.seetacloud.com:15759",
"http://region-9.seetacloud.com:43897",
"http://region-8.seetacloud.com:26344",
"http://region-9.seetacloud.com:33392",
"http://region-9.seetacloud.com:52205",
"http://region-8.seetacloud.com:13766",
"http://region-8.seetacloud.com:24469",
"http://region-8.seetacloud.com:15843",
"http://region-8.seetacloud.com:29444",
"http://region-8.seetacloud.com:19542",
"http://region-8.seetacloud.com:23010",
"http://region-8.seetacloud.com:12177",
"http://region-9.seetacloud.com:46056",
"http://region-8.seetacloud.com:25875",
"http://region-8.seetacloud.com:14470",
"http://region-8.seetacloud.com:27472",
"http://region-9.seetacloud.com:50903",
"http://region-8.seetacloud.com:15168",
"http://region-8.seetacloud.com:16654",
"http://region-8.seetacloud.com:15534",
"http://region-8.seetacloud.com:37385",
"http://region-8.seetacloud.com:36363",
"http://region-9.seetacloud.com:30640",
"http://region-8.seetacloud.com:40137",
"http://region-8.seetacloud.com:35920",
"http://region-8.seetacloud.com:35621",
"http://region-8.seetacloud.com:19095",
"http://region-8.seetacloud.com:44119",
"http://region-8.seetacloud.com:30716",
"http://region-8.seetacloud.com:39384",
"http://region-8.seetacloud.com:35202",
"http://region-8.seetacloud.com:43351",
"http://region-8.seetacloud.com:43354",
"http://region-8.seetacloud.com:38546",
"http://region-8.seetacloud.com:33092",
"http://region-8.seetacloud.com:47635",
"http://region-8.seetacloud.com:37654",
"http://region-8.seetacloud.com:35497",
"http://region-8.seetacloud.com:33490",
"http://region-8.seetacloud.com:46326",
"http://region-8.seetacloud.com:14618",
"http://region-8.seetacloud.com:17557",
"http://region-101.seetacloud.com:55957",
"http://region-101.seetacloud.com:55513",
"http://region-8.seetacloud.com:53680",
"http://region-8.seetacloud.com:52328",
"http://region-101.seetacloud.com:42548",
"http://region-8.seetacloud.com:53867",
"http://region-8.seetacloud.com:54333",
"http://region-8.seetacloud.com:52860",
"http://region-101.seetacloud.com:49913",
"http://region-101.seetacloud.com:50623",
"http://region-101.seetacloud.com:53880",
"http://region-101.seetacloud.com:43078",
"http://region-8.seetacloud.com:53918",
"http://region-101.seetacloud.com:46253",
"http://region-101.seetacloud.com:49417",
"http://region-101.seetacloud.com:56148",
"http://region-101.seetacloud.com:44870",
"http://region-101.seetacloud.com:46648",
"http://region-3.seetacloud.com:20762",
"http://region-3.seetacloud.com:24435",
"http://region-3.seetacloud.com:26858",
"http://region-3.seetacloud.com:26777",
"http://region-3.seetacloud.com:20940",
"http://region-3.seetacloud.com:20810",
"http://region-3.seetacloud.com:25001",
"http://region-3.seetacloud.com:26548",
"http://region-3.seetacloud.com:27431",
"http://region-3.seetacloud.com:22389",
"http://region-3.seetacloud.com:13407",
"http://region-3.seetacloud.com:12154",
"http://region-101.seetacloud.com:57309",
"http://region-101.seetacloud.com:57207",
"http://region-3.seetacloud.com:12199",
"http://region-3.seetacloud.com:25913",
"http://region-101.seetacloud.com:53802",
"http://region-3.seetacloud.com:14753",
"http://region-3.seetacloud.com:27505",
"http://region-3.seetacloud.com:24734",
"http://region-3.seetacloud.com:23221",
"http://region-3.seetacloud.com:27008",
"http://region-3.seetacloud.com:22773",
"http://region-3.seetacloud.com:32477",
"http://region-3.seetacloud.com:32847",
"http://region-3.seetacloud.com:23678",
"http://region-3.seetacloud.com:32046",
"http://region-3.seetacloud.com:31768",
"http://region-3.seetacloud.com:27233",
"http://region-3.seetacloud.com:27125",
"http://region-3.seetacloud.com:13533",
"http://region-3.seetacloud.com:34316",
"http://region-3.seetacloud.com:43919",
"http://region-3.seetacloud.com:45105",
"http://region-3.seetacloud.com:44891",
"http://region-3.seetacloud.com:45210",
"http://region-3.seetacloud.com:44187",
"http://region-3.seetacloud.com:43761",
"http://region-3.seetacloud.com:47831",
"http://region-3.seetacloud.com:47531",
"http://region-3.seetacloud.com:46443",
"http://region-3.seetacloud.com:35829",
"http://region-3.seetacloud.com:47708",
"http://region-3.seetacloud.com:46296",
"http://region-3.seetacloud.com:36214",
"http://region-3.seetacloud.com:49723",
"http://region-41.seetacloud.com:16249",
"http://region-3.seetacloud.com:57625",
"http://region-41.seetacloud.com:17322",
"http://region-3.seetacloud.com:57879",
"http://region-41.seetacloud.com:14028",
"http://region-3.seetacloud.com:55941",
"http://region-3.seetacloud.com:57779",
"http://region-3.seetacloud.com:50164",
"http://region-41.seetacloud.com:12029",
"http://region-3.seetacloud.com:51352",
"http://region-41.seetacloud.com:12780",
"http://region-41.seetacloud.com:16530",
"http://region-3.seetacloud.com:51038",
"http://region-3.seetacloud.com:60248",
"http://region-41.seetacloud.com:17924",
"http://region-41.seetacloud.com:15339",
"http://region-3.seetacloud.com:58065",
"http://region-3.seetacloud.com:61616",
"http://region-3.seetacloud.com:60947",
"http://region-3.seetacloud.com:51285",
"http://region-3.seetacloud.com:59402",
"http://region-3.seetacloud.com:36901",
"http://region-3.seetacloud.com:28766",
"http://region-3.seetacloud.com:45461",
"http://region-3.seetacloud.com:27874",
"http://region-41.seetacloud.com:20943",
"http://region-41.seetacloud.com:32538",
"http://region-41.seetacloud.com:20259",
"http://region-3.seetacloud.com:49224",
"http://region-41.seetacloud.com:44176",
"http://region-41.seetacloud.com:34737",
"http://region-41.seetacloud.com:44872",
"http://region-41.seetacloud.com:43685",
"http://region-41.seetacloud.com:47408",
"http://region-41.seetacloud.com:44634",
"http://region-41.seetacloud.com:35722",
"http://region-41.seetacloud.com:46891",
"http://region-41.seetacloud.com:34126",
"http://region-41.seetacloud.com:52550",
"http://region-41.seetacloud.com:52312",
"http://region-41.seetacloud.com:54084",
"http://region-41.seetacloud.com:56006",
"http://region-41.seetacloud.com:56194",
"http://region-41.seetacloud.com:52029",
"http://region-42.seetacloud.com:20933",
"http://region-42.seetacloud.com:25229",
"http://region-42.seetacloud.com:45727",
"http://region-42.seetacloud.com:40874",
"http://region-31.seetacloud.com:26265",
"http://region-42.seetacloud.com:44482",
"http://region-41.seetacloud.com:59617",
"http://region-31.seetacloud.com:28245",
"http://region-42.seetacloud.com:49510",
"http://region-31.seetacloud.com:27953",
"http://region-31.seetacloud.com:28894",
"http://region-31.seetacloud.com:34476",
"http://region-31.seetacloud.com:55617",
"http://region-31.seetacloud.com:23457",
"http://region-31.seetacloud.com:31417",
"http://region-31.seetacloud.com:28150",
"http://region-31.seetacloud.com:52961",
"http://region-31.seetacloud.com:20835",
"http://region-31.seetacloud.com:55770",
"http://region-4.seetacloud.com:36743",
"http://region-4.seetacloud.com:35133",
"http://region-4.seetacloud.com:38561",
"http://region-31.seetacloud.com:56849",
"http://region-4.seetacloud.com:51086",
"http://region-4.seetacloud.com:53622",
"http://region-4.seetacloud.com:50979",
"http://region-31.seetacloud.com:41389",
"http://region-4.seetacloud.com:42100",
"http://region-31.seetacloud.com:45580",
"http://region-31.seetacloud.com:41142",
"http://region-31.seetacloud.com:40040",
"http://region-4.seetacloud.com:41500",
"http://region-4.seetacloud.com:16345",
"http://region-4.seetacloud.com:39542",
"http://region-4.seetacloud.com:46636",
"http://region-4.seetacloud.com:25846",
"http://region-4.seetacloud.com:20840",
"http://region-4.seetacloud.com:48418",
"http://region-4.seetacloud.com:49894",
"http://region-4.seetacloud.com:48732",
"http://region-4.seetacloud.com:49403",
]

healthy_backends = []


async def wildcard_post(request: Request, path: str):
    global healthy_backends
    
    # 提取JSON数据
    data = await request.json()

    # 定义阈值
    max_width = 1200
    max_height = 1200
    max_steps = 95

    # 检查是否超过阈值
    if (
        "width" in data and data["width"] > max_width
        or "height" in data and data["height"] > max_height
        or "steps" in data and data["steps"] > max_steps
    ):
        return "参数过大,共享免费实例,注意公德。", 400

    if not healthy_backends:
        return "No healthy backends available.", 503

    backend = healthy_backends.pop(0)
    healthy_backends.append(backend)

    print(backend)
    target_url = f"{backend}/{path}"
    return RedirectResponse(target_url, status_code=307)



app.add_api_route("/{path:path}", wildcard_post, methods=["POST"])


def health_check(backend):
    health_check_path = "/sdapi/v1/txt2img"
    health_check_url = f"{backend}{health_check_path}"
    health_check_payload = {"prompt": "K", "steps": 1, "width": 64, "height": 64}

    try:
        response = requests.post(health_check_url, json=health_check_payload, timeout=5)
        print(f"Health check for {backend} returned {response.status_code}")
        if response.status_code == 200:
            response_json = response.json()
            if 'images' in response_json and response_json['images'] and response_json['images'][0]:
                return True
    except Exception:
        pass

    return False

def health_check_loop():
    global backends, healthy_backends

    while True:
        for backend in backends:
            is_healthy = health_check(backend)

            if is_healthy and backend not in healthy_backends:
                healthy_backends.append(backend)
            elif not is_healthy and backend in healthy_backends:
                healthy_backends.remove(backend)

        time.sleep(36000)


class BackendStatus(BaseModel):
    available_backends: List[str]
    available_count: int


@app.get("/backend_status", response_model=BackendStatus)
def get_backend_status():
    global healthy_backends
    return BackendStatus(
        available_backends=healthy_backends, available_count=len(healthy_backends)
    )


if __name__ == "__main__":
    health_check_thread = threading.Thread(target=health_check_loop)
    health_check_thread.daemon = True
    health_check_thread.start()

    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=4243)

去开启属于你的盲盒吧

4 个赞

支持正义实例喵

2 个赞

更新了
更新了后端列表,修正了健康检测逻辑

1 个赞

由于上游域名结构改变,此项目失效