fill传参

This commit is contained in:
zhxiao 2025-05-06 20:44:11 +08:00
parent 6025cd3d7b
commit 636a09359d
2 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,7 @@ def generate_fill_image(
prompt: str,
prompt_negative: str = "",
input_image_path: str = None,
reference_image_path: str = None,
style_image: str = None,
reference_strength: float = 0.8,
guidance: float = 30.0,
steps: int = 28,
@ -41,7 +41,7 @@ def generate_fill_image(
prompt (str): 正面提示词
prompt_negative (str): 负面提示词
input_image_path (str): 输入图像路径带有透明区域作为填充遮罩
reference_image_path (str): 参考图像路径用于指导填充风格和内容
style_image (str): 参考图像路径用于指导填充风格和内容
reference_strength (float): 参考图像的影响强度0-1之间默认0.8
guidance (float): 引导强度默认30.0
steps (int): 采样步数默认28
@ -113,16 +113,16 @@ def generate_fill_image(
input_filename = f"input_{random.randint(1000, 9999)}.png"
ref_filename = None
if reference_image_path:
if style_image:
ref_filename = f"ref_{random.randint(1000, 9999)}.png"
input_comfy_path = os.path.join(input_dir, input_filename)
shutil.copy(input_image_path, input_comfy_path)
ref_comfy_path = None
if reference_image_path:
if style_image:
ref_comfy_path = os.path.join(input_dir, ref_filename)
shutil.copy(reference_image_path, ref_comfy_path)
shutil.copy(style_image, ref_comfy_path)
# 预加载模型到GPU
from comfy import model_management
@ -153,7 +153,7 @@ def generate_fill_image(
# 如果有参考图像使用StyleModelApplyAdvanced处理
final_positive_cond = get_value_at_index(flux_guided, 0)
if reference_image_path:
if style_image:
try:
# 初始化StyleModelLoader和StyleModelApplyAdvanced节点
stylemodelloader = StyleModelLoader()

View File

@ -638,7 +638,7 @@ async def fill_image(
prompt: str = Form(""),
prompt_negative: str = Form(""),
input_image_path: UploadFile = File(...),
reference_image_path: UploadFile = File(None),
style_image: UploadFile = File(None),
guidance: float = Form(30.0),
steps: int = Form(28),
seed: int = Form(-1) # -1表示随机种子
@ -650,7 +650,7 @@ async def fill_image(
prompt: 正面提示词描述想要生成的内容
prompt_negative: 负面提示词描述想要避免的内容
input_image_path: 输入原始图像
reference_image_path: 参考图像可选
style_image: 参考图像可选
guidance: 引导强度影响图像与提示词的匹配度默认30.0
steps: 采样步数影响生成质量和时间默认28
seed: 随机种子控制生成结果的一致性-1表示随机
@ -668,8 +668,8 @@ async def fill_image(
# 处理参考图像(如果有)
reference_file_path = None
if reference_image_path and reference_image_path.filename:
reference_file_path = save_upload_file_tmp(reference_image_path)
if style_image and style_image.filename:
reference_file_path = save_upload_file_tmp(style_image)
background_tasks.add_task(cleanup_temp_file, reference_file_path)
try:
@ -678,7 +678,7 @@ async def fill_image(
prompt=prompt,
prompt_negative=prompt_negative,
input_image_path=input_file_path,
reference_image_path=reference_file_path,
style_image=reference_file_path,
guidance=guidance,
steps=steps,
seed=seed