Kims12 commited on
Commit
e52aef4
ยท
verified ยท
1 Parent(s): b32830a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -144,7 +144,7 @@ def process_images_with_prompt(image1, prompt, variation_index=0, max_retries=3)
144
  valid_images = [img for img in images if img is not None]
145
  if not valid_images:
146
  return None, "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", ""
147
- # ์ด๋ฏธ Gemini API๋กœ ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ๋Š” ์˜์–ด์ด๋ฏ€๋กœ ์ถ”๊ฐ€ ๋ฒˆ์—ญ์€ ์ƒ๋žต
148
  final_prompt = prompt.strip()
149
  result_img, status = generate_with_images(final_prompt, valid_images, variation_index)
150
  if result_img is not None:
@@ -187,7 +187,6 @@ NATURE_BACKGROUNDS = load_background_json("nature_backgrounds.json")
187
  INDOOR_BACKGROUNDS = load_background_json("indoor_backgrounds.json")
188
  ABSTRACT_BACKGROUNDS = load_background_json("abstract_backgrounds.json")
189
 
190
- # ๋ฐฐ๊ฒฝ์ด ๋กœ๋“œ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
191
  if not SIMPLE_BACKGROUNDS:
192
  SIMPLE_BACKGROUNDS = {"ํ™”์ดํŠธ ๋ฐฐ๊ฒฝ": "white background"}
193
  if not STUDIO_BACKGROUNDS:
@@ -314,6 +313,13 @@ def get_selected_background_info(bg_type, simple, studio, nature, indoor, abstra
314
  "english": "white background"
315
  }
316
 
 
 
 
 
 
 
 
317
  # ------------------- ํ†ตํ•ฉ ๊ธฐ๋Šฅ: ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ›„ ์ด๋ฏธ์ง€ ์ƒ์„ฑ -------------------
318
  def generate_product_image(image, bg_type, simple, studio, nature, indoor, abstract, product_name, additional_info):
319
  if image is None:
@@ -331,15 +337,17 @@ def generate_product_image(image, bg_type, simple, studio, nature, indoor, abstr
331
  "ํ‚ค ๋ฐœ๊ธ‰: https://makersuite.google.com/"
332
  )
333
  return None, warning_msg, warning_msg
334
- # ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ์ฐฝ์— ๋ฐ˜์˜ํ•˜๊ณ , ๊ทธ ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
335
- result_image, status, final_prompt = process_images_with_prompt(image, generated_prompt, 0)
 
 
336
  return result_image, status, final_prompt
337
 
338
  # ------------------- Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ -------------------
339
  def create_app():
340
- with gr.Blocks(title="๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ") as demo:
341
- gr.Markdown("# ๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ")
342
- gr.Markdown("์ƒํ’ˆ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ , ์ œํ’ˆ๋ช… ๋ฐ ๋ฐฐ๊ฒฝ ์˜ต์…˜๊ณผ ์ถ”๊ฐ€ ์š”์ฒญ์‚ฌํ•ญ์„ ์ž…๋ ฅํ•˜๋ฉด Gemini API๋ฅผ ์ด์šฉํ•˜์—ฌ ์˜์–ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ทธ ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.")
343
  with gr.Row():
344
  with gr.Column(scale=1):
345
  product_name = gr.Textbox(label="์ƒํ’ˆ๋ช… (ํ•œ๊ตญ์–ด ์ž…๋ ฅ)", placeholder="์˜ˆ: ์Šคํ‚จ์ผ€์–ด ํŠœ๋ธŒ, ํ…€๋ธ”๋Ÿฌ ๋“ฑ", interactive=True)
@@ -389,7 +397,6 @@ def create_app():
389
  lines=3,
390
  interactive=True
391
  )
392
- # ๋ฐฐ๊ฒฝ ์œ ํ˜• ๋ณ€๊ฒฝ ์‹œ ํ•ด๋‹น ๋“œ๋กญ๋‹ค์šด๋งŒ ๋ณด์ด๋„๋ก ์—…๋ฐ์ดํŠธ
393
  def update_dropdowns(bg_type):
