Update app.py
Browse files
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 |
-
|
|
|
|
|
336 |
return result_image, status, final_prompt
|
337 |
|
338 |
# ------------------- Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ -------------------
|
339 |
def create_app():
|
340 |
-
with gr.Blocks(title="๊ณ ๊ธ ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ํ๋กฌํํธ
|
341 |
-
gr.Markdown("# ๊ณ ๊ธ ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ํ๋กฌํํธ
|
342 |
-
gr.Markdown("์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ,
|
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 == "์ฌํ ๋ฐฐ๊ฒฝ")),
|