Kims12 commited on
Commit
969f915
ยท
verified ยท
1 Parent(s): 3be7e95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +172 -154
app.py CHANGED
@@ -224,104 +224,129 @@ def process_images_with_prompt(image1, image2, image3, prompt, bg_options=None):
224
  logger.exception("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
225
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
226
 
227
- def update_preview(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
228
- preview = f"์ƒํ’ˆ๋ช…: {product_name}\n"
229
- preview += f"์ œํ’ˆ๊ตฐ: {product_category}\n"
230
- preview += f"๋ฐฐ๊ฒฝ ์œ ํ˜•: {background_type}\n"
231
- preview += f"์„ธ๋ถ€ ์Šคํƒ€์ผ: {background_style}\n"
232
-
233
- if lighting:
234
- preview += f"์กฐ๋ช…: {lighting}\n"
235
- if texture and texture != "์„ ํƒ ์•ˆํ•จ":
236
- preview += f"๋ฐฐ๊ฒฝ ์งˆ๊ฐ: {texture}\n"
237
- if color_tone and color_tone != "์„ ํƒ ์•ˆํ•จ":
238
- preview += f"์ƒ‰๊ฐ: {color_tone}\n"
239
- if mood and mood != "์„ ํƒ ์•ˆํ•จ":
240
- preview += f"๋ถ„์œ„๊ธฐ: {mood}\n"
241
-
242
- # ์„ ํƒ ์‚ฌํ•ญ์„ ๊ธฐ๋ฐ˜์œผ๋กœ LLM ์Šคํƒ€์ผ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
243
- llm_prompt = generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood)
244
-
245
- preview += f"\n์ƒ์„ฑ๋œ LLM ํ”„๋กฌํ”„ํŠธ:\n{llm_prompt}"
246
-
247
- return preview, llm_prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  # LLM ์Šคํƒ€์ผ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ•จ์ˆ˜
250
  def generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
251
  # ๊ธฐ๋ณธ ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ
252
- prompt = f"{product_name}์„(๋ฅผ) "
253
 
254
  # ๋ฐฐ๊ฒฝ ์œ ํ˜• ๋ฐ ์Šคํƒ€์ผ ์ถ”๊ฐ€
255
  if background_type == "์ž์—ฐ ๋ฐฐ๊ฒฝ":
256
  if background_style == "์ˆฒ":
257
- prompt += "์šธ์ฐฝํ•œ ์ˆฒ์†์˜ ์ž์—ฐ ํ™˜๊ฒฝ์— "
258
  elif background_style == "ํ•ด๋ณ€":
259
- prompt += "์ฒญ๋Ÿ‰ํ•œ ํ•ด๋ณ€๊ฐ€์˜ ๋ชจ๋ž˜ ์œ„์— "
260
  elif background_style == "์‚ฐ":
261
- prompt += "์›…์žฅํ•œ ์‚ฐ์˜ ์ •์ƒ์—์„œ ๋ง‘์€ ํ•˜๋Š˜์„ ๋ฐฐ๊ฒฝ์œผ๋กœ "
262
  elif background_style == "๋“คํŒ":
263
- prompt += "๋„“๊ฒŒ ํŽผ์ณ์ง„ ์ดˆ์› ์œ„์— "
264
  elif background_style == "๊ณ„๊ณก":
265
- prompt += "์‹œ์›ํ•œ ๊ณ„๊ณก๋ฌผ์ด ํ๋ฅด๋Š” ๋ฐ”์œ„ ์œ„์— "
266
  elif background_style == "์—ด๋Œ€ ์ •์›":
267
- prompt += "์ƒ๋™๊ฐ ๋„˜์น˜๋Š” ์—ด๋Œ€ ์‹๋ฌผ๋กœ ๋‘˜๋Ÿฌ์‹ธ์ธ ๊ณต๊ฐ„์— "
268
  elif background_style == "์‚ฌ๋ง‰":
269
- prompt += "๋์—†์ด ํŽผ์ณ์ง„ ํ™ฉ๊ธˆ๋น› ์‚ฌ๋ง‰ ์œ„์— "
270
  elif background_style == "๋ˆˆ ํ’๊ฒฝ":
271
- prompt += "ํ•˜์–€ ๋ˆˆ์œผ๋กœ ๋ฎ์ธ ์ˆœ๋ฐฑ์˜ ํ’๊ฒฝ ์œ„์— "
272
  else:
273
- prompt += f"{background_style} ์ž์—ฐ ํ™˜๊ฒฝ ์†์— "
274
  elif background_type == "์‹ค๋‚ด ๋ฐฐ๊ฒฝ":
275
  if background_style == "๊ฑฐ์‹ค":
276
- prompt += "๋ชจ๋˜ํ•˜๊ณ  ์„ธ๋ จ๋œ ๊ฑฐ์‹ค ๊ณต๊ฐ„์˜ ํ…Œ์ด๋ธ” ์œ„์— "
277
  elif background_style == "์ฃผ๋ฐฉ":
278
- prompt += "๊น”๋”ํ•œ ์ฃผ๋ฐฉ ์นด์šดํ„ฐ ์œ„์— "
279
  elif background_style == "์„œ์žฌ":
280
- prompt += "์ง€์ ์ธ ๋ถ„์œ„๊ธฐ์˜ ์„œ์žฌ ์ฑ…์ƒ ์œ„์— "
281
  elif background_style == "ํ™”์žฅ๋Œ€":
282
- prompt += "์„ธ๋ จ๋œ ํ™”์žฅ๋Œ€ ์œ„์— "
283
  elif background_style == "ํ˜ธํ…” ๋กœ๋น„":
284
- prompt += "๊ณ ๊ธ‰์Šค๋Ÿฌ์šด ํ˜ธํ…” ๋กœ๋น„์˜ ๋Œ€๋ฆฌ์„ ํ…Œ์ด๋ธ” ์œ„์— "
285
  elif background_style == "์นดํŽ˜":
286
- prompt += "๊ฐ์„ฑ์ ์ธ ์นดํŽ˜ ํ…Œ์ด๋ธ” ์œ„์— "
287
  elif background_style == "๋ฏธ๋‹ˆ๋ฉ€ ๊ณต๊ฐ„":
288
- prompt += "๋ฏธ๋‹ˆ๋ฉ€ํ•œ ๋””์ž์ธ์˜ ๊น”๋”ํ•œ ๊ณต๊ฐ„์— "
289
  else:
290
- prompt += f"{background_style} ์‹ค๋‚ด ๊ณต๊ฐ„์— "
291
  elif background_type == "ํŠน์ˆ˜ ๋ฐฐ๊ฒฝ":
292
  if background_style == "๋„์‹œ ํ’๊ฒฝ":
293
- prompt += "ํ˜„๋Œ€์ ์ธ ๋„์‹œ ์Šค์นด์ด๋ผ์ธ์„ ๋ฐฐ๊ฒฝ์œผ๋กœ "
294
  elif background_style == "๋ฃจํ”„ํƒ‘":
295
- prompt += "๋„์‹œ ์ „๊ฒฝ์ด ๋ณด์ด๋Š” ๋ฃจํ”„ํƒ‘ ํ…Œ์ด๋ธ” ์œ„์— "
296
  elif background_style == "ํ•ด์•ˆ๊ฐ€":
297
- prompt += "์•„๋ฆ„๋‹ค์šด ํ•ด์•ˆ๊ฐ€์˜ ์ ˆ๋ฒฝ ์œ„์— "
298
  elif background_style == "๋ชจ๋˜ ์ŠคํŠœ๋””์˜ค":
299
- prompt += "ํ”„๋กœํŽ˜์…”๋„ํ•œ ๋ชจ๋˜ ์ŠคํŠœ๋””์˜ค ์„ธํŠธ์— "
300
  elif background_style == "๋นˆํ‹ฐ์ง€ ๊ณต๊ฐ„":
301
- prompt += "ํด๋ž˜์‹ํ•œ ๋ถ„์œ„๊ธฐ์˜ ๋นˆํ‹ฐ์ง€ ๊ณต๊ฐ„์— "
302
  elif background_style == "๋ฏธ๋‹ˆ์–ด์ฒ˜ ๊ณต๊ฐ„":
303
- prompt += "์ •๊ตํ•˜๊ฒŒ ๊พธ๋ฉฐ์ง„ ๋ฏธ๋‹ˆ์–ด์ฒ˜ ์„ธํŠธ ์œ„์— "
304
  else:
305
- prompt += f"{background_style} ํŠน์ˆ˜ ํ™˜๊ฒฝ์— "
306
 
307
  # ์กฐ๋ช…, ์งˆ๊ฐ, ์ƒ‰๊ฐ, ๋ถ„์œ„๊ธฐ ์ถ”๊ฐ€
308
- lighting_text = ""
309
- if lighting == "์ž์—ฐ๊ด‘":
310
- lighting_text = "๋ถ€๋“œ๋Ÿฌ์šด ์ž์—ฐ๊ด‘์ด ๋น„์น˜๋Š” ๊ฐ€์šด๋ฐ"
311
- elif lighting == "๋”ฐ๋œปํ•œ ์กฐ๋ช…":
312
- lighting_text = "๋”ฐ๋œปํ•œ ํ™ฉ๊ธˆ๋น› ์กฐ๋ช…์ด ๊ฐ์‹ธ๋Š” ๊ฐ€์šด๋ฐ"
313
- elif lighting == "๊ทธ๋ฆผ์ž ์žˆ๋Š” ์กฐ๋ช…":
314
- lighting_text = "๋“œ๋ผ๋งˆํ‹ฑํ•œ ๊ทธ๋ฆผ์ž๋ฅผ ๋งŒ๋“œ๋Š” ์กฐ๋ช… ์•„๋ž˜"
315
- elif lighting == "๋ฏธ๋‹ˆ๋ฉ€ ์กฐ๋ช…":
316
- lighting_text = "๊น”๋”ํ•˜๊ณ  ๋ฏธ๋‹ˆ๋ฉ€ํ•œ ์กฐ๋ช… ์•„๋ž˜"
317
-
318
- if lighting_text:
319
- prompt += lighting_text + " "
320
 
321
  # ์งˆ๊ฐ ์ถ”๊ฐ€
322
  if texture and texture != "์„ ํƒ ์•ˆํ•จ":
323
  if texture == "ํฐ ๋ฒฝ":
324
- prompt += "๊น”๋”ํ•œ ํฐ ๋ฒฝ์„ ๋ฐฐ๊ฒฝ์œผ๋กœ "
325
  elif texture == "๋Œ€๋ฆฌ์„":
326
  prompt += "๊ณ ๊ธ‰์Šค๋Ÿฌ์šด ๋Œ€๋ฆฌ์„ ์งˆ๊ฐ ์œ„์— "
327
  elif texture == "๋‚˜๋ฌด":
@@ -383,64 +408,30 @@ def generate_llm_prompt(product_name, product_category, background_type, backgro
383
 
384
  return prompt
385
 
386
- def process_and_show_prompt(image1, image2, image3, prompt, product_name, product_category,
387
- background_type, background_style, lighting, texture, color_tone, mood, llm_prompt=None):
388
- try:
389
- # ๋ฐฐ๊ฒฝ ์˜ต์…˜์„ ๋”•์…”๋„ˆ๋ฆฌ๋กœ ๊ตฌ์„ฑ
390
- bg_options = {
391
- "product_name": product_name if product_name else "์ƒํ’ˆ",
392
- "product_category": product_category,
393
- "background_type": background_type,
394
- "background_style": background_style,
395
- "lighting": lighting,
396
- "texture": texture if texture != "์„ ํƒ ์•ˆํ•จ" else "",
397
- "color_tone": color_tone if color_tone != "์„ ํƒ ์•ˆํ•จ" else "",
398
- "mood": mood if mood != "์„ ํƒ ์•ˆํ•จ" else ""
399
- }
400
-
401
- # LLM ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์žˆ์œผ๋ฉด ์‚ฌ์šฉ, ์—†์œผ๋ฉด ๊ธฐ๋ณธ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
402
- if llm_prompt and llm_prompt.strip():
403
- # LLM ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ
404
- prompt = llm_prompt
405
-
406
- # ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ๋ฐ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
407
- result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, bg_options)
408
-
409
- # ์„ ํƒ๋œ ์˜ต์…˜์„ ๋ฌธ์ž์—ด๋กœ ๊ตฌ์„ฑ
410
- options_summary = f"์ƒํ’ˆ๋ช…: {product_name if product_name else '์ง€์ •๋˜์ง€ ์•Š์Œ'}\n"
411
- options_summary += f"์ œํ’ˆ๊ตฐ: {product_category}\n"
412
- options_summary += f"๋ฐฐ๊ฒฝ ์œ ํ˜•: {background_type}\n"
413
- options_summary += f"์„ธ๋ถ€ ์Šคํƒ€์ผ: {background_style}\n"
414
-
415
- if lighting:
416
- options_summary += f"์กฐ๋ช…: {lighting}\n"
417
- if texture and texture != "์„ ํƒ ์•ˆํ•จ":
418
- options_summary += f"๋ฐฐ๊ฒฝ ์งˆ๊ฐ: {texture}\n"
419
- if color_tone and color_tone != "์„ ํƒ ์•ˆํ•จ":
420
- options_summary += f"์ƒ‰๊ฐ: {color_tone}\n"
421
- if mood and mood != "์„ ํƒ ์•ˆํ•จ":
422
- options_summary += f"๋ถ„์œ„๊ธฐ: {mood}\n"
423
-
424
- # ํ•œ๊ตญ์–ด์™€ ์˜์–ด ํ”„๋กฌํ”„ํŠธ ๋น„๊ต๋ฅผ ์œ„ํ•ด ์›๋ณธ ํ”„๋กฌํ”„ํŠธ ํ™•์ธ
425
- kr_prompt = preprocess_prompt(prompt, image1, image2, image3, bg_options)
426
-
427
- return result_img, status, final_prompt, options_summary, kr_prompt
428
- except Exception as e:
429
- logger.exception("์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
430
- return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt, "", ""
431
-
432
- # ์„ ํƒ ์˜ต์…˜ ํ‘œ์‹œ/์ˆจ๊น€ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
433
- def toggle_background_options(selection):
434
- if selection == "๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ":
435
- return (gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
436
- gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
437
- gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
438
- gr.update(visible=True))
439
- else:
440
- return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
441
- gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
442
- gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
443
- gr.update(visible=False))
444
 
445
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ฅธ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
446
  def update_background_style_options(background_type):
@@ -453,7 +444,6 @@ def update_background_style_options(background_type):
453
  else:
454
  return gr.update(choices=["์„ ํƒํ•˜์„ธ์š”"], value="์„ ํƒํ•˜์„ธ์š”")
455
 
456
-
457
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
458
  with gr.Blocks() as demo:
459
  gr.HTML(
@@ -565,20 +555,18 @@ with gr.Blocks() as demo:
565
  visible=False
566
  )
567
 
568
- # LLM ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ์ฐฝ
569
- llm_prompt_input = gr.Textbox(
570
- label="ํ”„๋กฌํ”„ํŠธ (์„ ํƒ ์‚ฌํ•ญ)",
571
- lines=3,
572
- visible=False
573
- )
574
 
575
- submit_btn = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
576
-
577
  with gr.Column(scale=1):
578
  output_image = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
579
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€")
580
- prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True)
581
- kr_prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (ํ•œ๊ตญ์–ด)", visible=True)
582
  options_summary = gr.Textbox(label="์„ ํƒ๋œ ์˜ต์…˜ ์š”์•ฝ", lines=8, visible=True)
