Update app.py
Browse files
app.py
CHANGED
@@ -224,8 +224,167 @@ 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 process_and_show_prompt(image1, image2, image3, prompt, product_name, product_category,
|
228 |
-
background_type, background_style, lighting, texture, color_tone, mood):
|
229 |
try:
|
230 |
# ๋ฐฐ๊ฒฝ ์ต์
์ ๋์
๋๋ฆฌ๋ก ๊ตฌ์ฑ
|
231 |
bg_options = {
|
@@ -238,7 +397,13 @@ def process_and_show_prompt(image1, image2, image3, prompt, product_name, produc
|
|
238 |
"color_tone": color_tone if color_tone != "์ ํ ์ํจ" else "",
|
239 |
"mood": mood if mood != "์ ํ ์ํจ" else ""
|
240 |
}
|
|
|
|
|
|
|
|
|
|
|
241 |
|
|
|
242 |
result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, bg_options)
|
243 |
|
244 |
# ์ ํ๋ ์ต์
์ ๋ฌธ์์ด๋ก ๊ตฌ์ฑ
|
@@ -288,23 +453,6 @@ def update_background_style_options(background_type):
|
|
288 |
else:
|
289 |
return gr.update(choices=["์ ํํ์ธ์"], value="์ ํํ์ธ์")
|
290 |
|
291 |
-
# ์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์
๋ฐ์ดํธ ํจ์
|
292 |
-
def update_preview(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
|
293 |
-
preview = f"์ํ๋ช
: {product_name}\n"
|
294 |
-
preview += f"์ ํ๊ตฐ: {product_category}\n"
|
295 |
-
preview += f"๋ฐฐ๊ฒฝ ์ ํ: {background_type}\n"
|
296 |
-
preview += f"์ธ๋ถ ์คํ์ผ: {background_style}\n"
|
297 |
-
|
298 |
-
if lighting:
|
299 |
-
preview += f"์กฐ๋ช
: {lighting}\n"
|
300 |
-
if texture and texture != "์ ํ ์ํจ":
|
301 |
-
preview += f"๋ฐฐ๊ฒฝ ์ง๊ฐ: {texture}\n"
|
302 |
-
if color_tone and color_tone != "์ ํ ์ํจ":
|
303 |
-
preview += f"์๊ฐ: {color_tone}\n"
|
304 |
-
if mood and mood != "์ ํ ์ํจ":
|
305 |
-
preview += f"๋ถ์๊ธฐ: {mood}\n"
|
306 |
-
|
307 |
-
return preview
|
308 |
|
309 |
# Gradio ์ธํฐํ์ด์ค
|
310 |
with gr.Blocks() as demo:
|
@@ -417,6 +565,13 @@ with gr.Blocks() as demo:
|
|
417 |
visible=False
|
418 |
)
|
419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
submit_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ", variant="primary")
|
421 |
|
422 |
with gr.Column(scale=1):
|
@@ -426,134 +581,113 @@ with gr.Blocks() as demo:
|
|
426 |
kr_prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (ํ๊ตญ์ด)", visible=True)
|
427 |
options_summary = gr.Textbox(label="์ ํ๋ ์ต์
์์ฝ", lines=8, visible=True)
|
428 |
|
429 |
-
# ์ ํ ์ต์
๋ฒํผ ํด๋ฆญ ์ ํ๋กฌํํธ ์
๋ ฅ๋ ์
๋ฐ์ดํธ (ํ๊ตญ์ด ๋ฌธ๊ตฌ)
|
430 |
-
image_change_btn.click(
|
431 |
-
fn=lambda: "#1 ์ด๋ฏธ์ง์ [๋ค๋ฅธ ๋ชจ์ต]์ผ๋ก ๋ณ๊ฒฝํ๋ผ.",
|
432 |
-
inputs=[],
|
433 |
-
outputs=prompt_input
|
434 |
-
).then(
|
435 |
-
fn=lambda: "์ด๋ฏธ์ง ๋ณ๊ฒฝ",
|
436 |
-
inputs=[],
|
437 |
-
outputs=current_selection
|
438 |
-
).then(
|
439 |
-
fn=toggle_background_options,
|
440 |
-
inputs=[current_selection],
|
441 |
-
outputs=[background_header, product_name, product_category, background_type,
|
442 |
-
background_style, additional_header, lighting, texture, color_tone,
|
443 |
-
mood, selection_preview]
|
444 |
-
)
|
445 |
-
|
446 |
-
text_remove_btn.click(
|
447 |
-
fn=lambda: "#1 ์ด๋ฏธ์ง์ [์ค๊ตญ์ด๋ฅผ ๋ชจ๋]๋ฅผ ์ ๊ฑฐํ๋ผ.",
|
448 |
-
inputs=[],
|
449 |
-
outputs=prompt_input
|
450 |
-
).then(
|
451 |
-
fn=lambda: "๊ธ์์ง์ฐ๊ธฐ",
|
452 |
-
inputs=[],
|
453 |
-
outputs=current_selection
|
454 |
-
).then(
|
455 |
-
fn=toggle_background_options,
|
456 |
-
inputs=[current_selection],
|
457 |
-
outputs=[background_header, product_name, product_category, background_type,
|
458 |
-
background_style, additional_header, lighting, texture, color_tone,
|
459 |
-
mood, selection_preview]
|
460 |
-
)
|
461 |
-
|
462 |
-
clothes_change_btn.click(
|
463 |
-
fn=lambda: "#1์ด๋ฏธ์ง์์ [์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด] ์์[์คํ์ผ๊ณผ ์์์]#2, #3์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์.",
|
464 |
-
inputs=[],
|
465 |
-
outputs=prompt_input
|
466 |
-
).then(
|
467 |
-
fn=lambda: "์ท๋ฐ๊พธ๊ธฐ",
|
468 |
-
inputs=[],
|
469 |
-
outputs=current_selection
|
470 |
-
).then(
|
471 |
-
fn=toggle_background_options,
|
472 |
-
inputs=[current_selection],
|
473 |
-
outputs=[background_header, product_name, product_category, background_type,
|
474 |
-
background_style, additional_header, lighting, texture, color_tone,
|
475 |
-
mood, selection_preview]
|
476 |
-
)
|
477 |
-
|
478 |
# ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ ๋ ๊ฐ๋จํ๊ฒ ์์
|
479 |
def show_background_options():
|
480 |
return ("๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ", "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ",
|
481 |
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
482 |
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
483 |
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
484 |
-
gr.update(visible=True), "") # ๋ง์ง๋ง์ selection_preview ๋ด์ฉ ์ถ๊ฐ
|
485 |
|
486 |
background_change_btn.click(
|
487 |
fn=show_background_options,
|
488 |
inputs=[],
|
489 |
outputs=[prompt_input, current_selection, background_header, product_name, product_category,
|
490 |
background_type, background_style, additional_header, lighting, texture,
|
491 |
-
color_tone, mood, selection_preview]
|
492 |
)
|
493 |
|
494 |
-
|
495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
inputs=[],
|
497 |
-
outputs=prompt_input
|
498 |
-
|
499 |
-
|
|
|
|
|
|
|
|
|
500 |
inputs=[],
|
501 |
-
outputs=current_selection
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
)
|
509 |
|
510 |
-
#
|
|
|
|
|
|
|
|
|
|
|
511 |
background_type.change(
|
512 |
fn=update_background_style_options,
|
513 |
inputs=[background_type],
|
514 |
outputs=[background_style]
|
|
|
|
|
|
|
|
|
515 |
)
|
516 |
|
517 |
-
#
|
518 |
product_name.change(
|
519 |
-
fn=
|
520 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
521 |
-
outputs=[selection_preview]
|
522 |
)
|
523 |
product_category.change(
|
524 |
-
fn=
|
525 |
-
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
526 |
-
outputs=[selection_preview]
|
527 |
-
)
|
528 |
-
background_type.change(
|
529 |
-
fn=update_preview,
|
530 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
531 |
-
outputs=[selection_preview]
|
532 |
)
|
533 |
background_style.change(
|
534 |
-
fn=
|
535 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
536 |
-
outputs=[selection_preview]
|
537 |
)
|
538 |
lighting.change(
|
539 |
-
fn=
|
540 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
541 |
-
outputs=[selection_preview]
|
542 |
)
|
543 |
texture.change(
|
544 |
-
fn=
|
545 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
546 |
-
outputs=[selection_preview]
|
547 |
)
|
548 |
color_tone.change(
|
549 |
-
fn=
|
550 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
551 |
-
outputs=[selection_preview]
|
552 |
)
|
553 |
mood.change(
|
554 |
-
fn=
|
555 |
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
556 |
-
outputs=[selection_preview]
|
557 |
)
|
558 |
|
559 |
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
@@ -561,7 +695,7 @@ with gr.Blocks() as demo:
|
|
561 |
fn=process_and_show_prompt,
|
562 |
inputs=[image1_input, image2_input, image3_input, prompt_input,
|
563 |
product_name, product_category, background_type, background_style,
|
564 |
-
lighting, texture, color_tone, mood],
|
565 |
outputs=[output_image, output_text, prompt_display, options_summary, kr_prompt_display],
|
566 |
)
|
567 |
|
@@ -569,12 +703,14 @@ with gr.Blocks() as demo:
|
|
569 |
"""
|
570 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
571 |
|
572 |
-
1.
|
573 |
-
2.
|
574 |
-
3.
|
575 |
-
4.
|
|
|
|
|
576 |
|
577 |
-
> **ํ**: ํ๋กฌํํธ๋ฅผ
|
578 |
"""
|
579 |
)
|
580 |
|
|
|
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 == "๋๋ฌด":
|
328 |
+
prompt += "๋ฐ๋ปํ ๋๋์ ์๋ชฉ ์ง๊ฐ ์์ "
|
329 |
+
elif texture == "๋ฒฝ๋":
|
330 |
+
prompt += "ํด๋์ํ ๋ฒฝ๋ ์ง๊ฐ์ ๋ฐฐ๊ฒฝ์ผ๋ก "
|
331 |
+
elif texture == "ํฐ ์ฒ":
|
332 |
+
prompt += "๋ถ๋๋ฌ์ด ํฐ ์ฒ ์์ "
|
333 |
+
elif texture == "์๋ฉํธ":
|
334 |
+
prompt += "๋ชจ๋ํ ์๋ฉํธ ์ง๊ฐ ์์ "
|
335 |
+
|
336 |
+
# ์๊ฐ ์ถ๊ฐ
|
337 |
+
if color_tone and color_tone != "์ ํ ์ํจ":
|
338 |
+
if color_tone == "ํ์ดํธ ํค":
|
339 |
+
prompt += "์๋ฐฑ์ ๊น๋ํ ์๊ฐ์ผ๋ก "
|
340 |
+
elif color_tone == "๋ธ๋ฃจ ํค":
|
341 |
+
prompt += "์์ํ ๋ธ๋ฃจ ํค์ ์๊ฐ์ผ๋ก "
|
342 |
+
elif color_tone == "๋ฐ๋ปํ ์์":
|
343 |
+
prompt += "๋ฐ๋ปํ ํ์คํ
์๊ฐ์ผ๋ก "
|
344 |
+
elif color_tone == "๋ชจ๋
ธํค":
|
345 |
+
prompt += "์ธ๋ จ๋ ๋ชจ๋
ธํค ์๊ฐ์ผ๋ก "
|
346 |
+
elif color_tone == "ํ์คํ
":
|
347 |
+
prompt += "๋ถ๋๋ฌ์ด ํ์คํ
์๊ฐ์ผ๋ก "
|
348 |
+
|
349 |
+
# ๋ถ์๊ธฐ ์ถ๊ฐ
|
350 |
+
if mood and mood != "์ ํ ์ํจ":
|
351 |
+
if mood == "ํฌ๊ทผํ":
|
352 |
+
prompt += "ํฌ๊ทผํ๊ณ ์๋ํ ๋ถ์๊ธฐ ์์์ "
|
353 |
+
elif mood == "์ฌํํ":
|
354 |
+
prompt += "์ฌํํ๊ณ ๊น๋ํ ๋ถ์๊ธฐ ์์์ "
|
355 |
+
elif mood == "๋ชจ๋ํ":
|
356 |
+
prompt += "๋ชจ๋ํ๊ณ ์ธ๋ จ๋ ๋ถ์๊ธฐ ์์์ "
|
357 |
+
elif mood == "๋ด์ถ๋ด":
|
358 |
+
prompt += "์์ฐ์ค๋ฝ๊ณ ํธ์ํ ๋ถ์๊ธฐ ์์์ "
|
359 |
+
elif mood == "๋ฏธ๋๋ฉ":
|
360 |
+
prompt += "๋ฏธ๋๋ฉ๋ฆฌ์ฆ์ ์ ์ ๋ ๋ถ์๊ธฐ ์์์ "
|
361 |
+
|
362 |
+
# ๋ง๋ฌด๋ฆฌ
|
363 |
+
if product_category == "ํ์ฅํ":
|
364 |
+
prompt += "์๋ฒฝํ ๋ํ
์ผ์ด ์ด์์๋ ํ์ฅํ ์ ํ์ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
365 |
+
elif product_category == "๊ฐ๋ฐฉ":
|
366 |
+
prompt += "์ง๊ฐ๊ณผ ๋์์ธ์ด ๋๋ณด์ด๋ ๊ฐ๋ฐฉ ์ ํ์ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
367 |
+
elif product_category == "์ก์ธ์๋ฆฌ":
|
368 |
+
prompt += "์ฌ์ธํ ๋ํ
์ผ์ด ๋น๋๋ ์ก์ธ์๋ฆฌ๋ฅผ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
369 |
+
elif product_category == "๋ณด์๋ฅ":
|
370 |
+
prompt += "ํ๋ คํ ๊ด์ฑ๊ฐ ๋๋ณด์ด๋ ๋ณด์ ์ ํ์ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
371 |
+
elif product_category == "ํ ๋ฐ์ฝ":
|
372 |
+
prompt += "๊ณต๊ฐ์ ์ด์ธ๋ฆฌ๋ ํ ๋ฐ์ฝ ์ ํ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
373 |
+
elif product_category == "์ ๋ฐ":
|
374 |
+
prompt += "๋์์ธ๊ณผ ์ง๊ฐ์ด ๋๋ณด์ด๋ ์ ๋ฐ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
375 |
+
elif product_category == "์๋ฅ":
|
376 |
+
prompt += "์์ฌ์ ์ค๋ฃจ์ฃ์ด ๋๋ณด์ด๋ ์๋ฅ๋ฅผ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
377 |
+
elif product_category == "์ฃผ๋ฐฉ์ฉํ":
|
378 |
+
prompt += "์ค์ฉ์ฑ๊ณผ ๋์์ธ์ด ๋๋ณด์ด๋ ์ฃผ๋ฐฉ์ฉํ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
379 |
+
elif product_category == "์ ์๊ธฐ๊ธฐ":
|
380 |
+
prompt += "์ฒจ๋จ ๊ธฐ์ ๊ณผ ๋์์ธ์ด ๋๋ณด์ด๋ ์ ์๊ธฐ๊ธฐ๋ฅผ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
381 |
+
else:
|
382 |
+
prompt += f"๋ํ
์ผ๊ณผ ํ์ง์ด ๋๋ณด์ด๋ {product_category} ์ ํ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง"
|
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 = {
|
|
|
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 |
# ์ ํ๋ ์ต์
์ ๋ฌธ์์ด๋ก ๊ตฌ์ฑ
|
|
|
453 |
else:
|
454 |
return gr.update(choices=["์ ํํ์ธ์"], value="์ ํํ์ธ์")
|
455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
|
457 |
# Gradio ์ธํฐํ์ด์ค
|
458 |
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):
|
|
|
581 |
kr_prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (ํ๊ตญ์ด)", visible=True)
|
582 |
options_summary = gr.Textbox(label="์ ํ๋ ์ต์
์์ฝ", lines=8, visible=True)
|
583 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
# ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ ๋ ๊ฐ๋จํ๊ฒ ์์
|
585 |
def show_background_options():
|
586 |
return ("๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ", "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ",
|
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 |
+
# ๋ค๋ฅธ ๊ธฐ๋ฅ ๋ฒํผ๋ค๋ ๊ฐ๋จํ ๋ฐฉ์์ผ๋ก ์์
|
601 |
+
def hide_background_options(prompt_value):
|
602 |
+
return (prompt_value, "๊ธฐํ",
|
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(
|
617 |
+
fn=lambda: hide_background_options("#1 ์ด๋ฏธ์ง์ [์ค๊ตญ์ด๋ฅผ ๋ชจ๋]๋ฅผ ์ ๊ฑฐํ๋ผ."),
|
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(
|
625 |
+
fn=lambda: hide_background_options("#1์ด๋ฏธ์ง์์ [์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด] ์์[์คํ์ผ๊ณผ ์์์]#2, #3์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์."),
|
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(
|
633 |
+
fn=lambda: hide_background_options("์ด๋ฏธ์ง #1์ ๋ชจ๋ธ์ด ํ์์ ๋ฐ๋ผ ์์ธ๋ ํ์ ์ ์ ๋์ ์ผ๋ก ๋ณํํ ํ, ์ด๋ฏธ์ง #2(๋๋ #3)์ ์ํ์ ์ต๋ํ ์๋ ํํ์ ๋ํ
์ผ์ ์ ์งํ๋ฉด์ ์์ฐ์ค๋ฝ๊ฒ ์ฐฉ์ฉํ ๋ชจ์ต์ ํฉ์ฑํ๋ผ."),
|
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(
|
647 |
fn=update_background_style_options,
|
648 |
inputs=[background_type],
|
649 |
outputs=[background_style]
|
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 |
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
|
|
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 |
|
|
|
703 |
"""
|
704 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
705 |
|
706 |
+
1. ์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์ (#1 ์ด๋ฏธ์ง).
|
707 |
+
2. "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ์ต์
์ด ๋ํ๋ฉ๋๋ค.
|
708 |
+
3. ์ํ๋ช
์ ์
๋ ฅํ๊ณ ์ ํ๊ตฐ, ๋ฐฐ๊ฒฝ ์ ํ, ๋ฐฐ๊ฒฝ ์ธ๋ถ ์คํ์ผ์ ์ ํํ์ธ์.
|
709 |
+
4. ์ถ๊ฐ ์ต์
(์กฐ๋ช
, ์ง๊ฐ, ์๊ฐ, ๋ถ์๊ธฐ)์ ์ ํํ๋ฉด ๋ ์ธ๋ฐํ ๋ฐฐ๊ฒฝ์ ์์ฑํ ์ ์์ต๋๋ค.
|
710 |
+
5. "์ด๋ฏธ์ง ์์ฑ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ ํํ ์ต์
์ ๋ฐ๋ผ ๋ฐฐ๊ฒฝ์ด ๋ณ๊ฒฝ๋ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ฉ๋๋ค.
|
711 |
+
6. ํ๋กฌํํธ ์
๋ ฅ๋์ ์ง์ ํ๋กฌํํธ๋ฅผ ์์ฑํ ์๋ ์์ต๋๋ค.
|
712 |
|
713 |
+
> **ํ**: ์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์์ ์์ฑ๋ LLM ํ๋กฌํํธ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
|
714 |
"""
|
715 |
)
|
716 |
|