Skip to content

Commit f5b2f68

Browse files
authored
Merge pull request #255 from mrhan1993/merge_2.3.0
Merge 2.3.0
2 parents d9869be + 513baa0 commit f5b2f68

7 files changed

+236
-208
lines changed

fooocusapi/api_utils.py

+32-41
Original file line numberDiff line numberDiff line change
@@ -130,46 +130,37 @@ def req_to_params(req: Text2ImgRequest) -> ImageGenerationParams:
130130
print(f"[Warning] Wrong inpaint_engine input: {adp.inpaint_engine}, using default")
131131
adp.inpaint_engine = default_inpaint_engine_version
132132

133-
advanced_params = [
134-
adp.disable_preview, adp.adm_scaler_positive, adp.adm_scaler_negative, adp.adm_scaler_end, adp.adaptive_cfg, adp.sampler_name, \
135-
adp.scheduler_name, False, adp.overwrite_step, adp.overwrite_switch, adp.overwrite_width, adp.overwrite_height, \
136-
adp.overwrite_vary_strength, adp.overwrite_upscale_strength, \
137-
adp.mixing_image_prompt_and_vary_upscale, adp.mixing_image_prompt_and_inpaint, \
138-
adp.debugging_cn_preprocessor, adp.skipping_cn_preprocessor, adp.controlnet_softness, adp.canny_low_threshold, adp.canny_high_threshold, \
139-
adp.refiner_swap_method, \
140-
adp.freeu_enabled, adp.freeu_b1, adp.freeu_b2, adp.freeu_s1, adp.freeu_s2, \
141-
adp.debugging_inpaint_preprocessor, adp.inpaint_disable_initial_latent, adp.inpaint_engine, adp.inpaint_strength, adp.inpaint_respective_field, \
142-
False, adp.invert_mask_checkbox, adp.inpaint_erode_or_dilate
143-
]
144-
145-
return ImageGenerationParams(prompt=prompt,
146-
negative_prompt=negative_prompt,
147-
style_selections=style_selections,
148-
performance_selection=performance_selection,
149-
aspect_ratios_selection=aspect_ratios_selection,
150-
image_number=image_number,
151-
image_seed=image_seed,
152-
sharpness=sharpness,
153-
guidance_scale=guidance_scale,
154-
base_model_name=base_model_name,
155-
refiner_model_name=refiner_model_name,
156-
refiner_switch=refiner_switch,
157-
loras=loras,
158-
uov_input_image=uov_input_image,
159-
uov_method=uov_method,
160-
upscale_value=upscale_value,
161-
outpaint_selections=outpaint_selections,
162-
outpaint_distance_left=outpaint_distance_left,
163-
outpaint_distance_right=outpaint_distance_right,
164-
outpaint_distance_top=outpaint_distance_top,
165-
outpaint_distance_bottom=outpaint_distance_bottom,
166-
inpaint_input_image=inpaint_input_image,
167-
inpaint_additional_prompt=inpaint_additional_prompt,
168-
image_prompts=image_prompts,
169-
advanced_params=advanced_params,
170-
save_extension=req.save_extension,
171-
require_base64=req.require_base64,
172-
)
133+
advanced_params = adp
134+
135+
return ImageGenerationParams(
136+
prompt=prompt,
137+
negative_prompt=negative_prompt,
138+
style_selections=style_selections,
139+
performance_selection=performance_selection,
140+
aspect_ratios_selection=aspect_ratios_selection,
141+
image_number=image_number,
142+
image_seed=image_seed,
143+
sharpness=sharpness,
144+
guidance_scale=guidance_scale,
145+
base_model_name=base_model_name,
146+
refiner_model_name=refiner_model_name,
147+
refiner_switch=refiner_switch,
148+
loras=loras,
149+
uov_input_image=uov_input_image,
150+
uov_method=uov_method,
151+
upscale_value=upscale_value,
152+
outpaint_selections=outpaint_selections,
153+
outpaint_distance_left=outpaint_distance_left,
154+
outpaint_distance_right=outpaint_distance_right,
155+
outpaint_distance_top=outpaint_distance_top,
156+
outpaint_distance_bottom=outpaint_distance_bottom,
157+
inpaint_input_image=inpaint_input_image,
158+
inpaint_additional_prompt=inpaint_additional_prompt,
159+
image_prompts=image_prompts,
160+
advanced_params=advanced_params,
161+
save_extension=req.save_extension,
162+
require_base64=req.require_base64,
163+
)
173164

