mrhan1993 / Fooocus-API

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

Using "Mixing Image Prompt and Inpaint" mode #310

Closed NitishTRI3D closed 2 months ago

NitishTRI3D commented 2 months ago

Is it possible to do this with Fooocus-API? I would want to pass 2 images as image prompts ( ImagePrompt, PyraCanny) And set of images to inpaint or outpaint tab with mask enabled - (original image, mask)

Can someone help with running this example?

mrhan1993 commented 2 months ago

try generation/image-prompt endpoint and mixing_image_prompt_and_inpaint in advanced_params to true

NitishTRI3D commented 2 months ago

Thanks, that is working

""" Examples codes for Fooocus API """ import json import os import base64 import requests

class Config: fooocus_host = 'http://127.0.0.1:8888' img_prompt = '/v2/generation/image-prompt'

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

class ImageList: """ Image List """ beach_bg = read_image("beach_bg.jpg") inpaint_source = read_image('fooocus_input.png') inpaint_mask = read_image('fooocus_mask.png')

def image_prompt(params: dict) -> dict: """ Image Prompt Args: params (dict): Params Returns: dict: Response """ data = json.dumps(params) response = requests.post( url=f"{Config.fooocus_host}{Config.img_prompt}", data=data, timeout=300) return response.json()

alphabake_bgswap_params = { "performance_selection": "Quality", "aspect_ratios_selection": "896*1152", "style_selections" : ["Fooocus V2", "Fooocus Photograph", "Photo Iphone Photographic", "Fooocus Negative"], "input_image": ImageList.inpaint_source, "input_mask": ImageList.inpaint_mask, "mixing_image_prompt_and_inpaint" : True, "image_prompts": [ { "cn_img": ImageList.beach_bg, "cn_stop": 0.8, "cn_weight": 1, "cn_type": "ImagePrompt" }, { "cn_img": ImageList.beach_bg, "cn_stop": 0.5, "cn_weight": 0.3, "cn_type": "PyraCanny" } ], "async_process": False }

face_swap_result = image_prompt(params=alphabake_bgswap_params) print(json.dumps(face_swap_result))

NitishTRI3D commented 2 months ago

Resolved