#๐Ÿ”’ Need help getting REACTOR face swap working on SD (exe pyinstaller) i made

9 messages ยท Page 1 of 1 (latest)

celest cloud
#

Reactor is a face swap tool, i use it to get cleaner faces on images i create, and others create. Currently all the code works pretty good...except face swapping

The code:

def api_change_face(file, face_image, input_model,
                    input_image, processing_unit, source_choice,
                    output_dir):
    ...
    result_path = os.path.join(output_dir, file)   # now it exists

    # โ”€โ”€ headers (same token you use elsewhere) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    headers = {
        "Authorization": API_CONFIG[0]['headers']["Authorization"],
        "accept":        "application/json",
        "Content-Type":  "application/json"
    }

    # โ”€โ”€ device โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    device_choice = "CUDA" if processing_unit.upper().startswith("GPU") else "CPU"

    # โ”€โ”€ encode images โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    with open(input_image, "rb") as f:
        base64_target = base64.b64encode(f.read()).decode()

    if face_image:
        with open(face_image, "rb") as f:
            base64_source = base64.b64encode(f.read()).decode()
    else:
        base64_source = ""

    # โ”€โ”€ where to save the swapped PNG โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    result_path = os.path.join(GENERATED_DIR, file)

    # โ”€โ”€ payload (your original fields retained) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    payload = {
        "face_model":         input_model,          # filename from dropdown
        "source_image":       base64_source,
        "target_image":       base64_target,
        "source_faces_index": [0],
        "face_index":         [0],
        "upscaler":           "None",
        "scale":              1,
        "upscale_visibility": 1,
        "face_restorer":      "CodeFormer",
        "restorer_visibility":0.7,
        "codeformer_weight":  0.6,
        "restore_first":      1,
        "model":              "inswapper_128.onnx",
        "gender_source":      0,
        "gender_target":      0,
        "save_to_file":       1,
        "result_file_path":   result_path,
        "device":             device_choice,
        "select_source":      source_choice
    }

    # โ”€โ”€ call Reactor โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    r = requests.post(
        "http://135.131.174.76:40221/reactor/image",
            headers=headers, json=payload, timeout=120)
    if r.status_code == 200:
        log_message("โœ… Reactor completed OK")
        return result_path
    else:
        log_message(f"โŒ Reactor error {r.status_code}: {r.text}")
        return None

def on_model_selected(selected_model: str) -> None:
    root.face_model_var.set(selected_model)

    if selected_model == "None":
        log_message("โš ๏ธ  Faceโ€‘swap disabled (None selected).")
        return

    if verify_face_model(selected_model):
        log_message(f"โœ… Face model chosen: {selected_model}")
    else:
        log_message(f"โŒ Model verification failed for: {selected_model}")
        root.face_model_var.set("None")

And:

def on_model_selected(selected_model: str) -> None:
    root.face_model_var.set(selected_model)

    if selected_model == "None":
        log_message("โš ๏ธ  Faceโ€‘swap disabled (None selected).")
        return

    if verify_face_model(selected_model):
        log_message(f"โœ… Face model chosen: {selected_model}")
    else:
        log_message(f"โŒ Model verification failed for: {selected_model}")
        root.face_model_var.set("None")

and then finally:

(i cant post the rest, no more room to do so) will post in next message, the generate command doesnt actually swap the face... but it DOES generate the correct image!

tranquil wyvernBOT
#

@celest cloud

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tranquil wyvernBOT
celest cloud
tranquil wyvernBOT
celest cloud
tranquil wyvernBOT
tranquil wyvernBOT
#

@celest cloud

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.