mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
558 stars 148 forks source link

Image Upscale v1 & v2 not working #89

Closed mathone1 closed 8 months ago

mathone1 commented 8 months ago

To begin, I want to thank you for creating this excellent project.

I noticed that the "input_image" field is ignored when requesting the following routes:

For example, using the following code:

def encode_file_to_base64(file_path):
    with open(file_path, "rb") as file:
        return base64.b64encode(file.read()).decode()

def send_post_request(encoded_image):
    url = "http://127.0.0.1:8888/v2/generation/image-prompt"
    payload = {
        "prompt": "",
        "negative_prompt": "unrealistic, saturated, high contrast, big nose, painting, drawing, sketch, cartoon, anime, manga, render, CG, 3d, watermark, signature, label",
        "style_selections": [
            "Fooocus V2",
            "Fooocus Photograph",
            "Fooocus Negative"
        ],
        "performance_selection": "Quality",
        "aspect_ratios_selection": "1664×2432",
        "image_number": 2,
        "image_seed": -1,
        "sharpness": 4,
        "guidance_scale": 4,
        "base_model_name": "realisticStockPhoto_v10.safetensors",
        "refiner_model_name": "None",
        "refiner_switch": 0.5,
        "loras": [],
        "advanced_params": {
            "disable_preview": True,
            "adm_scaler_positive": 1.5,
            "adm_scaler_negative": 0.8,
            "adm_scaler_end": 0.3,
            "refiner_swap_method": "joint",
            "adaptive_cfg": 7,
            "sampler_name": "dpmpp_2m_sde_gpu",
            "scheduler_name": "karras",
            "overwrite_step": -1,
            "overwrite_switch": -1,
            "overwrite_width": -1,
            "overwrite_height": -1,
            "overwrite_vary_strength": -1,
            "overwrite_upscale_strength": -1,
            "mixing_image_prompt_and_vary_upscale": False,
            "mixing_image_prompt_and_inpaint": False,
            "debugging_cn_preprocessor": False,
            "skipping_cn_preprocessor": False,
            "controlnet_softness": 0.25,
            "canny_low_threshold": 64,
            "canny_high_threshold": 128,
            "freeu_enabled": False,
            "freeu_b1": 1.01,
            "freeu_b2": 1.02,
            "freeu_s1": 0.99,
            "freeu_s2": 0.95,
            "debugging_inpaint_preprocessor": False,
            "inpaint_disable_initial_latent": False,
            "inpaint_engine": "v1",
            "inpaint_strength": 1,
            "inpaint_respective_field": 1
        },
        "require_base64": False,
        "async_process": False,
        "uov_method": "Upscale (2x)",
        "upscale_value": 2,
        "image_prompts": [],
        "input_image": encoded_image
    }
    response = requests.post(url, json=payload)
    return response.json()

encoded_image = encode_file_to_base64(image_path)
response = send_post_request(encoded_image)

An "upscale" occurs but it generates an image from a camera instead of the one provided

konieshadow commented 8 months ago

You cant't using "Upscale (or Vary)" and "Image Prompt" with single request with this api. You can think it was designed to separate for different main purposes. So you can request "Upscale" api after doing "Image Prompt".

mathone1 commented 8 months ago

Thank you for your prompt response.

Indeed, the URL was not the right one, it was my fault.