mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
ipadapter optional face autocrop input image
This commit is contained in:
@@ -55,6 +55,7 @@ class Api:
|
||||
self.add_api_route("/sdapi/v1/extra-batch-images", self.extras_batch_images_api, methods=["POST"], response_model=models.ResProcessBatch)
|
||||
self.add_api_route("/sdapi/v1/preprocess", self.process.post_preprocess, methods=["POST"])
|
||||
self.add_api_route("/sdapi/v1/mask", self.process.post_mask, methods=["POST"])
|
||||
self.add_api_route("/sdapi/v1/faces", self.process.post_face, methods=["POST"])
|
||||
|
||||
# api dealing with optional scripts
|
||||
self.add_api_route("/sdapi/v1/scripts", script.get_scripts_list, methods=["GET"], response_model=models.ResScripts)
|
||||
|
||||
@@ -95,7 +95,7 @@ class APIControl():
|
||||
|
||||
def prepare_ip_adapter(self, request):
|
||||
if hasattr(request, "ip_adapter") and request.ip_adapter:
|
||||
args = { 'ip_adapter_names': [], 'ip_adapter_scales': [], 'ip_adapter_starts': [], 'ip_adapter_ends': [], 'ip_adapter_images': [], 'ip_adapter_masks': [] }
|
||||
args = { 'ip_adapter_names': [], 'ip_adapter_scales': [], 'ip_adapter_crops': [], 'ip_adapter_starts': [], 'ip_adapter_ends': [], 'ip_adapter_images': [], 'ip_adapter_masks': [] }
|
||||
for ipadapter in request.ip_adapter:
|
||||
if not ipadapter.images or len(ipadapter.images) == 0:
|
||||
continue
|
||||
|
||||
@@ -64,6 +64,7 @@ class APIGenerate():
|
||||
if hasattr(request, "ip_adapter") and request.ip_adapter:
|
||||
p.ip_adapter_names = []
|
||||
p.ip_adapter_scales = []
|
||||
p.ip_adapter_crops = []
|
||||
p.ip_adapter_starts = []
|
||||
p.ip_adapter_ends = []
|
||||
p.ip_adapter_images = []
|
||||
@@ -72,6 +73,7 @@ class APIGenerate():
|
||||
continue
|
||||
p.ip_adapter_names.append(ipadapter.adapter)
|
||||
p.ip_adapter_scales.append(ipadapter.scale)
|
||||
p.ip_adapter_crops.append(ipadapter.crop)
|
||||
p.ip_adapter_starts.append(ipadapter.start)
|
||||
p.ip_adapter_ends.append(ipadapter.end)
|
||||
p.ip_adapter_images.append([helpers.decode_base64_to_image(x) for x in ipadapter.images])
|
||||
|
||||
@@ -26,6 +26,13 @@ class ReqMask(BaseModel):
|
||||
model: Optional[str] = Field(title="Model", description="The model to use for preprocessing")
|
||||
params: Optional[dict] = Field(default={}, title="Settings", description="Preprocessor settings")
|
||||
|
||||
class ReqFace(BaseModel):
|
||||
image: str = Field(title="Image", description="The base64 encoded image")
|
||||
|
||||
class ResFace(BaseModel):
|
||||
images: List[str] = Field(title="Image", description="The base64 encoded images of detected faces")
|
||||
scores: List[float] = Field(title="Scores", description="The scores of the detected faces")
|
||||
|
||||
class ResMask(BaseModel):
|
||||
mask: str = Field(default='', title="Image", description="The processed image in base64 format")
|
||||
|
||||
@@ -98,3 +105,18 @@ class APIProcess():
|
||||
return JSONResponse(status_code=400, content={"error": "Mask is none"})
|
||||
image = encode_pil_to_base64(processed)
|
||||
return ResMask(mask=image)
|
||||
|
||||
def post_face(self, req: ReqFace):
|
||||
from scripts.face_details import yolo # pylint: disable=no-name-in-module
|
||||
image = decode_base64_to_image(req.image)
|
||||
shared.state.begin('API-FACE', api=True)
|
||||
images = []
|
||||
scores = []
|
||||
with self.queue_lock:
|
||||
yolo.load()
|
||||
faces = yolo.predict(image)
|
||||
for face in faces:
|
||||
images.append(encode_pil_to_base64(face.face))
|
||||
scores.append(face.score)
|
||||
shared.state.end(api=False)
|
||||
return ResFace(images=images, scores=scores)
|
||||
|
||||
Reference in New Issue
Block a user