|
16 | 16 | from fastapi.encoders import jsonable_encoder
|
17 | 17 | from secrets import compare_digest
|
18 | 18 |
|
19 |
| -from modules import initialize |
20 |
| -initialize.imports() |
21 |
| - |
22 | 19 | import modules.shared as shared
|
23 | 20 | from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, postprocessing, errors, restart, shared_items
|
24 | 21 | from modules.api import models
|
|
36 | 33 | import piexif
|
37 | 34 | import piexif.helper
|
38 | 35 | from contextlib import closing
|
39 |
| -from ray import serve |
40 | 36 |
|
41 |
| -app = FastAPI() |
42 | 37 |
|
43 | 38 | def script_name_to_index(name, scripts):
|
44 | 39 | try:
|
@@ -202,29 +197,18 @@ async def http_exception_handler(request: Request, e: HTTPException):
|
202 | 197 | return handle_exception(request, e)
|
203 | 198 |
|
204 | 199 |
|
205 |
| -api_middleware(app) |
206 |
| - |
207 |
| - |
208 |
| -@serve.deployment( |
209 |
| - ray_actor_options={"num_gpus": 1}, |
210 |
| - autoscaling_config={"min_replicas": 0, "max_replicas": 2}, |
211 |
| - #route_prefix="/sdapi/v1", |
212 |
| - ) |
213 |
| -@serve.ingress(app) |
214 | 200 | class Api:
|
215 |
| - def __init__(self): |
216 |
| - initialize.initialize() |
| 201 | + def __init__(self, app: FastAPI, queue_lock: Lock): |
217 | 202 | if shared.cmd_opts.api_auth:
|
218 | 203 | self.credentials = {}
|
219 | 204 | for auth in shared.cmd_opts.api_auth.split(","):
|
220 | 205 | user, password = auth.split(":")
|
221 | 206 | self.credentials[user] = password
|
222 | 207 |
|
223 | 208 | self.router = APIRouter()
|
224 |
| - |
225 |
| - |
226 |
| - |
227 |
| - print("API initialized") |
| 209 | + self.app = app |
| 210 | + self.queue_lock = queue_lock |
| 211 | + api_middleware(self.app) |
228 | 212 | self.add_api_route("/sdapi/v1/txt2img", self.text2imgapi, methods=["POST"], response_model=models.TextToImageResponse)
|
229 | 213 | self.add_api_route("/sdapi/v1/img2img", self.img2imgapi, methods=["POST"], response_model=models.ImageToImageResponse)
|
230 | 214 | self.add_api_route("/sdapi/v1/extra-single-image", self.extras_single_image_api, methods=["POST"], response_model=models.ExtrasSingleImageResponse)
|
@@ -268,7 +252,6 @@ def __init__(self):
|
268 | 252 | self.default_script_arg_txt2img = []
|
269 | 253 | self.default_script_arg_img2img = []
|
270 | 254 |
|
271 |
| - |
272 | 255 | def add_api_route(self, path: str, endpoint, **kwargs):
|
273 | 256 | if shared.cmd_opts.api_auth:
|
274 | 257 | return self.app.add_api_route(path, endpoint, dependencies=[Depends(self.auth)], **kwargs)
|
@@ -802,4 +785,3 @@ def restart_webui(self):
|
802 | 785 | def stop_webui(request):
|
803 | 786 | shared.state.server_command = "stop"
|
804 | 787 | return Response("Stopping.")
|
805 |
| - |
0 commit comments