174165

175166
def generate_async_output(task: QueueTask, require_step_preview: bool = False) -> AsyncJobResponse:
@@ -213,7 +204,7 @@ def generate_image_result_output(results: List[ImageGenerationResult], require_b
213204
results = [GeneratedImageResult(
214205
base64=output_file_to_base64img(item.im) if require_base64 else None,
215206
url=get_file_serve_url(item.im),
216-
seed=item.seed,
207+
seed=str(item.seed),
217208
finish_reason=item.finish_reason) for item in results]
218209
return results
219210

fooocusapi/base_args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def add_base_args(parser: ArgumentParser, before_prepared: bool):
1111
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")
1212
parser.add_argument("--skip-pip", default=False, action="store_true", help="Skip automatic pip install when setup")
1313
parser.add_argument("--preload-pipeline", default=False, action="store_true", help="Preload pipeline before start http server")
14-
parser.add_argument("--queue-size", type=int, default=100, help="Working queue size, default: 3, generation requests exceeding working queue size will return failure")
14+
parser.add_argument("--queue-size", type=int, default=100, help="Working queue size, default: 100, generation requests exceeding working queue size will return failure")
1515
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")
1616
parser.add_argument('--webhook-url', type=str, default=None, help='The URL to send a POST request when a job is finished')
1717
parser.add_argument('--persistent', default=False, action="store_true", help="Store history to db")

fooocusapi/models.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525

2626
class Lora(BaseModel):
27+
enabled: bool
2728
model_name: str
2829
weight: float = Field(default=0.5, ge=-2, le=2)
2930

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

3435

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

3940

@@ -74,15 +75,16 @@ class ImagePrompt(BaseModel):
7475

7576
class AdvancedParams(BaseModel):
7677
disable_preview: bool = Field(False, description="Disable preview during generation")
78+
disable_intermediate_results: bool = Field(False, description="Disable intermediate results")
79+
disable_seed_increment: bool = Field(False, description="Disable Seed Increment")
7780
adm_scaler_positive: float = Field(1.5, description="Positive ADM Guidance Scaler", ge=0.1, le=3.0)
7881
adm_scaler_negative: float = Field(0.8, description="Negative ADM Guidance Scaler", ge=0.1, le=3.0)
7982
adm_scaler_end: float = Field(0.3, description="ADM Guidance End At Step", ge=0.0, le=1.0)
80-
refiner_swap_method: str = Field('joint', description="Refiner swap method")
8183
adaptive_cfg: float = Field(7.0, description="CFG Mimicking from TSNR", ge=1.0, le=30.0)
8284
sampler_name: str = Field(default_sampler, description="Sampler")
8385
scheduler_name: str = Field(default_scheduler, description="Scheduler")
8486
overwrite_step: int = Field(-1, description="Forced Overwrite of Sampling Step", ge=-1, le=200)
85-
overwrite_switch: int = Field(-1, description="Forced Overwrite of Refiner Switch Step", ge=-1, le=200)
87+
overwrite_switch: float = Field(-1, description="Forced Overwrite of Refiner Switch Step", ge=-1, le=1)
8688
overwrite_width: int = Field(-1, description="Forced Overwrite of Generating Width", ge=-1, le=2048)
8789
overwrite_height: int = Field(-1, description="Forced Overwrite of Generating Height", ge=-1, le=2048)
8890
overwrite_vary_strength: float = Field(-1, description='Forced Overwrite of Denoising Strength of "Vary"', ge=-1, le=1.0)
@@ -91,9 +93,10 @@ class AdvancedParams(BaseModel):
9193
mixing_image_prompt_and_inpaint: bool = Field(False, description="Mixing Image Prompt and Inpaint")
9294
debugging_cn_preprocessor: bool = Field(False, description="Debug Preprocessors")
9395
skipping_cn_preprocessor: bool = Field(False, description="Skip Preprocessors")
94-
controlnet_softness: float = Field(0.25, description="Softness of ControlNet", ge=0.0, le=1.0)
9596
canny_low_threshold: int = Field(64, description="Canny Low Threshold", ge=1, le=255)
9697
canny_high_threshold: int = Field(128, description="Canny High Threshold", ge=1, le=255)
98+
refiner_swap_method: str = Field('joint', description="Refiner swap method")
99+
controlnet_softness: float = Field(0.25, description="Softness of ControlNet", ge=0.0, le=1.0)
97100
freeu_enabled: bool = Field(False, description="FreeU enabled")
98101
freeu_b1: float = Field(1.01, description="FreeU B1")
99102
freeu_b2: float = Field(1.02, description="FreeU B2")
@@ -104,6 +107,7 @@ class AdvancedParams(BaseModel):
104107
inpaint_engine: str = Field('v1', description="Inpaint Engine")
105108
inpaint_strength: float = Field(1.0, description="Inpaint Denoising Strength", ge=0.0, le=1.0)
106109
inpaint_respective_field: float = Field(1.0, description="Inpaint Respective Field", ge=0.0, le=1.0)
110+
inpaint_mask_upload_checkbox: bool = Field(False, description="Upload Mask")
107111
invert_mask_checkbox: bool = Field(False, description="Invert Mask")
108112
inpaint_erode_or_dilate: int = Field(0, description="Mask Erode or Dilate", ge=-64, le=64)
109113

@@ -124,6 +128,7 @@ class Text2ImgRequest(BaseModel):
124128
loras: List[Lora] = Field(default=default_loras_model)
125129
advanced_params: AdvancedParams | None = AdvancedParams()
126130
save_extension: str = Field(default='png', description="Save extension, one of [png, jpg, webp]")
131+
read_wildcards_in_order: bool = Field(default=False, description="Read wildcards in order")
127132
require_base64: bool = Field(default=False, description="Return base64 data of generated image")
128133
async_process: bool = Field(default=False, description="Set to true will run async and return job info for retrieve generataion result later")
129134
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."
@@ -152,15 +157,13 @@ def lora_parser(loras: str) -> List[Lora]:
152157
raise RequestValidationError(errors=[errs])
153158

154159
def advanced_params_parser(advanced_params: str | None) -> AdvancedParams:
155-
advanced_params_obj = None
156160
if advanced_params is not None and len(advanced_params) > 0:
157161
try:
158162
advanced_params_obj = AdvancedParams.__pydantic_validator__.validate_json(advanced_params)
159163
return advanced_params_obj
160-
except ValidationError as ve:
161-
errs = ve.errors()
162-
raise RequestValidationError(errors=[errs])
163-
return advanced_params_obj
164+
except ValidationError:
165+
return AdvancedParams()
166+
return AdvancedParams()
164167

165168
def oupaint_selections_parser(outpaint_selections: str) -> List[OutpaintExpansion]:
166169
outpaint_selections_arr: List[OutpaintExpansion] = []

fooocusapi/repositories_versions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
22

3-
fooocus_version = '2.1.860'
3+
fooocus_version = '2.3.0'
44
fooocus_commit_hash = os.environ.get(
5-
'FOOOCUS_COMMIT_HASH', "624f74a1ed78ea09467c856cef35aeee0af863f6")
5+
'FOOOCUS_COMMIT_HASH', "e9bc5e50c6a9e9502e822d308cb370883c4ef202")

0 commit comments

Comments
 (0)