Skip to content

Commit

Permalink
Merge pull request #255 from mrhan1993/merge_2.3.0
Browse files Browse the repository at this point in the history
Merge 2.3.0
  • Loading branch information
mrhan1993 committed Mar 21, 2024
2 parents d9869be + 513baa0 commit f5b2f68
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 208 deletions.
73 changes: 32 additions & 41 deletions fooocusapi/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,46 +130,37 @@ def req_to_params(req: Text2ImgRequest) -> ImageGenerationParams:
print(f"[Warning] Wrong inpaint_engine input: {adp.inpaint_engine}, using default")
adp.inpaint_engine = 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.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, \
False, adp.invert_mask_checkbox, adp.inpaint_erode_or_dilate
]

return ImageGenerationParams(prompt=prompt,
negative_prompt=negative_prompt,
style_selections=style_selections,
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,
loras=loras,
uov_input_image=uov_input_image,
uov_method=uov_method,
upscale_value=upscale_value,
outpaint_selections=outpaint_selections,
outpaint_distance_left=outpaint_distance_left,
outpaint_distance_right=outpaint_distance_right,
outpaint_distance_top=outpaint_distance_top,
outpaint_distance_bottom=outpaint_distance_bottom,
inpaint_input_image=inpaint_input_image,
inpaint_additional_prompt=inpaint_additional_prompt,
image_prompts=image_prompts,
advanced_params=advanced_params,
save_extension=req.save_extension,
require_base64=req.require_base64,
)
advanced_params = adp

return ImageGenerationParams(
prompt=prompt,
negative_prompt=negative_prompt,
style_selections=style_selections,
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,
loras=loras,
uov_input_image=uov_input_image,
uov_method=uov_method,
upscale_value=upscale_value,
outpaint_selections=outpaint_selections,
outpaint_distance_left=outpaint_distance_left,
outpaint_distance_right=outpaint_distance_right,
outpaint_distance_top=outpaint_distance_top,
outpaint_distance_bottom=outpaint_distance_bottom,
inpaint_input_image=inpaint_input_image,
inpaint_additional_prompt=inpaint_additional_prompt,
image_prompts=image_prompts,
advanced_params=advanced_params,
save_extension=req.save_extension,
require_base64=req.require_base64,
)


