Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement:support api use upscaler #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions scripts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ def get_full_model(model_name):
return model
return None

def get_upscaler(name):
for upscaler in shared.sd_upscalers:
if upscaler.name == name:
return upscaler
return None

def roop_api(_: gr.Blocks, app: FastAPI):
@app.post("/roop/image")
async def roop_image(
source_image: str = Body("",title="source face image"),
target_image: str = Body("",title="target image"),
face_index: list[int] = Body([0],title="face index"),
scale: int = Body(1,title="scale"),
upscaler: str = Body("None", title="Upscaler"),
upscale_visibility: float = Body(1,title="upscale visibility"),
face_restorer: str = Body("None",title="face restorer"),
restorer_visibility: float = Body(1,title="face restorer"),
Expand All @@ -45,20 +52,20 @@ async def roop_image(
s_image = api.decode_base64_to_image(source_image)
t_image = api.decode_base64_to_image(target_image)
f_index = set(face_index)
up_options = UpscaleOptions(scale=scale, upscale_visibility=upscale_visibility,face_restorer=get_face_restorer(face_restorer),restorer_visibility=restorer_visibility)
up_options = UpscaleOptions(scale=scale, upscaler=get_upscaler(upscaler), upscale_visibility=upscale_visibility,face_restorer=get_face_restorer(face_restorer),restorer_visibility=restorer_visibility)
use_model = get_full_model(model)
if use_model is None:
Exception("Model not found")
result = swap_face(s_image, t_image, use_model, f_index, up_options)
return {"image": api.encode_pil_to_base64(result.image())}

@app.get("/roop/models")
async def roop_models():
models = []
for model in get_models():
models.append(model.split("/")[-1])
return {"models": models}

try:
import modules.script_callbacks as script_callbacks

Expand Down