Update app.py
Browse files
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
|
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 |
-
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
# ------------------- Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ -------------------
|
350 |
def create_app():
|
351 |
-
with gr.Blocks(title="๊ณ ๊ธ ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ํ๋กฌํํธ ๋ฐ ์ด๋ฏธ์ง ์์ฑ") as demo:
|
352 |
-
gr.Markdown("# ๊ณ ๊ธ ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ํ๋กฌํํธ ๋ฐ ์ด๋ฏธ์ง ์์ฑ")
|
353 |
-
gr.Markdown("์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ , ์ ํ๋ช
, ๋ฐฐ๊ฒฝ ์ต์
, ์ถ๊ฐ ์์ฒญ์ฌํญ์ ์
๋ ฅํ๋ฉด Gemini API๋ฅผ ํตํด ์์ด ํ๋กฌํํธ๋ฅผ ์์ฑํ๊ณ , ๊ทธ
|
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 |
-
|
418 |
with gr.Column(scale=1):
|
419 |
-
|
420 |
-
|
|
|
|
|
421 |
status_output = gr.Textbox(label="๊ฒฐ๊ณผ ์ ๋ณด", lines=3)
|
422 |
-
|
423 |
-
|
|
|
424 |
inputs=[image_input, background_type, simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown, product_name, additional_info],
|
425 |
-
outputs=[
|
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 |
|