Skip to content

Commit

Permalink
Merge for Fooocus v2.1.822
Browse files Browse the repository at this point in the history
  • Loading branch information
konieshadow committed Nov 21, 2023
1 parent 20cbedc commit 0b9af21
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 146 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

FastAPI powered API for [Fooocus](https://github.com/lllyasviel/Fooocus)

Currently loaded Fooocus version: 2.1.820
Currently loaded Fooocus version: 2.1.822

### Run with Replicate
Now you can use Fooocus-API by Replicate, the model is in [konieshadow/fooocus-api](https://replicate.com/konieshadow/fooocus-api).
Expand Down
104 changes: 74 additions & 30 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,6 @@
"description": "Canny High Threshold",
"default": 128
},
"inpaint_engine": {
"type": "string",
"title": "Inpaint Engine",
"description": "Inpaint Engine",
"default": "v1"
},
"freeu_enabled": {
"type": "boolean",
"title": "Freeu Enabled",
Expand Down Expand Up @@ -742,6 +736,40 @@
"title": "Freeu S2",
"description": "FreeU B4",
"default": 0.95
},
"debugging_inpaint_preprocessor": {
"type": "boolean",
"title": "Debugging Inpaint Preprocessor",
"description": "Debug Inpaint Preprocessing",
"default": false
},
"inpaint_disable_initial_latent": {
"type": "boolean",
"title": "Inpaint Disable Initial Latent",
"description": "Disable initial latent in inpaint",
"default": false
},
"inpaint_engine": {
"type": "string",
"title": "Inpaint Engine",
"description": "Inpaint Engine",
"default": "v1"
},
"inpaint_strength": {
"type": "number",
"maximum": 1,
"minimum": 0,
"title": "Inpaint Strength",
"description": "Inpaint Denoising Strength",
"default": 1
},
"inpaint_respective_field": {
"type": "number",
"maximum": 1,
"minimum": 0,
"title": "Inpaint Respective Field",
"description": "Inpaint Respective Field",
"default": 1
}
},
"type": "object",
Expand Down Expand Up @@ -874,6 +902,18 @@
"title": "Input Mask",
"description": "Inpaint or outpaint mask"
},
"inpaint_additional_prompt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Inpaint Additional Prompt",
"description": "Describe what you want to inpaint"
},
"outpaint_selections": {
"items": {
"type": "string"
Expand Down Expand Up @@ -902,7 +942,8 @@
"description": "Fooocus style selections, seperated by comma",
"default": [
"Fooocus V2",
"Fooocus Cinematic"
"Fooocus Enhance",
"Fooocus Sharp"
]
},
"performance_selection": {
Expand Down Expand Up @@ -944,25 +985,25 @@
"maximum": 30,
"minimum": 1,
"title": "Guidance Scale",
"default": 7
"default": 4
},
"base_model_name": {
"type": "string",
"title": "Base Model Name",
"default": "sd_xl_base_1.0_0.9vae.safetensors"
"default": "juggernautXL_version6Rundiffusion.safetensors"
},
"refiner_model_name": {
"type": "string",
"title": "Refiner Model Name",
"default": "sd_xl_refiner_1.0_0.9vae.safetensors"
"default": "None"
},
"refiner_switch": {
"type": "number",
"maximum": 1,
"minimum": 0.1,
"title": "Refiner Switch",
"description": "Refiner Switch At",
"default": 0.667
"default": 0.5
},
"loras": {
"anyOf": [
Expand All @@ -975,7 +1016,7 @@
],
"title": "Loras",
"description": "Lora config in JSON. Format as [{\"model_name\": \"sd_xl_offset_example-lora_1.0.safetensors\", \"weight\": 0.5}]",
"default": "[{\"model_name\":\"sd_xl_offset_example-lora_1.0.safetensors\",\"weight\":0.5}]"
"default": "[{\"model_name\":\"sd_xl_offset_example-lora_1.0.safetensors\",\"weight\":0.1}]"
},
"advanced_params": {
"anyOf": [
Expand Down Expand Up @@ -1201,7 +1242,8 @@
"description": "Fooocus style selections, seperated by comma",
"default": [
"Fooocus V2",
"Fooocus Cinematic"
"Fooocus Enhance",
"Fooocus Sharp"
]
},
"performance_selection": {
Expand Down Expand Up @@ -1243,25 +1285,25 @@
"maximum": 30,
"minimum": 1,
"title": "Guidance Scale",
"default": 7
"default": 4
},
"base_model_name": {
"type": "string",
"title": "Base Model Name",
"default": "sd_xl_base_1.0_0.9vae.safetensors"
"default": "juggernautXL_version6Rundiffusion.safetensors"
},
"refiner_model_name": {
"type": "string",
"title": "Refiner Model Name",
"default": "sd_xl_refiner_1.0_0.9vae.safetensors"
"default": "None"
},
"refiner_switch": {
"type": "number",
"maximum": 1,
"minimum": 0.1,
"title": "Refiner Switch",
"description": "Refiner Switch At",
"default": 0.667
"default": 0.5
},
"loras": {
"anyOf": [
Expand All @@ -1274,7 +1316,7 @@
],
"title": "Loras",
"description": "Lora config in JSON. Format as [{\"model_name\": \"sd_xl_offset_example-lora_1.0.safetensors\", \"weight\": 0.5}]",
"default": "[{\"model_name\":\"sd_xl_offset_example-lora_1.0.safetensors\",\"weight\":0.5}]"
"default": "[{\"model_name\":\"sd_xl_offset_example-lora_1.0.safetensors\",\"weight\":0.1}]"
},
"advanced_params": {
"anyOf": [
Expand Down Expand Up @@ -1334,7 +1376,8 @@
"description": "Fooocus style selections, seperated by comma",
"default": [
"Fooocus V2",
"Fooocus Cinematic"
"Fooocus Enhance",
"Fooocus Sharp"
]
},
"performance_selection": {
Expand Down Expand Up @@ -1376,25 +1419,25 @@
"maximum": 30,
"minimum": 1,
"title": "Guidance Scale",
"default": 7
"default": 4
},
"base_model_name": {
"type": "string",
"title": "Base Model Name",
"default": "sd_xl_base_1.0_0.9vae.safetensors"
"default": "juggernautXL_version6Rundiffusion.safetensors"
},
"refiner_model_name": {
"type": "string",
"title": "Refiner Model Name",
"default": "sd_xl_refiner_1.0_0.9vae.safetensors"
"default": "None"
},
"refiner_switch": {
"type": "number",
"maximum": 1,
"minimum": 0.1,
"title": "Refiner Switch",
"description": "Refiner Switch At",
"default": 0.667
"default": 0.5
},
"loras": {
"anyOf": [
Expand All @@ -1407,7 +1450,7 @@
],
"title": "Loras",
"description": "Lora config in JSON. Format as [{\"model_name\": \"sd_xl_offset_example-lora_1.0.safetensors\", \"weight\": 0.5}]",
"default": "[{\"model_name\":\"sd_xl_offset_example-lora_1.0.safetensors\",\"weight\":0.5}]"
"default": "[{\"model_name\":\"sd_xl_offset_example-lora_1.0.safetensors\",\"weight\":0.1}]"
},
"advanced_params": {
"anyOf": [
Expand Down Expand Up @@ -1616,7 +1659,8 @@
"title": "Style Selections",
"default": [
"Fooocus V2",
"Fooocus Cinematic"
"Fooocus Enhance",
"Fooocus Sharp"
]
},
"performance_selection": {
Expand Down Expand Up @@ -1658,25 +1702,25 @@
"maximum": 30,
"minimum": 1,
"title": "Guidance Scale",
"default": 7
"default": 4
},
"base_model_name": {
"type": "string",
"title": "Base Model Name",
"default": "sd_xl_base_1.0_0.9vae.safetensors"
"default": "juggernautXL_version6Rundiffusion.safetensors"
},
"refiner_model_name": {
"type": "string",
"title": "Refiner Model Name",
"default": "sd_xl_refiner_1.0_0.9vae.safetensors"
"default": "None"
},
"refiner_switch": {
"type": "number",
"maximum": 1,
"minimum": 0.1,
"title": "Refiner Switch",
"description": "Refiner Switch At",
"default": 0.667
"default": 0.5
},
"loras": {
"items": {
Expand All @@ -1687,7 +1731,7 @@
"default": [
{
"model_name": "sd_xl_offset_example-lora_1.0.safetensors",
"weight": 0.5
"weight": 0.1
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion fooocus_api_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.3.16'
version = '0.3.17'
19 changes: 13 additions & 6 deletions fooocusapi/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def req_to_params(req: Text2ImgRequest) -> ImageGenerationParams:
refiner_model_name = 'None'

inpaint_input_image = None
inpaint_additional_prompt = None
if isinstance(req, ImgInpaintOrOutpaintRequest):
inpaint_additional_prompt = req.inpaint_additional_prompt
input_image = read_input_image(req.input_image)
input_mask = None
if req.input_mask is not None:
Expand Down Expand Up @@ -96,12 +98,16 @@ def req_to_params(req: Text2ImgRequest) -> ImageGenerationParams:
print(f"[Warning] Wrong inpaint_engine input: {adp.inpaint_engine}, using default")
adp.inpaint_engine = flags.default_inpaint_engine_version

advanced_params = [adp.disable_preview, adp.adm_scaler_positive, adp.adm_scaler_negative, adp.adm_scaler_end, adp.adaptive_cfg, adp.sampler_name,
adp.scheduler_name, False, adp.overwrite_step, adp.overwrite_switch, adp.overwrite_width, adp.overwrite_height,
adp.overwrite_vary_strength, adp.overwrite_upscale_strength,
adp.mixing_image_prompt_and_vary_upscale, adp.mixing_image_prompt_and_inpaint,
adp.debugging_cn_preprocessor, adp.skipping_cn_preprocessor, adp.controlnet_softness, adp.canny_low_threshold, adp.canny_high_threshold, adp.inpaint_engine,
adp.refiner_swap_method, adp.freeu_enabled, adp.freeu_b1, adp.freeu_b2, adp.freeu_s1, adp.freeu_s2]
advanced_params = [
adp.disable_preview, adp.adm_scaler_positive, adp.adm_scaler_negative, adp.adm_scaler_end, adp.adaptive_cfg, adp.sampler_name, \
adp.scheduler_name, False, adp.overwrite_step, adp.overwrite_switch, adp.overwrite_width, adp.overwrite_height, \
adp.overwrite_vary_strength, adp.overwrite_upscale_strength, \
adp.mixing_image_prompt_and_vary_upscale, adp.mixing_image_prompt_and_inpaint, \
adp.debugging_cn_preprocessor, adp.skipping_cn_preprocessor, adp.controlnet_softness, adp.canny_low_threshold, adp.canny_high_threshold, \
adp.refiner_swap_method, \
adp.freeu_enabled, adp.freeu_b1, adp.freeu_b2, adp.freeu_s1, adp.freeu_s2, \
adp.debugging_inpaint_preprocessor, adp.inpaint_disable_initial_latent, adp.inpaint_engine, adp.inpaint_strength, adp.inpaint_respective_field
]

return ImageGenerationParams(prompt=prompt,
negative_prompt=negative_prompt,
Expand All @@ -120,6 +126,7 @@ def req_to_params(req: Text2ImgRequest) -> ImageGenerationParams:
uov_method=uov_method,
outpaint_selections=outpaint_selections,
inpaint_input_image=inpaint_input_image,
inpaint_additional_prompt=inpaint_additional_prompt,
image_prompts=image_prompts,
advanced_params=advanced_params,
)
Expand Down
10 changes: 8 additions & 2 deletions fooocusapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ class AdvancedParams(BaseModel):
controlnet_softness: float = Field(0.25, description="Softness of ControlNet", ge=0.0, le=1.0)
canny_low_threshold: int = Field(64, description="Canny Low Threshold", ge=1, le=255)
canny_high_threshold: int = Field(128, description="Canny High Threshold", ge=1, le=255)
inpaint_engine: str = Field('v1', description="Inpaint Engine")
freeu_enabled: bool = Field(False, description="FreeU enabled")
freeu_b1: float = Field(1.01, description="FreeU B1")
freeu_b2: float = Field(1.02, description="FreeU B2")
freeu_s1: float = Field(0.99, description="FreeU B3")
freeu_s2: float = Field(0.95, description="FreeU B4")
debugging_inpaint_preprocessor: bool = Field(False, description="Debug Inpaint Preprocessing")
inpaint_disable_initial_latent: bool = Field(False, description="Disable initial latent in inpaint")
inpaint_engine: str = Field('v1', description="Inpaint Engine")
inpaint_strength: float = Field(1.0, description="Inpaint Denoising Strength", ge=0.0, le=1.0)
inpaint_respective_field: float = Field(1.0, description="Inpaint Respective Field", ge=0.0, le=1.0)


class Text2ImgRequest(BaseModel):
Expand Down Expand Up @@ -172,12 +176,14 @@ def as_form(cls, input_image: UploadFile = Form(description="Init image for upsa
class ImgInpaintOrOutpaintRequest(Text2ImgRequest):
input_image: UploadFile
input_mask: UploadFile | None
inpaint_additional_prompt: str | None
outpaint_selections: List[OutpaintExpansion]

@classmethod
def as_form(cls, input_image: UploadFile = Form(description="Init image for inpaint or outpaint"),
input_mask: UploadFile = Form(
File(None), description="Inpaint or outpaint mask"),
inpaint_additional_prompt: str | None = Form(None, description="Describe what you want to inpaint"),
outpaint_selections: List[str] = Form(
[], description="Outpaint expansion selections, literal 'Left', 'Right', 'Top', 'Bottom' seperated by comma"),
prompt: str = Form(''),
Expand Down Expand Up @@ -238,7 +244,7 @@ def as_form(cls, input_image: UploadFile = Form(description="Init image for inpa
errs = ve.errors()
raise RequestValidationError(errors=[errs])

return cls(input_image=input_image, input_mask=input_mask, outpaint_selections=outpaint_selections_arr, prompt=prompt, negative_prompt=negative_prompt, style_selections=style_selection_arr,
return cls(input_image=input_image, input_mask=input_mask, inpaint_additional_prompt=inpaint_additional_prompt, outpaint_selections=outpaint_selections_arr, prompt=prompt, negative_prompt=negative_prompt, style_selections=style_selection_arr,
performance_selection=performance_selection, aspect_ratios_selection=aspect_ratios_selection,
image_number=image_number, image_seed=image_seed, sharpness=sharpness, guidance_scale=guidance_scale,
base_model_name=base_model_name, refiner_model_name=refiner_model_name, refiner_switch=refiner_switch,
Expand Down
Loading

0 comments on commit 0b9af21

Please sign in to comment.