mrhan1993 / Fooocus-API

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

图片重绘功能和图生图一样 #364

Closed git363 closed 4 days ago

git363 commented 1 week ago

图片重绘功能接口2,当指定重绘区域的内容是自己传的图片时,功能失效,结果和图生图一样,传的是啥图生成结果就是啥图,这个是不是接口参数继承导致的?,我看FOOOCUS是可以指定重绘区域图片内容的

mrhan1993 commented 5 days ago

把你的参数和图片、遮罩发来,我看看

git363 commented 4 days ago

需求是把涂抹的区域绘制成指定的图片内容 接口是:/v2/generation/image-inpaint-outpaint 传入参数是: inpaint_additional_prompt:小猫 input_image: 00025-3075121641

input_mask: 077d0d97b4e076894f019c0381622ea3

image_number:1 performance_selection:Speed advanced_params:{ inpaint_disable_initial_latent:true, inpaint_engine:v2.6 inpaint_strength:1.0 inpaint_respective_field:0, mixing_image_prompt_and_inpaint:1 } image_prompts:[{"cn_type":"ImagePrompt","cn_weight":"1","cn_stop":"0.5","cn_img":" ads_real_estate "}] 生成结果是 18a3dbd7-760c-40a8-8a8f-2beb16e90074 预期结果是: 希望涂抹的区域生成指定的图片内容,类似于电商把指定的服装替换到指定模特儿身上 不知道是不是我这边参数没有传对,反复看文档没有找出原因来,望大佬测试一下,感谢

mrhan1993 commented 4 days ago
"""
Examples codes for Fooocus API
"""
import json
import base64
import requests

class Config:
    """
    Config
    Attributes:
        fooocus_host (str): Fooocus API host
        text2img_ip (str): Text to Image with IP
        img_upscale (str): Upscale or Vary
        inpaint_outpaint (str): Inpaint or Outpaint
        img_prompt (str): Image Prompt
    """
    fooocus_host = 'http://127.0.0.1:8888'

    text2img_ip = '/v2/generation/text-to-image-with-ip'
    img_upscale = '/v2/generation/image-upscale-vary'
    inpaint_outpaint = '/v2/generation/image-inpaint-outpaint'
    img_prompt = '/v2/generation/image-prompt'

def read_image(path: str) -> str:
    """
    Read image from file
    Args:
        image_name (str): Image file name
    Returns:
        str: Image base64
    """
    with open(path, "rb") as f:
        image = f.read()
        f.close()
    return base64.b64encode(image).decode('utf-8')

def inpaint_outpaint(params: dict = None) -> dict:
    """
    Inpaint or Outpaint
    Args:
        params (dict): Params
    Returns:
        dict: Response
    """
    data = json.dumps(params)
    response = requests.post(
        url=f"{Config.fooocus_host}{Config.inpaint_outpaint}",
        data=data,
        timeout=300)
    return response.json()

t2i_ip_params = {
    "prompt": "a cat",
    "inpaint_additional_prompt": "a little cat",
    "performance_selection": "Speed",
    "input_image": read_image(r"C:\Users\LiveR\Desktop\343151766-1a6fdd49-e194-4a49-baed-94d4b60e0dde.png"),
    "input_mask": read_image(r"C:\Users\LiveR\Desktop\343152398-7991ceb2-efbb-49e2-ac99-f4fb961d8731.png"),
    "advanced_params": {
        "inpaint_disable_initial_latent": True,
        "inpaint_engine": "v2.6",
        "inpaint_strength": 1.0,
        "inpaint_respective_field": 0,
        "mixing_image_prompt_and_inpaint": True
        },
    "image_prompts": [
        {
            "cn_img": read_image(r"C:\Users\LiveR\Desktop\343153293-04b4cb03-a815-466c-b027-3d817cfad257.png"),
            "cn_stop": 0.5,
            "cn_weight": 1,
            "cn_type": "ImagePrompt"
        }
    ],
    "async_process": False
}

if __name__ == '__main__':
    response = inpaint_outpaint(params=t2i_ip_params)

大概是因为你的 mixing_image_prompt_and_inpaint:1 是错的,应该是 True

bbc31c9b-2cc4-464a-ac60-a598bd56ef29-0

git363 commented 4 days ago

非常感谢,我反复测试了一下,是可以的 确实是参数没有传对