import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
class ChaoShanIPGenerator:
def __init__(self, model_id):
# 加载基础模型
self.pipe = StableDiffusionPipeline.from_pretrained(
model_id,
torch_dtype=torch.float16,
safety_checker=None
)
self.pipe.scheduler = DPMSolverMultistepScheduler.from_config(self.pipe.scheduler.config)
self.pipe.to("cuda")
def generate_yingge_pear(self, prompt_text):
"""
生成英歌舞与水晶梨结合的IP图
"""
# 核心提示词工程:强调半透明材质和英歌舞特征
base_prompt = (
"cute chibi style, chaozhou yingge dance hero, "
"holding wooden sticks, traditional opera makeup, "
"inside a translucent crystal pear, subsurface scattering, "
"sunset beach background, c4d render style, 8k resolution"
)
# 负向提示词:避免生成实体工厂或复杂背景
negative_prompt = "factory, realistic photo, complex background, low quality"
image = self.pipe(
prompt=base_prompt + ", " + prompt_text,
negative_prompt=negative_prompt,
guidance_scale=7.5, # 提高提示词遵循度
num_inference_steps=30
).images[0]
return image
# 实例化并运行
# generator = ChaoShanIPGenerator("your_model_path")
# img = generator.generate_yingge_pear("dynamic pose")