@@ -199,7 +199,12 @@ def load_lora(pipe_):
199199
200200
201201# 프롬프트/파라미터
202- STYLE_SUFFIX_INIT = "child friendly, storybook, ultra detailed, dreamy cheerful atmosphere, anime style, anime face, soft light, pastel color, soft shading, masterpiece, best quality"
202+ STYLE_SUFFIX_ANIMAL = (
203+ "child friendly, storybook, ultra detailed, dreamy cheerful atmosphere, "
204+ "cute animal illustration, storybook animal art, cartoon animal style, "
205+ "soft light, pastel color, soft shading, masterpiece, best quality"
206+ )
207+ STYLE_SUFFIX_HUMAN = "child friendly, storybook, ultra detailed, dreamy cheerful atmosphere, anime style, anime face, soft light, pastel color, soft shading, masterpiece, best quality"
203208STYLE_SUFFIX_SCN = "child friendly, storybook, ultra detailed, dreamy cheerful atmosphere, anime style, anime face, soft light, pastel color, soft shading, masterpiece, best quality"
204209
205210NEGATIVE_PROMPT = (
@@ -225,10 +230,10 @@ def load_lora(pipe_):
225230}
226231
227232GENRE_PARAMS = {
228- "adventure" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12.5 },
229- "friendship" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12.5 },
230- "moral" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12.5 },
231- "family" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12.5 },
233+ "adventure" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12 },
234+ "friendship" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12 },
235+ "moral" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12 },
236+ "family" : {"controlnet_conditioning_scale" : 0.8 , "guidance_scale" : 12 },
232237}
233238
234239_SCN_SYSTEM = (
@@ -252,10 +257,23 @@ def _select_top_traits(traits, k=3):
252257 return ", " .join ([t .strip () for t in traits if t .strip ()][:k ])
253258
254259def build_character_prompt (name : str , age : int , gender : str , personalities : list , image_description : str ) -> str :
255- gender_short = "male" if gender .lower ().startswith ("m" ) else "female"
260+ gender_lower = gender .lower ()
261+
262+ if gender_lower .startswith ("m" ):
263+ gender_short = "male"
264+ elif gender_lower .startswith ("f" ):
265+ gender_short = "female"
266+ elif gender_lower .startswith ("a" ):
267+ gender_short = "animal"
268+ else :
269+ gender_short = "female"
270+
256271 image_desc_short = build_scene_prompt (image_description .strip ())
257272 core = f"one character only, { gender_short } , { image_desc_short } "
258- prompt = f"{ core } , { STYLE_SUFFIX_INIT } "
273+
274+ style_suffix = STYLE_SUFFIX_ANIMAL if gender_short == "animal" else STYLE_SUFFIX_HUMAN
275+
276+ prompt = f"{ core } , { style_suffix } "
259277 return (prompt [:320 ]).rstrip (", " )
260278
261279def _cleanup_prompt (s : str , max_len : int = 320 ) -> str :
@@ -283,6 +301,8 @@ def _cleanup_prompt(s: str, max_len: int = 320) -> str:
283301
284302def build_scene_prompt (prompt_main : str ) -> str :
285303 try :
304+ print ("[build_scene_prompt] prompt_main:" , repr (prompt_main )) # 입력 확인
305+
286306 resp = client .chat .completions .create (
287307 model = "gpt-4o" ,
288308 temperature = 0.6 ,
@@ -292,20 +312,30 @@ def build_scene_prompt(prompt_main: str) -> str:
292312 ],
293313 timeout = 20 , # seconds
294314 )
315+
316+ print ("[build_scene_prompt] raw resp:" , resp ) # 전체 응답 확인
317+
295318 text = resp .choices [0 ].message .content or ""
319+ print ("[build_scene_prompt] extracted text:" , repr (text )) # 모델이 뱉은 원문
320+
296321 text = _cleanup_prompt (text , max_len = 320 )
322+ print ("[build_scene_prompt] cleaned text:" , repr (text )) # 정제된 프롬프트
297323
298324 if not text :
325+ print ("[build_scene_prompt] cleaned text empty, returning original." )
299326 return prompt_main
327+
328+ print ("[build_scene_prompt] returning final:" , repr (text ))
300329 return text
301330
302- except Exception :
331+ except Exception as e :
332+ print ("[build_scene_prompt] Exception:" , e )
303333 return _cleanup_prompt (prompt_main , max_len = 320 )
304334
305335
306336def width_height ():
307337 if device == "cuda" :
308- return 1024 , 1024
338+ return 768 , 768
309339 elif device == "mps" :
310340 return 768 , 768
311341 raise RuntimeError ("[ERROR] width_height(): CPU path reached" )
@@ -324,6 +354,8 @@ def generate_init_character_image(
324354
325355 sketch_image = Image .open (BytesIO (sketch_bytes )).convert ("RGB" ).resize ((512 , 512 ))
326356 prompt = build_character_prompt (name , age , gender , personalities , image_description )
357+
358+ print ("[prompt]: {prompt}" .format (prompt = prompt ))
327359 width , height = width_height ()
328360
329361 with torch .inference_mode (), amp_autocast ():
@@ -332,7 +364,7 @@ def generate_init_character_image(
332364 negative_prompt = NEGATIVE_PROMPT ,
333365 image = sketch_image ,
334366 num_inference_steps = 50 ,
335- guidance_scale = 12.5 ,
367+ guidance_scale = 12 ,
336368 controlnet_conditioning_scale = 0.8 ,
337369 width = width ,
338370 height = height ,
@@ -351,14 +383,19 @@ def generate_controlnet_image(sketch_bytes: bytes, prompt: str, genre: str) -> s
351383 base_prompt = build_scene_prompt (prompt )
352384
353385 full_prompt , genre_negative , genre_params = compose_prompts (base_prompt , genre )
386+ prompt = f"{ full_prompt } , { STYLE_SUFFIX_HUMAN } "
387+ print ("[prompt]: {prompt}" .format (prompt = prompt ))
388+
354389 negative_prompt = merge_negative_prompt (NEGATIVE_PROMPT , genre_negative )
390+ guidance_scale = genre_params .get ("guidance_scale" )
391+ control_scale = genre_params .get ("controlnet_conditioning_scale" )
392+ print ("[genre]" ,genre )
393+ print ("[genre_param]" ,genre_params )
355394
356- guidance_scale = genre_params .get ("guidance_scale" , 12.5 )
357- control_scale = genre_params .get ("controlnet_conditioning_scale" , 0.8 )
358395
359396 with torch .inference_mode (), amp_autocast ():
360397 result = pipe (
361- prompt = full_prompt ,
398+ prompt = prompt ,
362399 negative_prompt = negative_prompt ,
363400 image = sketch_image ,
364401 num_inference_steps = 50 ,
0 commit comments