394
  return {
395
  simple_dropdown: gr.update(visible=(bg_type == "์‹ฌํ”Œ ๋ฐฐ๊ฒฝ")),
 
144
  valid_images = [img for img in images if img is not None]
145
  if not valid_images:
146
  return None, "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", ""
147
+ # ํ”„๋กฌํ”„ํŠธ๋Š” ์ด๋ฏธ Gemini API๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ ์˜์–ด ํ…์ŠคํŠธ๋ผ ๊ฐ€์ •
148
  final_prompt = prompt.strip()
149
  result_img, status = generate_with_images(final_prompt, valid_images, variation_index)
150
  if result_img is not None:
 
187
  INDOOR_BACKGROUNDS = load_background_json("indoor_backgrounds.json")
188
  ABSTRACT_BACKGROUNDS = load_background_json("abstract_backgrounds.json")
189
 
 
190
  if not SIMPLE_BACKGROUNDS:
191
  SIMPLE_BACKGROUNDS = {"ํ™”์ดํŠธ ๋ฐฐ๊ฒฝ": "white background"}
192
  if not STUDIO_BACKGROUNDS:
 
313
  "english": "white background"
314
  }
315
 
316
+ # --- ํ”„๋กฌํ”„ํŠธ์—์„œ ์›ํ•˜๋Š” ๋ถ€๋ถ„(ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ ๋ธ”๋ก)๋งŒ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜ ---
317
+ def filter_prompt_only(prompt):
318
+ # ์˜ˆ์‹œ๋กœ, ์„ค๋ช… ๋ถ€๋ถ„("Explanation of Key Elements:")์ด ์žˆ๋‹ค๋ฉด ๊ทธ ์•ž๋ถ€๋ถ„๋งŒ ์‚ฌ์šฉ
319
+ if "Explanation of Key Elements:" in prompt:
320
+ return prompt.split("Explanation of Key Elements:")[0].strip()
321
+ return prompt.strip()
322
+
323
  # ------------------- ํ†ตํ•ฉ ๊ธฐ๋Šฅ: ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ›„ ์ด๋ฏธ์ง€ ์ƒ์„ฑ -------------------
324
  def generate_product_image(image, bg_type, simple, studio, nature, indoor, abstract, product_name, additional_info):
325
  if image is None:
 
337
  "ํ‚ค ๋ฐœ๊ธ‰: https://makersuite.google.com/"
338
  )
339
  return None, warning_msg, warning_msg
340
+ # ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ์—์„œ ์˜ค์ง ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ ๋ธ”๋ก๋งŒ ์ถ”์ถœ
341
+ final_prompt = filter_prompt_only(generated_prompt)
342
+ # ์ถ”์ถœ๋œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ์ด๋ฏธ์ง€ ์ƒ์„ฑ
343
+ result_image, status = process_images_with_prompt(image, final_prompt, 0)[:2]
344
  return result_image, status, final_prompt
345
 
346
  # ------------------- Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ -------------------
347
  def create_app():
348
+ with gr.Blocks(title="๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ") as demo:
349
+ gr.Markdown("# ๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ")
350
+ gr.Markdown("์ƒํ’ˆ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ , ์ œํ’ˆ๋ช…, ๋ฐฐ๊ฒฝ ์˜ต์…˜, ์ถ”๊ฐ€ ์š”์ฒญ์‚ฌํ•ญ์„ ์ž…๋ ฅํ•˜๋ฉด Gemini API๋ฅผ ํ†ตํ•ด ์˜์–ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ทธ ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ๋Š” ์˜ค์ง ์•„๋ž˜์˜ Midjourney ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ๋งŒ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.")
351
  with gr.Row():
352
  with gr.Column(scale=1):
353
  product_name = gr.Textbox(label="์ƒํ’ˆ๋ช… (ํ•œ๊ตญ์–ด ์ž…๋ ฅ)", placeholder="์˜ˆ: ์Šคํ‚จ์ผ€์–ด ํŠœ๋ธŒ, ํ…€๋ธ”๋Ÿฌ ๋“ฑ", interactive=True)
 
397
  lines=3,
398
  interactive=True
399
  )
 
400
  def update_dropdowns(bg_type):
401
  return {
402
  simple_dropdown: gr.update(visible=(bg_type == "์‹ฌํ”Œ ๋ฐฐ๊ฒฝ")),