Spaces:
Kims12
/
Sleeping

Kims12 commited on
Commit
e8f6871
ยท
verified ยท
1 Parent(s): 56c932a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -197,7 +197,7 @@ if not INDOOR_BACKGROUNDS:
197
  if not ABSTRACT_BACKGROUNDS:
198
  ABSTRACT_BACKGROUNDS = {"๋„ค์˜จ ์กฐ๋ช…": "neon lights"}
199
 
200
- # ------------------- ์‹œ์Šคํ…œ ์ธ์ŠคํŠธ๋Ÿญ์…˜ ์ˆ˜์ • (์ƒํ’ˆ ํฌ์ปค์Šค ๋ฐ ๊ณ ํ™”์งˆ ๋ Œ๋”๋ง ์ถ”๊ฐ€) -------------------
201
  def generate_system_instruction():
202
  return """๋‹น์‹ ์€ ์ƒํ’ˆ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•œ ๊ณ ํ’ˆ์งˆ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค.
203
  ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์ƒํ’ˆ๋ช…, ๋ฐฐ๊ฒฝ ์œ ํ˜•, ์ถ”๊ฐ€ ์š”์ฒญ์‚ฌํ•ญ์„ ๋ฐ”ํƒ•์œผ๋กœ ๋ฏธ๋“œ์ €๋‹ˆ(Midjourney)์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ƒ์„ธํ•˜๊ณ  ์ „๋ฌธ์ ์ธ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์˜์–ด๋กœ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.
@@ -310,23 +310,20 @@ def get_selected_background_info(bg_type, simple, studio, nature, indoor, abstra
310
 
311
  # --- ํ”„๋กฌํ”„ํŠธ์—์„œ ์˜ค์ง Midjourney ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ๋งŒ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜ ---
312
  def filter_prompt_only(prompt):
313
- # "Highly detailed commercial photography" ๋ฌธ์ž์—ด๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ๋ถ€๋ถ„์„ ์ฐพ์Œ
314
  idx = prompt.find("Highly detailed commercial photography")
315
  if idx != -1:
316
  prompt_text = prompt[idx:].strip()
317
- # "--ar 1:1 --s 750 --q 2" ํŒŒ๋ผ๋ฏธํ„ฐ๊นŒ์ง€ ํฌํ•จํ•œ ํ›„ ๊ทธ ์ดํ›„ ์„ค๋ช…์ด ์žˆ๋‹ค๋ฉด ์ œ๊ฑฐ
318
  end_idx = prompt_text.rfind("--ar 1:1 --s 750 --q 2")
319
  if end_idx != -1:
320
- # ํŒŒ๋ผ๋ฏธํ„ฐ ํ…์ŠคํŠธ ๊ธธ์ด๋งŒํผ ๋”ํ•ด์„œ ์ž˜๋ผ๋ƒ„
321
  end_idx += len("--ar 1:1 --s 750 --q 2")
322
  prompt_text = prompt_text[:end_idx].strip()
323
  return prompt_text
324
  return prompt.strip()
325
 
326
- # ------------------- ํ†ตํ•ฉ ๊ธฐ๋Šฅ: ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ›„ ์ด๋ฏธ์ง€ ์ƒ์„ฑ -------------------
327
- def generate_product_image(image, bg_type, simple, studio, nature, indoor, abstract, product_name, additional_info):
328
  if image is None:
329
- return None, "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œ ํ›„ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."
330
  product_name = product_name.strip() or "์ œํ’ˆ"
331
  background_info = get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract)
332
  # Gemini API๋กœ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
@@ -339,18 +336,23 @@ def generate_product_image(image, bg_type, simple, studio, nature, indoor, abstr
339
  "2. ์ฝ”๋“œ ๋‚ด ์ง์ ‘ ์ž…๋ ฅ: GEMINI_API_KEY = \"your-api-key\"\n"
340
  "ํ‚ค ๋ฐœ๊ธ‰: https://makersuite.google.com/"
341
  )
342
- return None, warning_msg, warning_msg
343
- # ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ์—์„œ ์˜ค์ง Midjourney ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ ๋ธ”๋ก๋งŒ ์ถ”์ถœ
344
  final_prompt = filter_prompt_only(generated_prompt)
345
- # ์ถ”์ถœ๋œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ์ด๋ฏธ์ง€ ์ƒ์„ฑ
346
- result_image, status = process_images_with_prompt(image, final_prompt, 0)[:2]
347
- return result_image, status, final_prompt
 
 
 
 
 
 
348
 
349
  # ------------------- Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ -------------------
350
  def create_app():
351
- with gr.Blocks(title="๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ") as demo:
352
- gr.Markdown("# ๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ")
353
- gr.Markdown("์ƒํ’ˆ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ , ์ œํ’ˆ๋ช…, ๋ฐฐ๊ฒฝ ์˜ต์…˜, ์ถ”๊ฐ€ ์š”์ฒญ์‚ฌํ•ญ์„ ์ž…๋ ฅํ•˜๋ฉด Gemini API๋ฅผ ํ†ตํ•ด ์˜์–ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ทธ ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ๋Š” ๋ถˆํ•„์š”ํ•œ ์„ค๋ช… ์—†์ด ์˜ค์ง Midjourney ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ๋งŒ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.")
354
  with gr.Row():
355
  with gr.Column(scale=1):
356
  product_name = gr.Textbox(label="์ƒํ’ˆ๋ช… (ํ•œ๊ตญ์–ด ์ž…๋ ฅ)", placeholder="์˜ˆ: ์Šคํ‚จ์ผ€์–ด ํŠœ๋ธŒ, ํ…€๋ธ”๋Ÿฌ ๋“ฑ", interactive=True)
@@ -414,15 +416,18 @@ def create_app():
414
  outputs=[simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown]
415
  )
416
  image_input = gr.Image(label="์ƒํ’ˆ ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ", type="pil")
417
- generate_btn = gr.Button("ํ”„๋กฌํ”„ํŠธ ๋ฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
418
  with gr.Column(scale=1):
419
- prompt_output = gr.Textbox(label="์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", lines=6)
420
- image_output = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€", type="filepath")
 
 
421
  status_output = gr.Textbox(label="๊ฒฐ๊ณผ ์ •๋ณด", lines=3)
422
- generate_btn.click(
423
- fn=generate_product_image,
 
424
  inputs=[image_input, background_type, simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown, product_name, additional_info],
425
- outputs=[image_output, status_output, prompt_output]
426
  )
427
  return demo
428
 
 
197
  if not ABSTRACT_BACKGROUNDS:
198
  ABSTRACT_BACKGROUNDS = {"๋„ค์˜จ ์กฐ๋ช…": "neon lights"}
199
 
200
+ # ------------------- ์‹œ์Šคํ…œ ์ธ์ŠคํŠธ๋Ÿญ์…˜ (์ƒํ’ˆ ํฌ์ปค์Šค ๋ฐ ๊ณ ํ™”์งˆ ๋ Œ๋”๋ง) -------------------
201
  def generate_system_instruction():
202
  return """๋‹น์‹ ์€ ์ƒํ’ˆ ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•œ ๊ณ ํ’ˆ์งˆ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค.
