(_: gr.Blocks, app: FastAPI)
| 22 | warnings.filterwarnings("ignore", category=FutureWarning, message="Arguments other than a weight enum or `None`.*?") |
| 23 | |
| 24 | def 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 | |
| 41 | try: |
| 42 | import modules.script_callbacks as script_callbacks |
nothing calls this directly
no outgoing calls
no test coverage detected