def generate_async_output(task: QueueTask, require_step_preview: bool = False) -> AsyncJobResponse:
Expand Down Expand Up @@ -213,7 +204,7 @@ def generate_image_result_output(results: List[ImageGenerationResult], require_b
results = [GeneratedImageResult(
base64=output_file_to_base64img(item.im) if require_base64 else None,
url=get_file_serve_url(item.im),
seed=item.seed,
seed=str(item.seed),
finish_reason=item.finish_reason) for item in results]
return results

Expand Down
2 changes: 1 addition & 1 deletion fooocusapi/base_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def add_base_args(parser: ArgumentParser, before_prepared: bool):
parser.add_argument("--sync-repo", default=None, help="Sync dependent git repositories to local, 'skip' for skip sync action, 'only' for only do the sync action and not launch app")
parser.add_argument("--skip-pip", default=False, action="store_true", help="Skip automatic pip install when setup")
parser.add_argument("--preload-pipeline", default=False, action="store_true", help="Preload pipeline before start http server")
parser.add_argument("--queue-size", type=int, default=100, help="Working queue size, default: 3, generation requests exceeding working queue size will return failure")
parser.add_argument("--queue-size", type=int, default=100, help="Working queue size, default: 100, generation requests exceeding working queue size will return failure")
parser.add_argument("--queue-history", type=int, default=0, help="Finished jobs reserve size, tasks exceeding the limit will be deleted, including output image files, default: 0, means no limit")
parser.add_argument('--webhook-url', type=str, default=None, help='The URL to send a POST request when a job is finished')
parser.add_argument('--persistent', default=False, action="store_true", help="Store history to db")
Expand Down
21 changes: 12 additions & 9 deletions fooocusapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


class Lora(BaseModel):
enabled: bool
model_name: str
weight: float = Field(default=0.5, ge=-2, le=2)

Expand All @@ -33,7 +34,7 @@ class Lora(BaseModel):


LoraList = TypeAdapter(List[Lora])
default_loras_model = [Lora(model_name=lora[0], weight=lora[1]) for lora in default_loras if lora[0] != 'None']
default_loras_model = [Lora(enabled=lora[0], model_name=lora[1], weight=lora[2]) for lora in default_loras if lora[0] != 'None']
default_loras_json = LoraList.dump_json(default_loras_model)


Expand Down Expand Up @@ -74,15 +75,16 @@ class ImagePrompt(BaseModel):

class AdvancedParams(BaseModel):
disable_preview: bool = Field(False, description="Disable preview during generation")
disable_intermediate_results: bool = Field(False, description="Disable intermediate results")
disable_seed_increment: bool = Field(False, description="Disable Seed Increment")
adm_scaler_positive: float = Field(1.5, description="Positive ADM Guidance Scaler", ge=0.1, le=3.0)
adm_scaler_negative: float = Field(0.8, description="Negative ADM Guidance Scaler", ge=0.1, le=3.0)
adm_scaler_end: float = Field(0.3, description="ADM Guidance End At Step", ge=0.0, le=1.0)
refiner_swap_method: str = Field('joint', description="Refiner swap method")
adaptive_cfg: float = Field(7.0, description="CFG Mimicking from TSNR", ge=1.0, le=30.0)
sampler_name: str = Field(default_sampler, description="Sampler")
scheduler_name: str = Field(default_scheduler, description="Scheduler")
overwrite_step: int = Field(-1, description="Forced Overwrite of Sampling Step", ge=-1, le=200)
overwrite_switch: int = Field(-1, description="Forced Overwrite of Refiner Switch Step", ge=-1, le=200)
overwrite_switch: float = Field(-1, description="Forced Overwrite of Refiner Switch Step", ge=-1, le=1)
overwrite_width: int = Field(-1, description="Forced Overwrite of Generating Width", ge=-1, le=2048)
overwrite_height: int = Field(-1, description="Forced Overwrite of Generating Height", ge=-1, le=2048)
overwrite_vary_strength: float = Field(-1, description='Forced Overwrite of Denoising Strength of "Vary"', ge=-1, le=1.0)
Expand All @@ -91,9 +93,10 @@ class AdvancedParams(BaseModel):
mixing_image_prompt_and_inpaint: bool = Field(False, description="Mixing Image Prompt and Inpaint")
debugging_cn_preprocessor: bool = Field(False, description="Debug Preprocessors")
skipping_cn_preprocessor: bool = Field(False, description="Skip Preprocessors")
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)
refiner_swap_method: str = Field('joint', description="Refiner swap method")
controlnet_softness: float = Field(0.25, description="Softness of ControlNet", ge=0.0, le=1.0)
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")
Expand All @@ -104,6 +107,7 @@ class AdvancedParams(BaseModel):
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)
inpaint_mask_upload_checkbox: bool = Field(False, description="Upload Mask")
invert_mask_checkbox: bool = Field(False, description="Invert Mask")
inpaint_erode_or_dilate: int = Field(0, description="Mask Erode or Dilate", ge=-64, le=64)

Expand All @@ -124,6 +128,7 @@ class Text2ImgRequest(BaseModel):
loras: List[Lora] = Field(default=default_loras_model)
advanced_params: AdvancedParams | None = AdvancedParams()
save_extension: str = Field(default='png', description="Save extension, one of [png, jpg, webp]")
read_wildcards_in_order: bool = Field(default=False, description="Read wildcards in order")
require_base64: bool = Field(default=False, description="Return base64 data of generated image")
async_process: bool = Field(default=False, description="Set to true will run async and return job info for retrieve generataion result later")
webhook_url: str | None = Field(default='', description="Optional URL for a webhook callback. If provided, the system will send a POST request to this URL upon task completion or failure."
Expand Down Expand Up @@ -152,15 +157,13 @@ def lora_parser(loras: str) -> List[Lora]:
raise RequestValidationError(errors=[errs])

def advanced_params_parser(advanced_params: str | None) -> AdvancedParams:
advanced_params_obj = None
if advanced_params is not None and len(advanced_params) > 0:
try:
advanced_params_obj = AdvancedParams.__pydantic_validator__.validate_json(advanced_params)
return advanced_params_obj
except ValidationError as ve:
errs = ve.errors()
raise RequestValidationError(errors=[errs])
return advanced_params_obj
except ValidationError:
return AdvancedParams()
return AdvancedParams()

def oupaint_selections_parser(outpaint_selections: str) -> List[OutpaintExpansion]:
outpaint_selections_arr: List[OutpaintExpansion] = []
Expand Down
4 changes: 2 additions & 2 deletions fooocusapi/repositories_versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

fooocus_version = '2.1.860'
fooocus_version = '2.3.0'
fooocus_commit_hash = os.environ.get(
'FOOOCUS_COMMIT_HASH', "624f74a1ed78ea09467c856cef35aeee0af863f6")
'FOOOCUS_COMMIT_HASH', "e9bc5e50c6a9e9502e822d308cb370883c4ef202")
Loading

0 comments on commit f5b2f68

Please sign in to comment.