203
  ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์ƒํ’ˆ๋ช…, ๋ฐฐ๊ฒฝ ์œ ํ˜•, ์ถ”๊ฐ€ ์š”์ฒญ์‚ฌํ•ญ์„ ๋ฐ”ํƒ•์œผ๋กœ ๋ฏธ๋“œ์ €๋‹ˆ(Midjourney)์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ƒ์„ธํ•˜๊ณ  ์ „๋ฌธ์ ์ธ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์˜์–ด๋กœ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.
 
310
 
311
  # --- ํ”„๋กฌํ”„ํŠธ์—์„œ ์˜ค์ง Midjourney ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ๋งŒ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜ ---
312
  def filter_prompt_only(prompt):
 
313
  idx = prompt.find("Highly detailed commercial photography")
314
  if idx != -1:
315
  prompt_text = prompt[idx:].strip()
 
316
  end_idx = prompt_text.rfind("--ar 1:1 --s 750 --q 2")
317
  if end_idx != -1:
 
318
  end_idx += len("--ar 1:1 --s 750 --q 2")
319
  prompt_text = prompt_text[:end_idx].strip()
320
  return prompt_text
321
  return prompt.strip()
322
 
323
+ # ------------------- ํ†ตํ•ฉ ๊ธฐ๋Šฅ: 4์žฅ ์ด๋ฏธ์ง€ ์ƒ์„ฑ -------------------
324
+ def generate_product_images_multiple(image, bg_type, simple, studio, nature, indoor, abstract, product_name, additional_info):
325
  if image is None:
326
+ return None, None, None, None, "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.", "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œ ํ›„ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."
327
  product_name = product_name.strip() or "์ œํ’ˆ"
328
  background_info = get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract)
329
  # Gemini API๋กœ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
 
336
  "2. ์ฝ”๋“œ ๋‚ด ์ง์ ‘ ์ž…๋ ฅ: GEMINI_API_KEY = \"your-api-key\"\n"
337
  "ํ‚ค ๋ฐœ๊ธ‰: https://makersuite.google.com/"
338
  )
339
+ return None, None, None, None, warning_msg, warning_msg
 
340
  final_prompt = filter_prompt_only(generated_prompt)
341
+ images_list = []
342
+ statuses = []
343
+ for i in range(4):
344
+ result_img, status, _ = process_images_with_prompt(image, final_prompt, i)
345
+ images_list.append(result_img)
346
+ statuses.append(f"์ด๋ฏธ์ง€ #{i+1}: {status}")
347
+ time.sleep(1)
348
+ combined_status = "\n".join(statuses)
349
+ return images_list[0], images_list[1], images_list[2], images_list[3], combined_status, final_prompt
350
 
351
  # ------------------- Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ -------------------
352
  def create_app():
353
+ with gr.Blocks(title="๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋ฐ 4์žฅ ์ด๋ฏธ์ง€ ์ƒ์„ฑ") as demo:
354
+ gr.Markdown("# ๊ณ ๊ธ‰ ์ƒํ’ˆ ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋ฐ 4์žฅ ์ด๋ฏธ์ง€ ์ƒ์„ฑ")
355
+ gr.Markdown("์ƒํ’ˆ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ , ์ œํ’ˆ๋ช…, ๋ฐฐ๊ฒฝ ์˜ต์…˜, ์ถ”๊ฐ€ ์š”์ฒญ์‚ฌํ•ญ์„ ์ž…๋ ฅํ•˜๋ฉด Gemini API๋ฅผ ํ†ตํ•ด ์˜์–ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ทธ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ 4์žฅ์˜ ์ด๋ฏธ์ง€๊ฐ€ ์ˆœ์ฐจ์ ์œผ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ๋Š” ๋ถˆํ•„์š”ํ•œ ์„ค๋ช… ์—†์ด ์˜ค์ง Midjourney ํ”„๋กฌํ”„ํŠธ ํ…์ŠคํŠธ๋งŒ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.")
356
  with gr.Row():
357
  with gr.Column(scale=1):
358
  product_name = gr.Textbox(label="์ƒํ’ˆ๋ช… (ํ•œ๊ตญ์–ด ์ž…๋ ฅ)", placeholder="์˜ˆ: ์Šคํ‚จ์ผ€์–ด ํŠœ๋ธŒ, ํ…€๋ธ”๋Ÿฌ ๋“ฑ", interactive=True)
 
416
  outputs=[simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown]
417
  )
418
  image_input = gr.Image(label="์ƒํ’ˆ ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ", type="pil")
419
+ generate_multiple_btn = gr.Button("4์žฅ ์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
420
  with gr.Column(scale=1):
421
+ image_output1 = gr.Image(label="์ด๋ฏธ์ง€ #1", type="filepath")
422
+ image_output2 = gr.Image(label="์ด๋ฏธ์ง€ #2", type="filepath")
423
+ image_output3 = gr.Image(label="์ด๋ฏธ์ง€ #3", type="filepath")
424
+ image_output4 = gr.Image(label="์ด๋ฏธ์ง€ #4", type="filepath")
425
  status_output = gr.Textbox(label="๊ฒฐ๊ณผ ์ •๋ณด", lines=3)
426
+ prompt_output = gr.Textbox(label="์ƒ์„ฑ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", lines=6)
427
+ generate_multiple_btn.click(
428
+ fn=generate_product_images_multiple,
429
  inputs=[image_input, background_type, simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown, product_name, additional_info],
430
+ outputs=[image_output1, image_output2, image_output3, image_output4, status_output, prompt_output]
431
  )
432
  return demo
433