Kims12 commited on
Commit
ceef5c6
ยท
verified ยท
1 Parent(s): 03b3471

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +211 -45
app.py CHANGED
@@ -61,7 +61,7 @@ def translate_prompt_to_english(prompt):
61
  logger.exception("๋ฒˆ์—ญ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
62
  return prompt
63
 
64
- def preprocess_prompt(prompt, image1, image2, image3, background_options=None):
65
  """
66
  ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ธฐ๋Šฅ ๋ช…๋ น์„ ํ•ด์„
67
  """
@@ -105,13 +105,30 @@ def preprocess_prompt(prompt, image1, image2, image3, background_options=None):
105
 
106
  elif "5. ๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ" in prompt or "๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ" in prompt:
107
  # ๋ฐฐ๊ฒฝ ์˜ต์…˜์ด ์žˆ์œผ๋ฉด ๊ทธ๊ฒƒ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
108
- if background_options and all(background_options.values()):
109
- product_category = background_options.get("product_category", "์ผ๋ฐ˜ ์ƒํ’ˆ")
110
- background_type = background_options.get("background_type", "์ž์—ฐ ๋ฐฐ๊ฒฝ")
111
- background_style = background_options.get("background_style", "์ˆฒ")
 
 
 
 
 
112
 
113
- # ์ƒํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ํŠนํ™”๋œ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
114
- prompt = f"์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ {product_category} ์ƒํ’ˆ์€ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๋ฉด์„œ, ๋ฐฐ๊ฒฝ์„ {background_type} ์ค‘ {background_style}์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. ์ƒํ’ˆ์˜ ์ƒ‰์ƒ, ์งˆ๊ฐ, ํ˜•ํƒœ๋Š” ์™„๋ฒฝํ•˜๊ฒŒ ๋ณด์กดํ•˜๊ณ  ๊ณ ํ’ˆ์งˆ ์ƒํ’ˆ ์‚ฌ์ง„ ์Šคํƒ€์ผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
 
 
 
 
 
 
 
 
 
 
 
 
115
  else:
116
  prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ํ”ผ์‚ฌ์ฒด๋Š” ์œ ์ง€ํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ™”๋กญ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”."
117
 
@@ -173,7 +190,7 @@ def generate_with_images(prompt, images):
173
  logger.exception("์ด๋ฏธ์ง€ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
174
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
175
 
176
- def process_images_with_prompt(image1, image2, image3, prompt, background_options=None):
177
  """
178
  3๊ฐœ์˜ ์ด๋ฏธ์ง€์™€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ์ตœ์ข… ์˜์–ด ํ”„๋กฌํ”„ํŠธ(final_prompt)๋ฅผ ์ƒ์„ฑํ•œ ํ›„,
179
  API๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
@@ -185,7 +202,7 @@ def process_images_with_prompt(image1, image2, image3, prompt, background_option
185
  return None, "์ ์–ด๋„ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", ""
186
 
187
  if prompt and prompt.strip():
188
- processed_prompt = preprocess_prompt(prompt, image1, image2, image3, background_options)
189
  if re.search("[๊ฐ€-ํžฃ]", processed_prompt):
190
  final_prompt = translate_prompt_to_english(processed_prompt)
191
  else:
@@ -207,35 +224,58 @@ def process_images_with_prompt(image1, image2, image3, prompt, background_option
207
  logger.exception("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
208
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
209
 
210
- def process_and_show_prompt(image1, image2, image3, prompt, product_category=None, background_type=None, background_style=None):
 
211
  try:
212
- # ๋ฐฐ๊ฒฝ ์˜ต์…˜์ด ์žˆ์„ ๊ฒฝ์šฐ ๋”•์…”๋„ˆ๋ฆฌ๋กœ ์ „๋‹ฌ
213
- background_options = None
214
- if all([product_category, background_type, background_style]):
215
- background_options = {
216
- "product_category": product_category,
217
- "background_type": background_type,
218
- "background_style": background_style
219
- }
 
 
 
220
 
221
- result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, background_options)
222
 
223
  # ์„ ํƒ๋œ ์˜ต์…˜์„ ๋ฌธ์ž์—ด๋กœ ๊ตฌ์„ฑ
224
- options_summary = ""
225
- if background_options:
226
- options_summary = f"์ œํ’ˆ๊ตฐ: {product_category}\n๋ฐฐ๊ฒฝ ์œ ํ˜•: {background_type}\n์„ธ๋ถ€ ์Šคํƒ€์ผ: {background_style}"
 
 
 
 
 
 
 
 
 
 
227
 
228
- return result_img, status, final_prompt, options_summary
 
 
 
229
  except Exception as e:
230
  logger.exception("์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
231
- return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt, ""
232
 
233
  # ์„ ํƒ ์˜ต์…˜ ํ‘œ์‹œ/์ˆจ๊น€ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
234
  def toggle_background_options(selection):
235
  if selection == "๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ":
236
- return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
 
 
 
237
  else:
238
- return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
 
 
 
239
 
240
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ฅธ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
241
  def update_background_style_options(background_type):
@@ -248,13 +288,31 @@ def update_background_style_options(background_type):
248
  else:
249
  return gr.update(choices=["์„ ํƒํ•˜์„ธ์š”"], value="์„ ํƒํ•˜์„ธ์š”")
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
252
  with gr.Blocks() as demo:
253
  gr.HTML(
254
  """
255
  <div style="text-align: center; margin-bottom: 1rem;">
256
- <h1>๊ฐ„๋‹จํ•œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ๊ธฐ (์˜ˆ์ œ ํฌํ•จ)</h1>
257
- <p>์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ์•„๋ž˜ ์˜ˆ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์ฒ˜๋ฆฌ๋œ ๊ฒฐ๊ณผ๊ฐ€ down ํด๋”์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.</p>
258
  </div>
259
  """
260
  )
@@ -262,11 +320,12 @@ with gr.Blocks() as demo:
262
  current_selection = gr.State("")
263
 
264
  with gr.Row():
265
- with gr.Column():
266
  with gr.Row():
267
- image1_input = gr.Image(type="pil", label="#1", image_mode="RGB")
268
- image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
269
- image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
 
270
  prompt_input = gr.Textbox(
271
  lines=3,
272
  placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
@@ -277,12 +336,19 @@ with gr.Blocks() as demo:
277
  image_change_btn = gr.Button("์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ")
278
  text_remove_btn = gr.Button("๊ธ€์ž์ง€์šฐ๊ธฐ")
279
  clothes_change_btn = gr.Button("์˜ท๋ฐ”๊พธ๊ธฐ")
280
- background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ")
281
  composite_product_btn = gr.Button("์ƒํ’ˆํ•ฉ์„ฑ")
282
 
283
- # ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ๊ด€๋ จ ์˜ต์…˜๋“ค (๊ธฐ๋ณธ์ ์œผ๋กœ ์ˆจ๊น€ ์ƒํƒœ)
284
- with gr.Row(visible=False) as background_options_row:
285
- gr.HTML("<h3>๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ์˜ต์…˜</h3>")
 
 
 
 
 
 
 
286
 
287
  # ์ œํ’ˆ๊ตฐ ์นดํ…Œ๊ณ ๋ฆฌ ๋“œ๋กญ๋‹ค์šด
288
  product_category = gr.Dropdown(
@@ -308,13 +374,58 @@ with gr.Blocks() as demo:
308
  visible=False
309
  )
310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  submit_btn = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
312
 
313
- with gr.Column():
314
  output_image = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
315
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€")
316
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True)
317
- options_summary = gr.Textbox(label="์„ ํƒ๋œ ์˜ต์…˜", visible=True)
 
318
 
319
  # ์„ ํƒ ์˜ต์…˜ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€ ์—…๋ฐ์ดํŠธ (ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ)
320
  image_change_btn.click(
@@ -328,7 +439,9 @@ with gr.Blocks() as demo:
328
  ).then(
329
  fn=toggle_background_options,
330
  inputs=[current_selection],
331
- outputs=[background_options_row, product_category, background_type, background_style]
 
 
332
  )
333
 
334
  text_remove_btn.click(
@@ -342,7 +455,9 @@ with gr.Blocks() as demo:
342
  ).then(
343
  fn=toggle_background_options,
344
  inputs=[current_selection],
345
- outputs=[background_options_row, product_category, background_type, background_style]
 
 
346
  )
347
 
348
  clothes_change_btn.click(
@@ -356,7 +471,9 @@ with gr.Blocks() as demo:
356
  ).then(
357
  fn=toggle_background_options,
358
  inputs=[current_selection],
359
- outputs=[background_options_row, product_category, background_type, background_style]
 
 
360
  )
361
 
362
  background_change_btn.click(
@@ -370,7 +487,9 @@ with gr.Blocks() as demo:
370
  ).then(
371
  fn=toggle_background_options,
372
  inputs=[current_selection],
373
- outputs=[background_options_row, product_category, background_type, background_style]
 
 
374
  )
375
 
376
  composite_product_btn.click(
@@ -384,7 +503,9 @@ with gr.Blocks() as demo:
384
  ).then(
385
  fn=toggle_background_options,
386
  inputs=[current_selection],
387
- outputs=[background_options_row, product_category, background_type, background_style]
 
 
388
  )
389
 
390
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
@@ -394,13 +515,58 @@ with gr.Blocks() as demo:
394
  outputs=[background_style]
395
  )
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
398
  submit_btn.click(
399
  fn=process_and_show_prompt,
400
- inputs=[image1_input, image2_input, image3_input, prompt_input, product_category, background_type, background_style],
401
- outputs=[output_image, output_text, prompt_display, options_summary],
 
 
402
  )
403
 
 
404
  gr.Markdown(
405
  """
406
  ### ์‚ฌ์šฉ ๋ฐฉ๋ฒ•:
 
61
  logger.exception("๋ฒˆ์—ญ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
62
  return prompt
63
 
64
+ def preprocess_prompt(prompt, image1, image2, image3, bg_options=None):
65
  """
66
  ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ธฐ๋Šฅ ๋ช…๋ น์„ ํ•ด์„
67
  """
 
105
 
106
  elif "5. ๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ" in prompt or "๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ" in prompt:
107
  # ๋ฐฐ๊ฒฝ ์˜ต์…˜์ด ์žˆ์œผ๋ฉด ๊ทธ๊ฒƒ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
108
+ if bg_options and all([bg_options.get("product_name"), bg_options.get("background_type"), bg_options.get("background_style")]):
109
+ product_name = bg_options.get("product_name", "")
110
+ product_category = bg_options.get("product_category", "์ผ๋ฐ˜ ์ƒํ’ˆ")
111
+ background_type = bg_options.get("background_type", "์ž์—ฐ ๋ฐฐ๊ฒฝ")
112
+ background_style = bg_options.get("background_style", "์ˆฒ")
113
+ lighting = bg_options.get("lighting", "์ž์—ฐ๊ด‘")
114
+ texture = bg_options.get("texture", "")
115
+ color_tone = bg_options.get("color_tone", "")
116
+ mood = bg_options.get("mood", "")
117
 
118
+ # ์ƒ์„ธ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
119
+ prompt = f"{product_name} ์ƒํ’ˆ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ {background_type} ์ค‘ {background_style}์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. "
120
+
121
+ # ์ถ”๊ฐ€ ์„ธ๋ถ€ ์‚ฌํ•ญ ํฌํ•จ
122
+ if lighting:
123
+ prompt += f"{lighting} ์กฐ๋ช…์„ ์‚ฌ์šฉํ•˜๊ณ , "
124
+ if texture:
125
+ prompt += f"{texture} ์งˆ๊ฐ์„ ํ‘œํ˜„ํ•˜๋ฉฐ, "
126
+ if color_tone:
127
+ prompt += f"{color_tone} : ์ „์ฒด ์ƒ‰๊ฐ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ , "
128
+ if mood:
129
+ prompt += f"{mood}ํ•œ ๋ถ„์œ„๊ธฐ๋กœ "
130
+
131
+ prompt += f"์—ฐ์ถœํ•ด์ฃผ์„ธ์š”. {product_category} ์ƒํ’ˆ์˜ ์ƒ‰์ƒ, ์งˆ๊ฐ, ํ˜•ํƒœ๋Š” ์™„๋ฒฝํ•˜๊ฒŒ ๋ณด์กดํ•˜๊ณ  ๊ณ ํ’ˆ์งˆ ์ƒํ’ˆ ์‚ฌ์ง„ ์Šคํƒ€์ผ๋กœ ์ œ์ž‘ํ•ด์ฃผ์„ธ์š”."
132
  else:
133
  prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ํ”ผ์‚ฌ์ฒด๋Š” ์œ ์ง€ํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ™”๋กญ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”."
134
 
 
190
  logger.exception("์ด๋ฏธ์ง€ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
191
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
192
 
193
+ def process_images_with_prompt(image1, image2, image3, prompt, bg_options=None):
194
  """
195
  3๊ฐœ์˜ ์ด๋ฏธ์ง€์™€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ์ตœ์ข… ์˜์–ด ํ”„๋กฌํ”„ํŠธ(final_prompt)๋ฅผ ์ƒ์„ฑํ•œ ํ›„,
196
  API๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
 
202
  return None, "์ ์–ด๋„ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", ""
203
 
204
  if prompt and prompt.strip():
205
+ processed_prompt = preprocess_prompt(prompt, image1, image2, image3, bg_options)
206
  if re.search("[๊ฐ€-ํžฃ]", processed_prompt):
207
  final_prompt = translate_prompt_to_english(processed_prompt)
208
  else:
 
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 = {
232
+ "product_name": product_name,
233
+ "product_category": product_category,
234
+ "background_type": background_type,
235
+ "background_style": background_style,
236
+ "lighting": lighting,
237
+ "texture": texture,
238
+ "color_tone": color_tone,
239
+ "mood": mood
240
+ }
241
 
242
+ result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, bg_options)
243
 
244
  # ์„ ํƒ๋œ ์˜ต์…˜์„ ๋ฌธ์ž์—ด๋กœ ๊ตฌ์„ฑ
245
+ options_summary = f"์ƒํ’ˆ๋ช…: {product_name}\n"
246
+ options_summary += f"์ œํ’ˆ๊ตฐ: {product_category}\n"
247
+ options_summary += f"๋ฐฐ๊ฒฝ ์œ ํ˜•: {background_type}\n"
248
+ options_summary += f"์„ธ๋ถ€ ์Šคํƒ€์ผ: {background_style}\n"
249
+
250
+ if lighting:
251
+ options_summary += f"์กฐ๋ช…: {lighting}\n"
252
+ if texture:
253
+ options_summary += f"๋ฐฐ๊ฒฝ ์งˆ๊ฐ: {texture}\n"
254
+ if color_tone:
255
+ options_summary += f"์ƒ‰๊ฐ: {color_tone}\n"
256
+ if mood:
257
+ options_summary += f"๋ถ„์œ„๊ธฐ: {mood}\n"
258
 
259
+ # ํ•œ๊ตญ์–ด์™€ ์˜์–ด ํ”„๋กฌํ”„ํŠธ ๋น„๊ต๋ฅผ ์œ„ํ•ด ์›๋ณธ ํ”„๋กฌํ”„ํŠธ ํ™•์ธ
260
+ kr_prompt = preprocess_prompt(prompt, image1, image2, image3, bg_options)
261
+
262
+ return result_img, status, final_prompt, options_summary, kr_prompt
263
  except Exception as e:
264
  logger.exception("์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
265
+ return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt, "", ""
266
 
267
  # ์„ ํƒ ์˜ต์…˜ ํ‘œ์‹œ/์ˆจ๊น€ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
268
  def toggle_background_options(selection):
269
  if selection == "๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ":
270
+ return (gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
271
+ gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
272
+ gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
273
+ gr.update(visible=True))
274
  else:
275
+ return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
276
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
277
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
278
+ gr.update(visible=False))
279
 
280
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ฅธ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
281
  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:
301
+ preview += f"๋ฐฐ๊ฒฝ ์งˆ๊ฐ: {texture}\n"
302
+ if color_tone:
303
+ preview += f"์ƒ‰๊ฐ: {color_tone}\n"
304
+ if mood:
305
+ preview += f"๋ถ„์œ„๊ธฐ: {mood}\n"
306
+
307
+ return preview
308
+
309
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
310
  with gr.Blocks() as demo:
311
  gr.HTML(
312
  """
313
  <div style="text-align: center; margin-bottom: 1rem;">
314
+ <h1>์ด์ปค๋จธ์Šค ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ์ƒ์„ฑ๊ธฐ</h1>
315
+ <p>์ƒํ’ˆ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ์›ํ•˜๋Š” ๋ฐฐ๊ฒฝ ์˜ต์…˜์„ ์„ ํƒํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜์„ธ์š”.</p>
316
  </div>
317
  """
318
  )
 
320
  current_selection = gr.State("")
321
 
322
  with gr.Row():
323
+ with gr.Column(scale=1):
324
  with gr.Row():
325
+ image1_input = gr.Image(type="pil", label="#1 ์ƒํ’ˆ ์ด๋ฏธ์ง€", image_mode="RGB")
326
+ image2_input = gr.Image(type="pil", label="#2 (์„ ํƒ์‚ฌํ•ญ)", image_mode="RGB")
327
+ image3_input = gr.Image(type="pil", label="#3 (์„ ํƒ์‚ฌํ•ญ)", image_mode="RGB")
328
+
329
  prompt_input = gr.Textbox(
330
  lines=3,
331
  placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
 
336
  image_change_btn = gr.Button("์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ")
337
  text_remove_btn = gr.Button("๊ธ€์ž์ง€์šฐ๊ธฐ")
338
  clothes_change_btn = gr.Button("์˜ท๋ฐ”๊พธ๊ธฐ")
339
+ background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ", variant="primary")
340
  composite_product_btn = gr.Button("์ƒํ’ˆํ•ฉ์„ฑ")
341
 
342
+ # ๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ๊ด€๋ จ ์„น์…˜ (๊ธฐ๋ณธ์ ์œผ๋กœ ์ˆจ๊น€ ์ƒํƒœ)
343
+ with gr.Row(visible=False) as background_header:
344
+ gr.HTML("<h3 style='margin-top: 20px; margin-bottom: 10px; width: 100%; text-align: center;'>๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ ์˜ต์…˜</h3>")
345
+
346
+ # ์ƒํ’ˆ๋ช… ์ž…๋ ฅ
347
+ product_name = gr.Textbox(
348
+ label="์ƒํ’ˆ๋ช… ์ž…๋ ฅ",
349
+ placeholder="์ƒํ’ˆ๋ช…์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”",
350
+ visible=False
351
+ )
352
 
353
  # ์ œํ’ˆ๊ตฐ ์นดํ…Œ๊ณ ๋ฆฌ ๋“œ๋กญ๋‹ค์šด
354
  product_category = gr.Dropdown(
 
374
  visible=False
375
  )
376
 
377
+ # ์ถ”๊ฐ€ ์„ ํƒ ์˜ต์…˜ ํ—ค๋”
378
+ with gr.Row(visible=False) as additional_header:
379
+ gr.HTML("<h4 style='margin-top: 15px; margin-bottom: 10px; width: 100%; text-align: center;'>์ถ”๊ฐ€ ์„ ํƒ ์˜ต์…˜</h4>")
380
+
381
+ # ์กฐ๋ช… ๋“œ๋กญ๋‹ค์šด
382
+ lighting = gr.Dropdown(
383
+ choices=["์ž์—ฐ๊ด‘", "๋”ฐ๋œปํ•œ ์กฐ๋ช…", "๊ทธ๋ฆผ์ž ์žˆ๋Š” ์กฐ๋ช…", "๋ฏธ๋‹ˆ๋ฉ€ ์กฐ๋ช…"],
384
+ label="์กฐ๋ช… ์„ ํƒ",
385
+ value="์ž์—ฐ๊ด‘",
386
+ visible=False
387
+ )
388
+
389
+ # ๋ฐฐ๊ฒฝ ์งˆ๊ฐ ๋“œ๋กญ๋‹ค์šด
390
+ texture = gr.Dropdown(
391
+ choices=["ํฐ ๋ฒฝ", "๋Œ€๋ฆฌ์„", "๋‚˜๋ฌด", "๋ฒฝ๋Œ", "ํฐ ์ฒœ", "์‹œ๋ฉ˜ํŠธ"],
392
+ label="๋ฐฐ๊ฒฝ ์งˆ๊ฐ ์„ ํƒ",
393
+ value="",
394
+ visible=False
395
+ )
396
+
397
+ # ์ƒ‰๊ฐ ๋“œ๋กญ๋‹ค์šด
398
+ color_tone = gr.Dropdown(
399
+ choices=["ํ™”์ดํŠธ ํ†ค", "๋ธ”๋ฃจ ํ†ค", "๋”ฐ๋œปํ•œ ์ƒ‰์ƒ", "๋ชจ๋…ธํ†ค", "ํŒŒ์Šคํ…”"],
400
+ label="์ƒ‰๊ฐ ์„ ํƒ",
401
+ value="",
402
+ visible=False
403
+ )
404
+
405
+ # ๋ถ„์œ„๊ธฐ ๋“œ๋กญ๋‹ค์šด
406
+ mood = gr.Dropdown(
407
+ choices=["ํฌ๊ทผํ•œ", "์‹ฌํ”Œํ•œ", "๋ชจ๋˜ํ•œ", "๋‚ด์ถ”๋Ÿด", "๋ฏธ๋‹ˆ๋ฉ€"],
408
+ label="๋ถ„์œ„๊ธฐ ์„ ํƒ",
409
+ value="",
410
+ visible=False
411
+ )
412
+
413
+ # ์„ ํƒ ๋‚ด์šฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
414
+ selection_preview = gr.Textbox(
415
+ label="์„ ํƒ ๋‚ด์šฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ",
416
+ lines=8,
417
+ readonly=True,
418
+ visible=False
419
+ )
420
+
421
  submit_btn = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
422
 
423
+ with gr.Column(scale=1):
424
  output_image = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
425
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€")
426
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True)
427
+ kr_prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (ํ•œ๊ตญ์–ด)", visible=True)
428
+ options_summary = gr.Textbox(label="์„ ํƒ๋œ ์˜ต์…˜ ์š”์•ฝ", lines=8, visible=True)
429
 
430
  # ์„ ํƒ ์˜ต์…˜ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€ ์—…๋ฐ์ดํŠธ (ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ)
431
  image_change_btn.click(
 
439
  ).then(
440
  fn=toggle_background_options,
441
  inputs=[current_selection],
442
+ outputs=[background_header, product_name, product_category, background_type,
443
+ background_style, additional_header, lighting, texture, color_tone,
444
+ mood, selection_preview]
445
  )
446
 
447
  text_remove_btn.click(
 
455
  ).then(
456
  fn=toggle_background_options,
457
  inputs=[current_selection],
458
+ outputs=[background_header, product_name, product_category, background_type,
459
+ background_style, additional_header, lighting, texture, color_tone,
460
+ mood, selection_preview]
461
  )
462
 
463
  clothes_change_btn.click(
 
471
  ).then(
472
  fn=toggle_background_options,
473
  inputs=[current_selection],
474
+ outputs=[background_header, product_name, product_category, background_type,
475
+ background_style, additional_header, lighting, texture, color_tone,
476
+ mood, selection_preview]
477
  )
478
 
479
  background_change_btn.click(
 
487
  ).then(
488
  fn=toggle_background_options,
489
  inputs=[current_selection],
490
+ outputs=[background_header, product_name, product_category, background_type,
491
+ background_style, additional_header, lighting, texture, color_tone,
492
+ mood, selection_preview]
493
  )
494
 
495
  composite_product_btn.click(
 
503
  ).then(
504
  fn=toggle_background_options,
505
  inputs=[current_selection],
506
+ outputs=[background_header, product_name, product_category, background_type,
507
+ background_style, additional_header, lighting, texture, color_tone,
508
+ mood, selection_preview]
509
  )
510
 
511
  # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
 
515
  outputs=[background_style]
516
  )
517
 
518
+ # ์„ ํƒ ๋‚ด์šฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์—…๋ฐ์ดํŠธ (๋ชจ๋“  ์„ ํƒ ์ปดํฌ๋„ŒํŠธ์˜ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ์— ์—ฐ๊ฒฐ)
519
+ product_name.change(
520
+ fn=update_preview,
521
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
522
+ outputs=[selection_preview]
523
+ )
524
+ product_category.change(
525
+ fn=update_preview,
526
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
527
+ outputs=[selection_preview]
528
+ )
529
+ background_type.change(
530
+ fn=update_preview,
531
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
532
+ outputs=[selection_preview]
533
+ )
534
+ background_style.change(
535
+ fn=update_preview,
536
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
537
+ outputs=[selection_preview]
538
+ )
539
+ lighting.change(
540
+ fn=update_preview,
541
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
542
+ outputs=[selection_preview]
543
+ )
544
+ texture.change(
545
+ fn=update_preview,
546
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
547
+ outputs=[selection_preview]
548
+ )
549
+ color_tone.change(
550
+ fn=update_preview,
551
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
552
+ outputs=[selection_preview]
553
+ )
554
+ mood.change(
555
+ fn=update_preview,
556
+ inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
557
+ outputs=[selection_preview]
558
+ )
559
+
560
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
561
  submit_btn.click(
562
  fn=process_and_show_prompt,
563
+ inputs=[image1_input, image2_input, image3_input, prompt_input,
564
+ product_name, product_category, background_type, background_style,
565
+ lighting, texture, color_tone, mood],
566
+ outputs=[output_image, output_text, prompt_display, options_summary, kr_prompt_display],
567
  )
568
 
569
+
570
  gr.Markdown(
571
  """
572
  ### ์‚ฌ์šฉ ๋ฐฉ๋ฒ•: