MCPcopy Create free account
hub / github.com/SpenserCai/sd-webui-deoldify / deoldify_api

Function deoldify_api

scripts/api.py:24–39  ·  view source on GitHub ↗
(_: gr.Blocks, app: FastAPI)

Source from the content-addressed store, hash-verified

22warnings.filterwarnings("ignore", category=FutureWarning, message="Arguments other than a weight enum or `None`.*?")
23
24def deoldify_api(_: gr.Blocks, app: FastAPI):
25 @app.post("/deoldify/image")
26 async def deoldify_image(
27 input_image: str = Body("",title="image input"),
28 render_factor: int = Body(35,title="render factor"),
29 artistic: bool = Body(False,title="artistic")
30 ):
31 vis = get_image_colorizer(root_folder=Path(paths_internal.models_path),render_factor=render_factor, artistic=artistic)
32 # 判断input_image是否是url
33 if input_image.startswith("http"):
34 img = vis._get_image_from_url(input_image)
35 else:
36 # 把base64转换成图片 PIL.Image
37 img = Image.open(BytesIO(base64.b64decode(input_image)))
38 outImg = vis.get_transformed_image_from_image(img, render_factor=render_factor)
39 return {"image": api.encode_pil_to_base64(outImg).decode("utf-8")}
40
41try:
42 import modules.script_callbacks as script_callbacks

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected