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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -14
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):
65
  """
66
  ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ธฐ๋Šฅ ๋ช…๋ น์„ ํ•ด์„
67
  """
@@ -103,8 +103,17 @@ def preprocess_prompt(prompt, image1, image2, image3):
103
  elif "4. ์˜ท๋ฐ”๊พธ๊ธฐ" in prompt:
104
  prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์ธ๋ฌผ ์˜์ƒ์„ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์˜์ƒ์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. ์˜์ƒ์˜ ์Šคํƒ€์ผ๊ณผ ์ƒ‰์ƒ์€ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ๋”ฐ๋ฅด๋˜, ์‹ ์ฒด ๋น„์œจ๊ณผ ํฌ์ฆˆ๋Š” ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ์œ ์ง€ํ•ด์ฃผ์„ธ์š”."
105
 
106
- elif "5. ๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ" in prompt:
107
- prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ํ”ผ์‚ฌ์ฒด๋Š” ์œ ์ง€ํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ™”๋กญ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”."
 
 
 
 
 
 
 
 
 
108
 
109
  elif "์ƒํ’ˆํ•ฉ์„ฑ" in prompt:
110
  prompt = "#1 ์ƒํ’ˆ ์ด๋ฏธ์ง€์— #2 ์ด๋ฏธ์ง€ ๋˜๋Š” #3 ์ด๋ฏธ์ง€๋ฅผ [๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๊ณ , ํŠนํžˆ ์ƒํ’ˆ์ด ๋‹๋ณด์ด๋„๋ก ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉํ•˜์—ฌ]์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•˜๋ผ."
@@ -164,7 +173,7 @@ def generate_with_images(prompt, images):
164
  logger.exception("์ด๋ฏธ์ง€ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
165
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
166
 
167
- def process_images_with_prompt(image1, image2, image3, prompt):
168
  """
169
  3๊ฐœ์˜ ์ด๋ฏธ์ง€์™€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ์ตœ์ข… ์˜์–ด ํ”„๋กฌํ”„ํŠธ(final_prompt)๋ฅผ ์ƒ์„ฑํ•œ ํ›„,
170
  API๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
@@ -176,7 +185,7 @@ def process_images_with_prompt(image1, image2, image3, prompt):
176
  return None, "์ ์–ด๋„ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", ""
177
 
178
  if prompt and prompt.strip():
179
- processed_prompt = preprocess_prompt(prompt, image1, image2, image3)
180
  if re.search("[๊ฐ€-ํžฃ]", processed_prompt):
181
  final_prompt = translate_prompt_to_english(processed_prompt)
182
  else:
@@ -198,13 +207,46 @@ def process_images_with_prompt(image1, image2, image3, prompt):
198
  logger.exception("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
199
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
200
 
201
- def process_and_show_prompt(image1, image2, image3, prompt):
202
  try:
203
- result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt)
204
- return result_img, status, final_prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  except Exception as e:
206
  logger.exception("์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
207
- return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
210
  with gr.Blocks() as demo:
@@ -217,6 +259,8 @@ with gr.Blocks() as demo:
217
  """
218
  )
219
 
 
 
220
  with gr.Row():
221
  with gr.Column():
222
  with gr.Row():
@@ -228,50 +272,133 @@ with gr.Blocks() as demo:
228
  placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
229
  label="ํ”„๋กฌํ”„ํŠธ (์„ ํƒ ์‚ฌํ•ญ)"
230
  )
 
231
  with gr.Row():
232
  image_change_btn = gr.Button("์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ")
233
  text_remove_btn = gr.Button("๊ธ€์ž์ง€์šฐ๊ธฐ")
234
  clothes_change_btn = gr.Button("์˜ท๋ฐ”๊พธ๊ธฐ")
235
  background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ")
236
- # ๋ฒ„ํŠผ ๋ผ๋ฒจ๊ณผ ํด๋ฆญ ์‹œ ๋ฐ˜ํ™˜๋˜๋Š” ํ”„๋กฌํ”„ํŠธ ์ˆ˜์ •
237
  composite_product_btn = gr.Button("์ƒํ’ˆํ•ฉ์„ฑ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  submit_btn = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
 
239
  with gr.Column():
240
  output_image = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
241
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€")
242
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True)
 
243
 
244
  # ์„ ํƒ ์˜ต์…˜ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€ ์—…๋ฐ์ดํŠธ (ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ)
245
  image_change_btn.click(
246
  fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ [๋‹ค๋ฅธ ๋ชจ์Šต]์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ.",
247
  inputs=[],
248
  outputs=prompt_input
 
 
 
 
 
 
 
 
249
  )
 
250
  text_remove_btn.click(
251
  fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ [์ค‘๊ตญ์–ด๋ฅผ ๋ชจ๋‘]๋ฅผ ์ œ๊ฑฐํ•˜๋ผ.",
252
  inputs=[],
253
  outputs=prompt_input
 
 
 
 
 
 
 
 
254
  )
 
255
  clothes_change_btn.click(
256
  fn=lambda: "#1์ด๋ฏธ์ง€์—์„œ [์‹ ์ฒด ๋น„์œจ๊ณผ ํฌ์ฆˆ๋Š” ์œ ์ง€ํ•œ ์ฒด] ์˜์ƒ[์Šคํƒ€์ผ๊ณผ ์ƒ‰์ƒ์„]#2, #3์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.",
257
  inputs=[],
258
  outputs=prompt_input
 
 
 
 
 
 
 
 
259
  )
 
260
  background_change_btn.click(
261
- fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ #2 ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ.",
262
  inputs=[],
263
  outputs=prompt_input
 
 
 
 
 
 
 
 
264
  )
 
265
  composite_product_btn.click(
266
  fn=lambda: "์ด๋ฏธ์ง€ #1์˜ ๋ชจ๋ธ์ด ํ•„์š”์— ๋”ฐ๋ผ ์ž์„ธ๋‚˜ ํ‘œ์ •์„ ์œ ๋™์ ์œผ๋กœ ๋ณ€ํ˜•ํ•œ ํ›„, ์ด๋ฏธ์ง€ #2(๋˜๋Š” #3)์˜ ์ƒํ’ˆ์„ ์ตœ๋Œ€ํ•œ ์›๋ž˜ ํ˜•ํƒœ์™€ ๋””ํ…Œ์ผ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ฐฉ์šฉํ•œ ๋ชจ์Šต์„ ํ•ฉ์„ฑํ•˜๋ผ.",
267
  inputs=[],
268
  outputs=prompt_input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  )
270
 
 
271
  submit_btn.click(
272
  fn=process_and_show_prompt,
273
- inputs=[image1_input, image2_input, image3_input, prompt_input],
274
- outputs=[output_image, output_text, prompt_display],
275
  )
276
 
277
  gr.Markdown(
@@ -281,10 +408,11 @@ with gr.Blocks() as demo:
281
  1. **์ž๋™ ํ•ฉ์„ฑ**: ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋น„์›Œ๋‘๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.
282
  2. **์ด๋ฏธ์ง€ ์ฐธ์กฐ**: #1, #2, #3์œผ๋กœ ๊ฐ ์ด๋ฏธ์ง€๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
283
  3. **์„ ํƒ ์˜ต์…˜**: ์œ„์˜ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€์— ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ๋กœ ์ž…๋ ฅํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
 
284
 
285
  > **ํŒ**: ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
286
  """
287
  )
288
 
289
  if __name__ == "__main__":
290
- demo.launch(share=True)
 
61
  logger.exception("๋ฒˆ์—ญ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
62
  return prompt
63
 
64
+ def preprocess_prompt(prompt, image1, image2, image3, background_options=None):
65
  """
66
  ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ธฐ๋Šฅ ๋ช…๋ น์„ ํ•ด์„
67
  """
 
103
  elif "4. ์˜ท๋ฐ”๊พธ๊ธฐ" in prompt:
104
  prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์ธ๋ฌผ ์˜์ƒ์„ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์˜ ์˜์ƒ์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”. ์˜์ƒ์˜ ์Šคํƒ€์ผ๊ณผ ์ƒ‰์ƒ์€ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ๋”ฐ๋ฅด๋˜, ์‹ ์ฒด ๋น„์œจ๊ณผ ํฌ์ฆˆ๋Š” ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ์œ ์ง€ํ•ด์ฃผ์„ธ์š”."
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
 
118
  elif "์ƒํ’ˆํ•ฉ์„ฑ" in prompt:
119
  prompt = "#1 ์ƒํ’ˆ ์ด๋ฏธ์ง€์— #2 ์ด๋ฏธ์ง€ ๋˜๋Š” #3 ์ด๋ฏธ์ง€๋ฅผ [๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๊ณ , ํŠนํžˆ ์ƒํ’ˆ์ด ๋‹๋ณด์ด๋„๋ก ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉํ•˜์—ฌ]์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•˜๋ผ."
 
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
  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
  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):
242
+ if background_type == "์ž์—ฐ ๋ฐฐ๊ฒฝ":
243
+ return gr.update(choices=["์ˆฒ", "ํ•ด๋ณ€", "์‚ฐ", "๋“คํŒ", "๊ณ„๊ณก", "์—ด๋Œ€ ์ •์›", "์‚ฌ๋ง‰", "๋ˆˆ ํ’๊ฒฝ"], value="์ˆฒ")
244
+ elif background_type == "์‹ค๋‚ด ๋ฐฐ๊ฒฝ":
245
+ return gr.update(choices=["๊ฑฐ์‹ค", "์ฃผ๋ฐฉ", "์„œ์žฌ", "ํ™”์žฅ๋Œ€", "ํ˜ธํ…” ๋กœ๋น„", "์นดํŽ˜", "๋ฏธ๋‹ˆ๋ฉ€ ๊ณต๊ฐ„"], value="๊ฑฐ์‹ค")
246
+ elif background_type == "ํŠน์ˆ˜ ๋ฐฐ๊ฒฝ":
247
+ return gr.update(choices=["๋„์‹œ ํ’๊ฒฝ", "๋ฃจํ”„ํƒ‘", "ํ•ด์•ˆ๊ฐ€", "๋ชจ๋˜ ์ŠคํŠœ๋””์˜ค", "๋นˆํ‹ฐ์ง€ ๊ณต๊ฐ„", "๋ฏธ๋‹ˆ์–ด์ฒ˜ ๊ณต๊ฐ„"], value="๋„์‹œ ํ’๊ฒฝ")
248
+ else:
249
+ return gr.update(choices=["์„ ํƒํ•˜์„ธ์š”"], value="์„ ํƒํ•˜์„ธ์š”")
250
 
251
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
252
  with gr.Blocks() as demo:
 
259
  """
260
  )
261
 
262
+ current_selection = gr.State("")
263
+
264
  with gr.Row():
265
  with gr.Column():
266
  with gr.Row():
 
272
  placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
273
  label="ํ”„๋กฌํ”„ํŠธ (์„ ํƒ ์‚ฌํ•ญ)"
274
  )
275
+
276
  with gr.Row():
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(
289
+ choices=["ํ™”์žฅํ’ˆ", "๊ฐ€๋ฐฉ", "์•ก์„ธ์„œ๋ฆฌ", "๋ณด์„๋ฅ˜", "ํ™ˆ ๋ฐ์ฝ”", "์‹ ๋ฐœ", "์˜๋ฅ˜", "์ฃผ๋ฐฉ์šฉํ’ˆ", "์ „์ž๊ธฐ๊ธฐ", "๊ธฐํƒ€"],
290
+ label="์ œํ’ˆ๊ตฐ ์„ ํƒ",
291
+ value="๊ธฐํƒ€",
292
+ visible=False
293
+ )
294
+
295
+ # ๋ฐฐ๊ฒฝ ์œ ํ˜• ๋“œ๋กญ๋‹ค์šด
296
+ background_type = gr.Dropdown(
297
+ choices=["์ž์—ฐ ๋ฐฐ๊ฒฝ", "์‹ค๋‚ด ๋ฐฐ๊ฒฝ", "ํŠน์ˆ˜ ๋ฐฐ๊ฒฝ"],
298
+ label="๋ฐฐ๊ฒฝ ์œ ํ˜• ์„ ํƒ",
299
+ value="์ž์—ฐ ๋ฐฐ๊ฒฝ",
300
+ visible=False
301
+ )
302
+
303
+ # ๋ฐฐ๊ฒฝ ์„ธ๋ถ€ ์Šคํƒ€์ผ ๋“œ๋กญ๋‹ค์šด (๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ๋™์  ๋ณ€๊ฒฝ)
304
+ background_style = gr.Dropdown(
305
+ choices=["์ˆฒ", "ํ•ด๋ณ€", "์‚ฐ", "๋“คํŒ", "๊ณ„๊ณก", "์—ด๋Œ€ ์ •์›", "์‚ฌ๋ง‰", "๋ˆˆ ํ’๊ฒฝ"],
306
+ label="๋ฐฐ๊ฒฝ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์„ ํƒ",
307
+ value="์ˆฒ",
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(
321
  fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ [๋‹ค๋ฅธ ๋ชจ์Šต]์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ.",
322
  inputs=[],
323
  outputs=prompt_input
324
+ ).then(
325
+ fn=lambda: "์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ",
326
+ inputs=[],
327
+ outputs=current_selection
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(
335
  fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ [์ค‘๊ตญ์–ด๋ฅผ ๋ชจ๋‘]๋ฅผ ์ œ๊ฑฐํ•˜๋ผ.",
336
  inputs=[],
337
  outputs=prompt_input
338
+ ).then(
339
+ fn=lambda: "๊ธ€์ž์ง€์šฐ๊ธฐ",
340
+ inputs=[],
341
+ outputs=current_selection
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(
349
  fn=lambda: "#1์ด๋ฏธ์ง€์—์„œ [์‹ ์ฒด ๋น„์œจ๊ณผ ํฌ์ฆˆ๋Š” ์œ ์ง€ํ•œ ์ฒด] ์˜์ƒ[์Šคํƒ€์ผ๊ณผ ์ƒ‰์ƒ์„]#2, #3์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.",
350
  inputs=[],
351
  outputs=prompt_input
352
+ ).then(
353
+ fn=lambda: "์˜ท๋ฐ”๊พธ๊ธฐ",
354
+ inputs=[],
355
+ outputs=current_selection
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(
363
+ fn=lambda: "๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ",
364
  inputs=[],
365
  outputs=prompt_input
366
+ ).then(
367
+ fn=lambda: "๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ",
368
+ inputs=[],
369
+ outputs=current_selection
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(
377
  fn=lambda: "์ด๋ฏธ์ง€ #1์˜ ๋ชจ๋ธ์ด ํ•„์š”์— ๋”ฐ๋ผ ์ž์„ธ๋‚˜ ํ‘œ์ •์„ ์œ ๋™์ ์œผ๋กœ ๋ณ€ํ˜•ํ•œ ํ›„, ์ด๋ฏธ์ง€ #2(๋˜๋Š” #3)์˜ ์ƒํ’ˆ์„ ์ตœ๋Œ€ํ•œ ์›๋ž˜ ํ˜•ํƒœ์™€ ๋””ํ…Œ์ผ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ฐฉ์šฉํ•œ ๋ชจ์Šต์„ ํ•ฉ์„ฑํ•˜๋ผ.",
378
  inputs=[],
379
  outputs=prompt_input
380
+ ).then(
381
+ fn=lambda: "์ƒํ’ˆํ•ฉ์„ฑ",
382
+ inputs=[],
383
+ outputs=current_selection
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
+ # ๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ์„ธ๋ถ€ ์Šคํƒ€์ผ ์˜ต์…˜ ์—…๋ฐ์ดํŠธ
391
+ background_type.change(
392
+ fn=update_background_style_options,
393
+ inputs=[background_type],
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(
 
408
  1. **์ž๋™ ํ•ฉ์„ฑ**: ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋น„์›Œ๋‘๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.
409
  2. **์ด๋ฏธ์ง€ ์ฐธ์กฐ**: #1, #2, #3์œผ๋กœ ๊ฐ ์ด๋ฏธ์ง€๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
410
  3. **์„ ํƒ ์˜ต์…˜**: ์œ„์˜ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€์— ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ๋กœ ์ž…๋ ฅํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
411
+ 4. **๋ฐฐ๊ฒฝ ๋ณ€๊ฒฝ**: ๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์ถ”๊ฐ€ ์˜ต์…˜์ด ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
412
 
413
  > **ํŒ**: ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
414
  """
415
  )
416
 
417
  if __name__ == "__main__":
418
+ demo.launch(share=True)