583
 
584
  # ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ์ˆ˜์ •
@@ -587,14 +575,14 @@ with gr.Blocks() as demo:
587
  gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
588
  gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
589
  gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
590
- gr.update(visible=True), "", "") # ๋งˆ์ง€๋ง‰์— selection_preview์™€ llm_prompt ๋‚ด์šฉ ์ถ”๊ฐ€
591
 
592
  background_change_btn.click(
593
  fn=show_background_options,
594
  inputs=[],
595
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
596
  background_type, background_style, additional_header, lighting, texture,
597
- color_tone, mood, selection_preview, llm_prompt_input]
598
  )
599
 
600
  # ๋‹ค๋ฅธ ๊ธฐ๋Šฅ ๋ฒ„ํŠผ๋“ค๋„ ๊ฐ„๋‹จํ•œ ๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ •
@@ -603,14 +591,14 @@ with gr.Blocks() as demo:
603
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
604
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
605
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
606
- gr.update(visible=False), "", "") # ๋งˆ์ง€๋ง‰์— selection_preview์™€ llm_prompt ๋‚ด์šฉ ์ถ”๊ฐ€
607
 
608
  image_change_btn.click(
609
  fn=lambda: hide_background_options("#1 ์ด๋ฏธ์ง€์˜ [๋‹ค๋ฅธ ๋ชจ์Šต]์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ."),
610
  inputs=[],
611
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
612
  background_type, background_style, additional_header, lighting, texture,
613
- color_tone, mood, selection_preview, llm_prompt_input]
614
  )
615
 
616
  text_remove_btn.click(
@@ -618,7 +606,7 @@ with gr.Blocks() as demo:
618
  inputs=[],
619
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
620
  background_type, background_style, additional_header, lighting, texture,
621
- color_tone, mood, selection_preview, llm_prompt_input]
622
  )
623
 
624
  clothes_change_btn.click(
@@ -626,7 +614,7 @@ with gr.Blocks() as demo:
626
  inputs=[],
627
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
628
  background_type, background_style, additional_header, lighting, texture,
629
- color_tone, mood, selection_preview, llm_prompt_input]
630
  )
631
 
632
  composite_product_btn.click(
@@ -634,13 +622,30 @@ with gr.Blocks() as demo:
634
  inputs=[],
635
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
636
  background_type, background_style, additional_header, lighting, texture,
637
- color_tone, mood, selection_preview, llm_prompt_input]
638
  )
639
 
640
  # ์„ ํƒ ์˜ต์…˜ ๋ณ€๊ฒฝ ์‹œ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์™€ LLM ํ”„๋กฌํ”„ํŠธ ์—…๋ฐ์ดํŠธ
641
  def update_all_previews(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
642
- preview, llm_prompt = update_preview(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood)
643
- return preview, llm_prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644
 
645
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ (๋จผ์ € ์ˆ˜ํ–‰)
646
  background_type.change(
@@ -650,53 +655,65 @@ with gr.Blocks() as demo:
650
  ).then(
651
  fn=update_all_previews,
652
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
653
- outputs=[selection_preview, llm_prompt_input]
654
  )
655
 
656
  # ๋ชจ๋“  ์„ ํƒ ์ปดํฌ๋„ŒํŠธ์˜ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ์— ์—ฐ๊ฒฐ
657
  product_name.change(
658
  fn=update_all_previews,
659
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
660
- outputs=[selection_preview, llm_prompt_input]
661
  )
 
662
  product_category.change(
663
  fn=update_all_previews,
664
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
665
- outputs=[selection_preview, llm_prompt_input]
666
  )
 
667
  background_style.change(
668
  fn=update_all_previews,
669
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
670
- outputs=[selection_preview, llm_prompt_input]
671
  )
 
672
  lighting.change(
673
  fn=update_all_previews,
674
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
675
- outputs=[selection_preview, llm_prompt_input]
676
  )
 
677
  texture.change(
678
  fn=update_all_previews,
679
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
680
- outputs=[selection_preview, llm_prompt_input]
681
  )
 
682
  color_tone.change(
683
  fn=update_all_previews,
684
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
685
- outputs=[selection_preview, llm_prompt_input]
686
  )
 
687
  mood.change(
688
  fn=update_all_previews,
689
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
690
- outputs=[selection_preview, llm_prompt_input]
 
 
 
 
 
 
 
 
691
  )
692
 
693
- # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
694
  submit_btn.click(
695
- fn=process_and_show_prompt,
696
- inputs=[image1_input, image2_input, image3_input, prompt_input,
697
- product_name, product_category, background_type, background_style,
698
- lighting, texture, color_tone, mood, llm_prompt_input],
699
- outputs=[output_image, output_text, prompt_display, options_summary, kr_prompt_display],
700
  )
701
 
702
  gr.Markdown(
@@ -707,10 +724,11 @@ with gr.Blocks() as demo:
707
  2. "๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ์˜ต์…˜์ด ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
708
  3. ์ƒํ’ˆ๋ช…์„ ์ž…๋ ฅํ•˜๊ณ  ์ œํ’ˆ๊ตฐ, ๋ฐฐ๊ฒฝ ์œ ํ˜•, ๋ฐฐ๊ฒฝ ์„ธ๋ถ€ ์Šคํƒ€์ผ์„ ์„ ํƒํ•˜์„ธ์š”.
709
  4. ์ถ”๊ฐ€ ์˜ต์…˜(์กฐ๋ช…, ์งˆ๊ฐ, ์ƒ‰๊ฐ, ๋ถ„์œ„๊ธฐ)์„ ์„ ํƒํ•˜๋ฉด ๋” ์„ธ๋ฐ€ํ•œ ๋ฐฐ๊ฒฝ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
710
- 5. "์ด๋ฏธ์ง€ ์ƒ์„ฑ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์„ ํƒํ•œ ์˜ต์…˜์— ๋”ฐ๋ผ ๋ฐฐ๊ฒฝ์ด ๋ณ€๊ฒฝ๋œ ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
711
- 6. ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€์— ์ง์ ‘ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
 
712
 
713
- > **ํŒ**: ์„ ํƒ ๋‚ด์šฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์—์„œ ์ƒ์„ฑ๋œ LLM ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
714
  """
715
  )
716
 
 
224
  logger.exception("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
225
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
226
 
227
+ def ask_llm_for_final_prompt(kr_prompt):
228
+ """
229
+ LLM์— 2์ฐจ ์งˆ๋ฌธํ•˜์—ฌ ๋” ์ž์—ฐ์Šค๋Ÿฌ์šด ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์–ป๋Š” ํ•จ์ˆ˜
230
+ ์‹ค์ œ ๊ตฌํ˜„์—์„œ๋Š” LLM API๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•จ
231
+ """
232
+ try:
233
+ api_key = os.environ.get("GEMINI_API_KEY")
234
+ if not api_key:
235
+ logger.error("Gemini API ํ‚ค๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.")
236
+ return f"AI ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ”„๋กฌํ”„ํŠธ: {kr_prompt}"
237
+
238
+ client = genai.Client(api_key=api_key)
239
+
240
+ llm_prompt = f"""
241
+ ๋‹ค์Œ์€ ์ด์ปค๋จธ์Šค ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ์„ ์œ„ํ•œ ํ”„๋กฌํ”„ํŠธ์ž…๋‹ˆ๋‹ค. ์ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋” ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ๋งค๋ ฅ์ ์ธ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ”„๋กฌํ”„ํŠธ๋กœ
242
+ ๋‹ค์‹œ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ๋‹จ, ์›๋ณธ ์ด๋ฏธ์ง€์˜ ์ œํ’ˆ ํŠน์„ฑ์„ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ ๊ณผ ๋ฐฐ๊ฒฝ๋งŒ ๋ณ€๊ฒฝํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ ์€ ๋ฐ˜๋“œ์‹œ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
243
+
244
+ ์›๋ณธ ํ”„๋กฌํ”„ํŠธ:
245
+ {kr_prompt}
246
+
247
+ ๊ฒฐ๊ณผ๋ฌผ์€ AI ์ด๋ฏธ์ง€ ์ƒ์„ฑ์— ์ตœ์ ํ™”๋œ ํ”„๋กฌํ”„ํŠธ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ๋ฌผ๋งŒ ์ œ๊ณตํ•˜๊ณ  ์„ค๋ช…์ด๋‚˜ ์ถ”๊ฐ€ ํ…์ŠคํŠธ ์—†์ด ํ”„๋กฌํ”„ํŠธ ์ž์ฒด๋งŒ ์ถœ๋ ฅํ•ด์ฃผ์„ธ์š”.
248
+ """
249
+
250
+ response = client.models.generate_content(
251
+ model="gemini-2.0-flash",
252
+ contents=[llm_prompt],
253
+ config=types.GenerateContentConfig(
254
+ response_modalities=['Text'],
255
+ temperature=0.7,
256
+ top_p=0.95,
257
+ top_k=40,
258
+ max_output_tokens=512
259
+ )
260
+ )
261
+
262
+ final_prompt = ""
263
+ for part in response.candidates[0].content.parts:
264
+ if hasattr(part, 'text') and part.text:
265
+ final_prompt += part.text
266
+
267
+ if final_prompt.strip():
268
+ logger.info(f"LLM 2์ฐจ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๊ฒฐ๊ณผ: {final_prompt.strip()}")
269
+ return final_prompt.strip()
270
+ else:
271
+ logger.warning("LLM 2์ฐจ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์›๋ณธ ํ”„๋กฌํ”„ํŠธ ์‚ฌ์šฉ")
272
+ return f"AI ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ”„๋กฌํ”„ํŠธ: {kr_prompt}"
273
+ except Exception as e:
274
+ logger.exception("LLM 2์ฐจ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
275
+ return f"AI ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ”„๋กฌํ”„ํŠธ: {kr_prompt}"
276
 
277
  # LLM ์Šคํƒ€์ผ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ•จ์ˆ˜
278
  def generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
279
  # ๊ธฐ๋ณธ ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ
280
+ prompt = f"#1 ์›๋ณธ ์ด๋ฏธ์ง€์˜ {product_name} ์ œํ’ˆ์„ 100% ๋™์ผํ•˜๊ฒŒ ์œ ์ง€ํ•˜๋ฉด์„œ ๋ฐฐ๊ฒฝ๋งŒ "
281
 
282
  # ๋ฐฐ๊ฒฝ ์œ ํ˜• ๋ฐ ์Šคํƒ€์ผ ์ถ”๊ฐ€
283
  if background_type == "์ž์—ฐ ๋ฐฐ๊ฒฝ":
284
  if background_style == "์ˆฒ":
285
+ prompt += "์šธ์ฐฝํ•œ ์ˆฒ์†์˜ ์ž์—ฐ ํ™˜๊ฒฝ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
286
  elif background_style == "ํ•ด๋ณ€":
287
+ prompt += "์ฒญ๋Ÿ‰ํ•œ ํ•ด๋ณ€๊ฐ€์˜ ๋ชจ๋ž˜ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
288
  elif background_style == "์‚ฐ":
289
+ prompt += "์›…์žฅํ•œ ์‚ฐ์˜ ์ •์ƒ์—์„œ ๋ง‘์€ ํ•˜๋Š˜์„ ๋ฐฐ๊ฒฝ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
290
  elif background_style == "๋“คํŒ":
291
+ prompt += "๋„“๊ฒŒ ํŽผ์ณ์ง„ ์ดˆ์› ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
292
  elif background_style == "๊ณ„๊ณก":
293
+ prompt += "์‹œ์›ํ•œ ๊ณ„๊ณก๋ฌผ์ด ํ๋ฅด๋Š” ๋ฐ”์œ„ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
294
  elif background_style == "์—ด๋Œ€ ์ •์›":
295
+ prompt += "์ƒ๋™๊ฐ ๋„˜์น˜๋Š” ์—ด๋Œ€ ์‹๋ฌผ๋กœ ๋‘˜๋Ÿฌ์‹ธ์ธ ๊ณต๊ฐ„์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
296
  elif background_style == "์‚ฌ๋ง‰":
297
+ prompt += "๋์—†์ด ํŽผ์ณ์ง„ ํ™ฉ๊ธˆ๋น› ์‚ฌ๋ง‰ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
298
  elif background_style == "๋ˆˆ ํ’๊ฒฝ":
299
+ prompt += "ํ•˜์–€ ๋ˆˆ์œผ๋กœ ๋ฎ์ธ ์ˆœ๋ฐฑ์˜ ํ’๊ฒฝ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
300
  else:
301
+ prompt += f"{background_style} ์ž์—ฐ ํ™˜๊ฒฝ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
302
  elif background_type == "์‹ค๋‚ด ๋ฐฐ๊ฒฝ":
303
  if background_style == "๊ฑฐ์‹ค":
304
+ prompt += "๋ชจ๋˜ํ•˜๊ณ  ์„ธ๋ จ๋œ ๊ฑฐ์‹ค ๊ณต๊ฐ„์˜ ํ…Œ์ด๋ธ” ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
305
  elif background_style == "์ฃผ๋ฐฉ":
306
+ prompt += "๊น”๋”ํ•œ ์ฃผ๋ฐฉ ์นด์šดํ„ฐ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
307
  elif background_style == "์„œ์žฌ":
308
+ prompt += "์ง€์ ์ธ ๋ถ„์œ„๊ธฐ์˜ ์„œ์žฌ ์ฑ…์ƒ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
309
  elif background_style == "ํ™”์žฅ๋Œ€":
310
+ prompt += "์„ธ๋ จ๋œ ํ™”์žฅ๋Œ€ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
311
  elif background_style == "ํ˜ธํ…” ๋กœ๋น„":
312
+ prompt += "๊ณ ๊ธ‰์Šค๋Ÿฌ์šด ํ˜ธํ…” ๋กœ๋น„์˜ ๋Œ€๋ฆฌ์„ ํ…Œ์ด๋ธ” ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
313
  elif background_style == "์นดํŽ˜":
314
+ prompt += "๊ฐ์„ฑ์ ์ธ ์นดํŽ˜ ํ…Œ์ด๋ธ” ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
315
  elif background_style == "๋ฏธ๋‹ˆ๋ฉ€ ๊ณต๊ฐ„":
316
+ prompt += "๋ฏธ๋‹ˆ๋ฉ€ํ•œ ๋””์ž์ธ์˜ ๊น”๋”ํ•œ ๊ณต๊ฐ„์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
317
  else:
318
+ prompt += f"{background_style} ์‹ค๋‚ด ๊ณต๊ฐ„์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
319
  elif background_type == "ํŠน์ˆ˜ ๋ฐฐ๊ฒฝ":
320
  if background_style == "๋„์‹œ ํ’๊ฒฝ":
321
+ prompt += "ํ˜„๋Œ€์ ์ธ ๋„์‹œ ์Šค์นด์ด๋ผ์ธ์„ ๋ฐฐ๊ฒฝ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
322
  elif background_style == "๋ฃจํ”„ํƒ‘":
323
+ prompt += "๋„์‹œ ์ „๊ฒฝ์ด ๋ณด์ด๋Š” ๋ฃจํ”„ํƒ‘ ํ…Œ์ด๋ธ” ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
324
  elif background_style == "ํ•ด์•ˆ๊ฐ€":
325
+ prompt += "์•„๋ฆ„๋‹ค์šด ํ•ด์•ˆ๊ฐ€์˜ ์ ˆ๋ฒฝ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
326
  elif background_style == "๋ชจ๋˜ ์ŠคํŠœ๋””์˜ค":
327
+ prompt += "ํ”„๋กœํŽ˜์…”๋„ํ•œ ๋ชจ๋˜ ์ŠคํŠœ๋””์˜ค ์„ธํŠธ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
328
  elif background_style == "๋นˆํ‹ฐ์ง€ ๊ณต๊ฐ„":
329
+ prompt += "ํด๋ž˜์‹ํ•œ ๋ถ„์œ„๊ธฐ์˜ ๋นˆํ‹ฐ์ง€ ๊ณต๊ฐ„์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
330
  elif background_style == "๋ฏธ๋‹ˆ์–ด์ฒ˜ ๊ณต๊ฐ„":
331
+ prompt += "์ •๊ตํ•˜๊ฒŒ ๊พธ๋ฉฐ์ง„ ๋ฏธ๋‹ˆ์–ด์ฒ˜ ์„ธํŠธ ์œ„๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
332
  else:
333
+ prompt += f"{background_style} ํŠน์ˆ˜ ํ™˜๊ฒฝ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
334
 
335
  # ์กฐ๋ช…, ์งˆ๊ฐ, ์ƒ‰๊ฐ, ๋ถ„์œ„๊ธฐ ์ถ”๊ฐ€
336
+ if lighting:
337
+ if lighting == "์ž์—ฐ๊ด‘":
338
+ prompt += "๋ถ€๋“œ๋Ÿฌ์šด ์ž์—ฐ๊ด‘์ด ๋น„์น˜๋Š” ํ™˜๊ฒฝ์—์„œ "
339
+ elif lighting == "๋”ฐ๋œปํ•œ ์กฐ๋ช…":
340
+ prompt += "๋”ฐ๋œปํ•œ ๏ฟฝ๏ฟฝ๊ธˆ๋น› ์กฐ๋ช…์ด ๊ฐ์‹ธ๋Š” ํ™˜๊ฒฝ์—์„œ "
341
+ elif lighting == "๊ทธ๋ฆผ์ž ์žˆ๋Š” ์กฐ๋ช…":
342
+ prompt += "๋“œ๋ผ๋งˆํ‹ฑํ•œ ๊ทธ๋ฆผ์ž๋ฅผ ๋งŒ๋“œ๋Š” ์กฐ๋ช… ์•„๋ž˜์—์„œ "
343
+ elif lighting == "๋ฏธ๋‹ˆ๋ฉ€ ์กฐ๋ช…":
344
+ prompt += "๊น”๋”ํ•˜๊ณ  ๋ฏธ๋‹ˆ๋ฉ€ํ•œ ์กฐ๋ช… ์•„๋ž˜์—์„œ "
 
 
 
345
 
346
  # ์งˆ๊ฐ ์ถ”๊ฐ€
347
  if texture and texture != "์„ ํƒ ์•ˆํ•จ":
348
  if texture == "ํฐ ๋ฒฝ":
349
+ prompt += "๊น”๋”ํ•œ ํฐ ๋ฒฝ์„ ๋ฐฐ๊ฒฝ์œผ๋กœ ํ•˜์—ฌ "
350
  elif texture == "๋Œ€๋ฆฌ์„":
351
  prompt += "๊ณ ๊ธ‰์Šค๋Ÿฌ์šด ๋Œ€๋ฆฌ์„ ์งˆ๊ฐ ์œ„์— "
352
  elif texture == "๋‚˜๋ฌด":
 
408
 
409
  return prompt
410
 
411
+ # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฐ LLM์— 2์ฐจ ์งˆ๋ฌธ ํ•จ์ˆ˜
412
+ def generate_prompt_and_ask_llm(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
413
+ # 1์ฐจ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
414
+ kr_prompt = generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood)
415
+
416
+ # LLM์— 2์ฐจ ์งˆ๋ฌธํ•˜์—ฌ ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
417
+ final_prompt = ask_llm_for_final_prompt(kr_prompt)
418
+
419
+ # ์„ ํƒ ์˜ต์…˜ ์š”์•ฝ
420
+ options_summary = f"์ƒํ’ˆ๋ช…: {product_name if product_name else '์ง€์ •๋˜์ง€ ์•Š์Œ'}\n"
421
+ options_summary += f"์ œํ’ˆ๊ตฐ: {product_category}\n"
422
+ options_summary += f"๋ฐฐ๊ฒฝ ์œ ํ˜•: {background_type}\n"
423
+ options_summary += f"์„ธ๋ถ€ ์Šคํƒ€์ผ: {background_style}\n"
424
+
425
+ if lighting:
426
+ options_summary += f"์กฐ๋ช…: {lighting}\n"
427
+ if texture and texture != "์„ ํƒ ์•ˆํ•จ":
428
+ options_summary += f"๋ฐฐ๊ฒฝ ์งˆ๊ฐ: {texture}\n"
429
+ if color_tone and color_tone != "์„ ํƒ ์•ˆํ•จ":
430
+ options_summary += f"์ƒ‰๊ฐ: {color_tone}\n"
431
+ if mood and mood != "์„ ํƒ ์•ˆํ•จ":
432
+ options_summary += f"๋ถ„์œ„๊ธฐ: {mood}\n"
433
+
434
+ return kr_prompt, final_prompt, options_summary
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
 
436
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ฅธ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
437
  def update_background_style_options(background_type):
 
444
  else:
445
  return gr.update(choices=["์„ ํƒํ•˜์„ธ์š”"], value="์„ ํƒํ•˜์„ธ์š”")
446
 
 
447
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
448
  with gr.Blocks() as demo:
449
  gr.HTML(
 
555
  visible=False
556
  )
557
 
558
+ # ๋ฒ„ํŠผ๋“ค์„ ๊ทธ๋ฃนํ™”
559
+ with gr.Row(visible=False) as buttons_row:
560
+ # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฒ„ํŠผ ์ถ”๊ฐ€
561
+ prompt_generate_btn = gr.Button("ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ", variant="secondary")
562
+ # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ
563
+ submit_btn = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
564
 
 
 
565
  with gr.Column(scale=1):
566
  output_image = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
567
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€")
568
+ kr_prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (ํ•œ๊ตญ์–ด)", visible=True, lines=4)
569
+ prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True, lines=4)
570
  options_summary = gr.Textbox(label="์„ ํƒ๋œ ์˜ต์…˜ ์š”์•ฝ", lines=8, visible=True)
571
 
572
  # ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ์ˆ˜์ •
 
575
  gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
576
  gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
577
  gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
578
+ gr.update(visible=True), "", gr.update(visible=True)) # ๋ฒ„ํŠผ ๊ทธ๋ฃน ํ‘œ์‹œ ์ถ”๊ฐ€
579
 
580
  background_change_btn.click(
581
  fn=show_background_options,
582
  inputs=[],
583
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
584
  background_type, background_style, additional_header, lighting, texture,
585
+ color_tone, mood, selection_preview, buttons_row]
586
  )
587
 
588
  # ๋‹ค๋ฅธ ๊ธฐ๋Šฅ ๋ฒ„ํŠผ๋“ค๋„ ๊ฐ„๋‹จํ•œ ๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ •
 
591
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
592
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
593
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
594
+ gr.update(visible=False), "", gr.update(visible=False)) # ๋ฒ„ํŠผ ๊ทธ๋ฃน ์ˆจ๊น€ ์ถ”๊ฐ€
595
 
596
  image_change_btn.click(
597
  fn=lambda: hide_background_options("#1 ์ด๋ฏธ์ง€์˜ [๋‹ค๋ฅธ ๋ชจ์Šต]์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ."),
598
  inputs=[],
599
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
600
  background_type, background_style, additional_header, lighting, texture,
601
+ color_tone, mood, selection_preview, buttons_row]
602
  )
603
 
604
  text_remove_btn.click(
 
606
  inputs=[],
607
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
608
  background_type, background_style, additional_header, lighting, texture,
609
+ color_tone, mood, selection_preview, buttons_row]
610
  )
611
 
612
  clothes_change_btn.click(
 
614
  inputs=[],
615
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
616
  background_type, background_style, additional_header, lighting, texture,
617
+ color_tone, mood, selection_preview, buttons_row]
618
  )
619
 
620
  composite_product_btn.click(
 
622
  inputs=[],
623
  outputs=[prompt_input, current_selection, background_header, product_name, product_category,
624
  background_type, background_style, additional_header, lighting, texture,
625
+ color_tone, mood, selection_preview, buttons_row]
626
  )
627
 
628
  # ์„ ํƒ ์˜ต์…˜ ๋ณ€๊ฒฝ ์‹œ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์™€ LLM ํ”„๋กฌํ”„ํŠธ ์—…๋ฐ์ดํŠธ
629
  def update_all_previews(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
630
+ llm_prompt = generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood)
631
+
632
+ preview = f"์ƒํ’ˆ๋ช…: {product_name}\n"
633
+ preview += f"์ œํ’ˆ๊ตฐ: {product_category}\n"
634
+ preview += f"๋ฐฐ๊ฒฝ ์œ ํ˜•: {background_type}\n"
635
+ preview += f"์„ธ๋ถ€ ์Šคํƒ€์ผ: {background_style}\n"
636
+
637
+ if lighting:
638
+ preview += f"์กฐ๋ช…: {lighting}\n"
639
+ if texture and texture != "์„ ํƒ ์•ˆํ•จ":
640
+ preview += f"๋ฐฐ๊ฒฝ ์งˆ๊ฐ: {texture}\n"
641
+ if color_tone and color_tone != "์„ ํƒ ์•ˆํ•จ":
642
+ preview += f"์ƒ‰๊ฐ: {color_tone}\n"
643
+ if mood and mood != "์„ ํƒ ์•ˆํ•จ":
644
+ preview += f"๋ถ„์œ„๊ธฐ: {mood}\n"
645
+
646
+ preview += f"\n์ƒ์„ฑ๋  ํ”„๋กฌํ”„ํŠธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ:\n{llm_prompt}"
647
+
648
+ return preview
649
 
650
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ (๋จผ์ € ์ˆ˜ํ–‰)
651
  background_type.change(
 
655
  ).then(
656
  fn=update_all_previews,
657
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
658
+ outputs=[selection_preview]
659
  )
660
 
661
  # ๋ชจ๋“  ์„ ํƒ ์ปดํฌ๋„ŒํŠธ์˜ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ์— ์—ฐ๊ฒฐ
662
  product_name.change(
663
  fn=update_all_previews,
664
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
665
+ outputs=[selection_preview]
666
  )
667
+
668
  product_category.change(
669
  fn=update_all_previews,
670
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
671
+ outputs=[selection_preview]
672
  )
673
+
674
  background_style.change(
675
  fn=update_all_previews,
676
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
677
+ outputs=[selection_preview]
678
  )
679
+
680
  lighting.change(
681
  fn=update_all_previews,
682
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
683
+ outputs=[selection_preview]
684
  )
685
+
686
  texture.change(
687
  fn=update_all_previews,
688
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
689
+ outputs=[selection_preview]
690
  )
691
+
692
  color_tone.change(
693
  fn=update_all_previews,
694
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
695
+ outputs=[selection_preview]
696
  )
697
+
698
  mood.change(
699
  fn=update_all_previews,
700
  inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
701
+ outputs=[selection_preview]
702
+ )
703
+
704
+ # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
705
+ prompt_generate_btn.click(
706
+ fn=generate_prompt_and_ask_llm,
707
+ inputs=[product_name, product_category, background_type, background_style,
708
+ lighting, texture, color_tone, mood],
709
+ outputs=[kr_prompt_display, prompt_input, options_summary]
710
  )
711
 
712
+ # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ (์›๋ž˜ ๊ธฐ๋Šฅ ๋ณต์›)
713
  submit_btn.click(
714
+ fn=process_images_with_prompt,
715
+ inputs=[image1_input, image2_input, image3_input, prompt_input],
716
+ outputs=[output_image, output_text, prompt_display],
 
 
717
  )
718
 
719
  gr.Markdown(
 
724
  2. "๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ์˜ต์…˜์ด ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
725
  3. ์ƒํ’ˆ๋ช…์„ ์ž…๋ ฅํ•˜๊ณ  ์ œํ’ˆ๊ตฐ, ๋ฐฐ๊ฒฝ ์œ ํ˜•, ๋ฐฐ๊ฒฝ ์„ธ๋ถ€ ์Šคํƒ€์ผ์„ ์„ ํƒํ•˜์„ธ์š”.
726
  4. ์ถ”๊ฐ€ ์˜ต์…˜(์กฐ๋ช…, ์งˆ๊ฐ, ์ƒ‰๊ฐ, ๋ถ„์œ„๊ธฐ)์„ ์„ ํƒํ•˜๋ฉด ๋” ์„ธ๋ฐ€ํ•œ ๋ฐฐ๊ฒฝ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
727
+ 5. "ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด LLM ์Šคํƒ€์ผ ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์ƒ์„ฑ๋˜๊ณ , ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ด๋ฏธ์ง€ ์ƒ์„ฑ์šฉ ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
728
+ 6. "์ด๋ฏธ์ง€ ์ƒ์„ฑ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
729
+ 7. ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€์— ์ง์ ‘ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
730
 
731
+ > **ํŒ**: ์„ ํƒ ๋‚ด์šฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์—์„œ ์ƒ์„ฑ๋  ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
732
  """
733
  )
734