Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
-
import json
|
4 |
from PIL import Image
|
5 |
import gradio as gr
|
6 |
import logging
|
7 |
import re
|
8 |
import time
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
from dotenv import load_dotenv
|
13 |
|
14 |
load_dotenv()
|
@@ -19,27 +19,15 @@ logger = logging.getLogger(__name__)
|
|
19 |
|
20 |
# Gemini API ํค ์ค์
|
21 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", "")
|
22 |
-
|
23 |
-
genai.configure(api_key=GEMINI_API_KEY)
|
24 |
-
else:
|
25 |
-
logger.warning("GEMINI_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
26 |
|
27 |
-
# ๋ฐฐ๊ฒฝ JSON ํ์ผ ๊ฒฝ๋ก ์ค์
|
28 |
BACKGROUNDS_DIR = "./background"
|
29 |
|
30 |
-
#
|
31 |
if not os.path.exists(BACKGROUNDS_DIR):
|
32 |
os.makedirs(BACKGROUNDS_DIR)
|
33 |
logger.info(f"๋ฐฐ๊ฒฝ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ์ต๋๋ค: {BACKGROUNDS_DIR}")
|
34 |
-
else:
|
35 |
-
logger.info(f"๋ฐฐ๊ฒฝ ๋๋ ํ ๋ฆฌ๊ฐ ์ด๋ฏธ ์กด์ฌํฉ๋๋ค: {BACKGROUNDS_DIR}")
|
36 |
-
|
37 |
-
# ๊ธฐ๋ณธ ๋ฐฐ๊ฒฝ ๋ฐ์ดํฐ
|
38 |
-
SIMPLE_BACKGROUNDS = {"ํ์ดํธ ๋ฐฐ๊ฒฝ": "white background", "๋ธ๋ ๋ฐฐ๊ฒฝ": "black background", "๊ทธ๋ผ๋ฐ์ด์
๋ฐฐ๊ฒฝ": "gradient background"}
|
39 |
-
STUDIO_BACKGROUNDS = {"์ ํ ์ฌ์ง ์คํ๋์ค": "product photography studio", "๋ฏธ๋๋ฉ ์คํ๋์ค": "minimal studio"}
|
40 |
-
NATURE_BACKGROUNDS = {"์ด๋ ํด๋ณ": "tropical beach", "์ฒ์": "forest", "์ฐ์
์ง๋": "mountain landscape"}
|
41 |
-
INDOOR_BACKGROUNDS = {"๋ชจ๋ ๋ฆฌ๋น๋ฃธ": "modern living room", "์ธ๋ จ๋ ์ฌ๋ฌด์ค": "elegant office", "๋ญ์
๋ฆฌ ํธํ
": "luxury hotel"}
|
42 |
-
ABSTRACT_BACKGROUNDS = {"๋ค์จ ์กฐ๋ช
": "neon lights", "์ถ์์ ๊ทธ๋ผ๋ฐ์ด์
": "abstract gradient", "์ฐ์ฃผ ๋ฐฐ๊ฒฝ": "space background"}
|
43 |
|
44 |
# JSON ํ์ผ ๋ก๋ ํจ์
|
45 |
def load_background_json(filename):
|
@@ -51,34 +39,6 @@ def load_background_json(filename):
|
|
51 |
return data
|
52 |
except FileNotFoundError:
|
53 |
logger.warning(f"๊ฒฝ๊ณ : {filename} ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.")
|
54 |
-
# ๊ธฐ๋ณธ๊ฐ ์์ฑ - ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ์์ฑ
|
55 |
-
try:
|
56 |
-
with open(file_path, 'w', encoding='utf-8') as f:
|
57 |
-
if "simple" in filename:
|
58 |
-
json.dump(SIMPLE_BACKGROUNDS, f, ensure_ascii=False, indent=2)
|
59 |
-
elif "studio" in filename:
|
60 |
-
json.dump(STUDIO_BACKGROUNDS, f, ensure_ascii=False, indent=2)
|
61 |
-
elif "nature" in filename:
|
62 |
-
json.dump(NATURE_BACKGROUNDS, f, ensure_ascii=False, indent=2)
|
63 |
-
elif "indoor" in filename:
|
64 |
-
json.dump(INDOOR_BACKGROUNDS, f, ensure_ascii=False, indent=2)
|
65 |
-
elif "abstract" in filename:
|
66 |
-
json.dump(ABSTRACT_BACKGROUNDS, f, ensure_ascii=False, indent=2)
|
67 |
-
logger.info(f"{filename} ํ์ผ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์์ฑํ์ต๋๋ค.")
|
68 |
-
except Exception as e:
|
69 |
-
logger.error(f"ํ์ผ ์์ฑ ์ค ์ค๋ฅ: {str(e)}")
|
70 |
-
|
71 |
-
# ๊ธฐ๋ณธ๊ฐ ๋ฐํ
|
72 |
-
if "simple" in filename:
|
73 |
-
return SIMPLE_BACKGROUNDS
|
74 |
-
elif "studio" in filename:
|
75 |
-
return STUDIO_BACKGROUNDS
|
76 |
-
elif "nature" in filename:
|
77 |
-
return NATURE_BACKGROUNDS
|
78 |
-
elif "indoor" in filename:
|
79 |
-
return INDOOR_BACKGROUNDS
|
80 |
-
elif "abstract" in filename:
|
81 |
-
return ABSTRACT_BACKGROUNDS
|
82 |
return {}
|
83 |
except json.JSONDecodeError:
|
84 |
logger.warning(f"๊ฒฝ๊ณ : {filename} ํ์ผ์ JSON ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.")
|
@@ -94,75 +54,151 @@ NATURE_BACKGROUNDS = load_background_json("nature_backgrounds.json")
|
|
94 |
INDOOR_BACKGROUNDS = load_background_json("indoor_backgrounds.json")
|
95 |
ABSTRACT_BACKGROUNDS = load_background_json("abstract_backgrounds.json")
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
def save_binary_file(file_name, data):
|
98 |
with open(file_name, "wb") as f:
|
99 |
f.write(data)
|
100 |
|
101 |
-
def
|
102 |
-
if not
|
103 |
-
return
|
104 |
-
|
105 |
-
prompt = prompt.replace("#1", "IMAGE_TAG_ONE")
|
106 |
-
|
107 |
try:
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
temperature=0.2,
|
129 |
-
top_p=0.95,
|
130 |
-
top_k=40,
|
131 |
-
max_output_tokens=512
|
132 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
translated_text = translated_text.replace("IMAGE_TAG_ONE", "#1")
|
138 |
-
logger.info(f"Translated text: {translated_text.strip()}")
|
139 |
-
return translated_text.strip()
|
140 |
-
else:
|
141 |
-
logger.warning("๋ฒ์ญ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค. ์๋ณธ ํ๋กฌํํธ ์ฌ์ฉ")
|
142 |
-
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
143 |
-
return prompt
|
144 |
except Exception as e:
|
145 |
-
|
146 |
-
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
147 |
-
return prompt
|
148 |
-
|
149 |
-
def preprocess_prompt(prompt, image1):
|
150 |
-
has_img1 = image1 is not None
|
151 |
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
else:
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
159 |
|
160 |
def generate_with_images(prompt, images, variation_index=0):
|
161 |
try:
|
162 |
-
|
|
|
163 |
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
164 |
|
165 |
-
client = genai.Client(api_key=
|
166 |
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}, ๋ณํ ์ธ๋ฑ์ค: {variation_index}")
|
167 |
|
168 |
variation_suffixes = [
|
@@ -236,11 +272,7 @@ def process_images_with_prompt(image1, prompt, variation_index=0, max_retries=3)
|
|
236 |
return None, "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", ""
|
237 |
|
238 |
if prompt and prompt.strip():
|
239 |
-
|
240 |
-
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
241 |
-
final_prompt = translate_prompt_to_english(processed_prompt)
|
242 |
-
else:
|
243 |
-
final_prompt = processed_prompt
|
244 |
else:
|
245 |
final_prompt = "Please creatively transform this image into a more vivid and artistic version. Do not include any text or watermarks in the generated image."
|
246 |
logger.info("Default prompt generated for single image")
|
@@ -296,240 +328,94 @@ def generate_multiple_images(image1, prompt, progress=gr.Progress()):
|
|
296 |
|
297 |
return results[0], results[1], results[2], results[3], combined_status, combined_prompts
|
298 |
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
์์ธํ๊ณ ์ ๋ฌธ์ ์ธ ํ๋กฌํํธ๋ฅผ ์์ด๋ก ์์ฑํด์ฃผ์ธ์.
|
303 |
-
๋ค์ ๊ฐ์ด๋๋ผ์ธ์ ๋ฐ๋์ ๋ฐ๋ผ์ผ ํฉ๋๋ค:
|
304 |
-
1. ์ํ์ "#1"๋ก ์ง์ ํ์ฌ ์ฐธ์กฐํฉ๋๋ค. (์: "skincare tube (#1)")
|
305 |
-
2. *** ๋งค์ฐ ์ค์: ์ํ์ ์๋ ํน์ฑ(๋์์ธ, ์์, ํํ, ๋ก๊ณ , ํจํค์ง ๋ฑ)์ ์ด๋ค ์ํฉ์์๋ ์ ๋ ๋ณ๊ฒฝํ์ง ์์ต๋๋ค. ***
|
306 |
-
3. *** ์ํ์ ๋ณธ์ง์ ํน์ฑ์ ์ ์งํ๋, ์์ฐ์ค๋ฌ์ด ํ๊ฒฝ ํตํฉ์ ์ํ ์กฐ๋ช
๊ณผ ๊ทธ๋ฆผ์๋ ํ์ฉํฉ๋๋ค: ***
|
307 |
-
- ์ํ ์์ฒด์ ์์, ๋์์ธ, ํํ, ํ
์ค์ฒ๋ ์ ๋ ์์ ํ์ง ์์ต๋๋ค.
|
308 |
-
- ํ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ธ๋ฆฌ๋ ๊ทธ๋ฆผ์, ์ฃผ๋ณ ์กฐ๋ช
ํจ๊ณผ๋ ํ์ฉ๋ฉ๋๋ค.
|
309 |
-
- ์ํ์ ๋ฌผ๋ฐฉ์ธ, ์์ถ, ๊ธ, ์๊ณผ ๊ฐ์ ์ถ๊ฐ ์์๋ ๋ฌผ๋ฆฌ์ ํจ๊ณผ๋ ์ ์ฉํ์ง ์์ต๋๋ค.
|
310 |
-
- ํ๊ฒฝ์ ์ด์ธ๋ฆฌ๋ ์์ฐ์ค๋ฌ์ด ๋น ๋ฐ์ฌ, ์ฃผ๋ณ ์กฐ๋ช
, ๊ทธ๋ฆผ์๋ ์ฌ์ค์ ํตํฉ๊ฐ์ ์ํด ์ ์ฉํ ์ ์์ต๋๋ค.
|
311 |
-
4. ์ด๋ฏธ์ง ๋น์จ์ ์ ํํ 1:1(์ ์ฌ๊ฐํ) ํ์์ผ๋ก ์ง์ ํฉ๋๋ค. ํ๋กฌํํธ์ "square format", "1:1 ratio" ๋๋ "aspect ratio 1:1"์ ๋ช
์์ ์ผ๋ก ํฌํจํฉ๋๋ค.
|
312 |
-
5. ์ํ์ ๋ฐ๋์ ์ ์ฌ๊ฐํ ๊ตฌ๋์ ์ ์ค์์ ๋ฐฐ์น๋์ด์ผ ํฉ๋๋ค.
|
313 |
-
6. ์ํ์ ์ด๋ฏธ์ง์ ์ฃผ์ ์ด์ ์ผ๋ก ๋ถ๊ฐ์ํค๊ณ , ์ํ์ ๋น์จ์ด ์ ์ฒด ์ด๋ฏธ์ง์์ ํฌ๊ฒ ์ฐจ์งํ๋๋ก ํฉ๋๋ค.
|
314 |
-
7. ์ํ ์ด๋ฏธ์ง ์ปท์์(#1)์ ๊ธฐ๋ณธ ํํ์ ์์์ ์ ์งํ๋ฉด์, ์ ํํ ํ๊ฒฝ์ ์์ฐ์ค๋ฝ๊ฒ ํตํฉ๋๋๋ก ํฉ๋๋ค.
|
315 |
-
8. ๊ณ ๊ธ์ค๋ฌ์ด ์์
์ ์ด๋ฏธ์ง๋ฅผ ์ํ ๋ค์ ํ๊ฒฝ ์์๋ค์ ํฌํจํ์ธ์:
|
316 |
-
- ์ํ๊ณผ ์ด์ธ๋ฆฌ๋ ์ฃผ๋ณ ํ๊ฒฝ/๋ฐฐ๊ฒฝ ์์๋ฅผ ์ถ๊ฐํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ํ์ฅํ ์ฃผ๋ณ์ ๊ฝ์ด๋ ํ๋ธ, ์๋ฃ ์ ํ ์์ ๊ณผ์ผ, ์ ์์ ํ ๊ทผ์ฒ์ ํ๋์ ์ํ ๋ฑ.
|
317 |
-
- ํ๊ฒฝ์ ์กฐ๋ช
ํจ๊ณผ(๋ฆผ ๋ผ์ดํธ, ๋ฐฑ๋ผ์ดํธ, ์ํํธ๋ฐ์ค ๋ฑ)๋ฅผ ์ค๋ช
ํฉ๋๋ค.
|
318 |
-
- ์ํ์ด ํ๊ฒฝ์ ์์ฐ์ค๋ฝ๊ฒ ์กด์ฌํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋๋ก ์ ์ ํ ๊ทธ๋ฆผ์์ ๋น ํํ์ ํฌํจํฉ๋๋ค.
|
319 |
-
- ์ํ์ ์ฉ๋๋ ์ฅ์ ์ ๊ฐ์ ์ ์ผ๋ก ์์ํ๋ ๋ฐฐ๊ฒฝ ์์๋ฅผ ํฌํจํฉ๋๋ค.
|
320 |
-
- ํ๋กํ์
๋ํ ์์
์ฌ์ง ํจ๊ณผ(์ ํ์ ํผ์ฌ๊ณ ์ฌ๋, ์ํํธ ํฌ์ปค์ค, ์คํ๋์ค ์กฐ๋ช
๋ฑ)๋ฅผ ๋ช
์ํฉ๋๋ค.
|
321 |
-
9. ํ๋กฌํํธ์ ๋ค์ ์์๋ค์ ๋ช
์์ ์ผ๋ก ํฌํจํ์ธ์:
|
322 |
-
- "highly detailed commercial photography"
|
323 |
-
- "award-winning product photography"
|
324 |
-
- "professional advertising imagery"
|
325 |
-
- "studio quality"
|
326 |
-
- "magazine advertisement quality"
|
327 |
-
10. ๋ฐฐ๊ฒฝ ํ๊ฒฝ ์์๋ฅผ ์ํ ์นดํ
๊ณ ๋ฆฌ์ ๋ง๊ฒ ์ ํํฉ๋๋ค:
|
328 |
-
- ์คํจ์ผ์ด ์ ํ: ๊นจ๋ํ ์์ค ์ ๋ฐ, ์ฐ์ํ ํ์ฅ๋, ์คํ ๊ฐ์ ํ๊ฒฝ ๋ฑ
|
329 |
-
- ์๋ฃ ์ ํ: ์ธ๋ จ๋ ํ
์ด๋ธ, ํํฐ ํ๊ฒฝ, ์ผ์ธ ํผํฌ๋ ์ฅ๋ฉด ๋ฑ
|
330 |
-
- ์ ์ ์ ํ: ์ธ๋ จ๋ ์์
๊ณต๊ฐ, ํ๋์ ์ธ ๊ฑฐ์ค, ๋ฏธ๋๋ฉํ ์ฑ
์ ๋ฑ
|
331 |
-
- ํจ์
/์๋ฅ: ์ธ๋ จ๋ ์ผ๋ฃธ, ๋์ ๊ฑฐ๋ฆฌ, ์๋ ๊ฐ์คํ ๋ผ์ดํ์คํ์ผ ํ๊ฒฝ ๋ฑ
|
332 |
-
- ์ํ ์ ํ: ๊น๋ํ ์ฃผ๋ฐฉ, ์ํ, ์๋ฆฌ ํ๊ฒฝ ๋ฑ
|
333 |
-
11. ์ฌ์ฉ์๊ฐ ์ ๊ณตํ ๊ตฌ์ฒด์ ์ธ ๋ฐฐ๊ฒฝ๊ณผ ์ถ๊ฐ ์์ฒญ์ฌํญ์ ์ ํํ ๋ฐ์ํฉ๋๋ค.
|
334 |
-
12. ํ๋กฌํํธ๋ ๋ฏธ๋์ ๋ AI์ ์ต์ ํ๋์ด์ผ ํฉ๋๋ค.
|
335 |
-
13. ํ๋กฌํํธ ๋์ "--ar 1:1 --s 750 --q 2" ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ์ฌ ๋ฏธ๋์ ๋์์ ๊ณ ํ์ง ์ ์ฌ๊ฐํ ๋น์จ์ ๊ฐ์ ํฉ๋๋ค.
|
336 |
-
์ถ๋ ฅ ํ์์ ์์ด๋ก ๋ ๋จ์ผ ๋จ๋ฝ์ ์์ธํ ํ๋กฌํํธ์ฌ์ผ ํ๋ฉฐ, ๋์ ๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ๊ฐ ํฌํจ๋์ด์ผ ํฉ๋๋ค.
|
337 |
-
"""
|
338 |
-
|
339 |
-
def generate_prompt_with_gemini(product_name, background_info, additional_info=""):
|
340 |
-
if not GEMINI_API_KEY:
|
341 |
-
return "Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ ๋ณ์ GEMINI_API_KEY๋ฅผ ์ค์ ํ๊ฑฐ๋ ์ฝ๋์ ์ง์ ์
๋ ฅํ์ธ์."
|
342 |
-
try:
|
343 |
-
prompt_request = f"""
|
344 |
-
์ํ๋ช
: {product_name}
|
345 |
-
๋ฐฐ๊ฒฝ ์ ํ: {background_info.get('english', 'studio')}
|
346 |
-
๋ฐฐ๊ฒฝ ์นดํ
๊ณ ๋ฆฌ: {background_info.get('category', '')}
|
347 |
-
๋ฐฐ๊ฒฝ ์ด๋ฆ: {background_info.get('name', '')}
|
348 |
-
์ถ๊ฐ ์์ฒญ์ฌํญ: {additional_info}
|
349 |
-
์ค์ ์๊ตฌ์ฌํญ:
|
350 |
-
1. ์ํ์ด ํฌ๊ฒ ๋ถ๊ฐ๋๊ณ ์ด๋ฏธ์ง์์ ์ค์ฌ์ ์ธ ์์น๋ฅผ ์ฐจ์งํ๋๋ก ํ๋กฌํํธ๋ฅผ ์์ฑํด์ฃผ์ธ์.
|
351 |
-
2. ์ด๋ฏธ์ง๋ ์ ํํ 1:1 ๋น์จ(์ ์ฌ๊ฐํ)์ด์ด์ผ ํฉ๋๋ค.
|
352 |
-
3. ์ํ์ ์ ์ฌ๊ฐํ ํ๋ ์์ ์ ์ค์์ ์์นํด์ผ ํฉ๋๋ค.
|
353 |
-
4. ์ํ์ ๋์์ธ, ์์, ํํ, ๋ก๊ณ ๋ฑ ๋ณธ์ง์ ํน์ฑ์ ์ ๋ ์์ ํ์ง ๋ง์ธ์.
|
354 |
-
5. ํ๊ฒฝ๊ณผ์ ์์ฐ์ค๋ฌ์ด ํตํฉ์ ์ํ ์กฐ๋ช
ํจ๊ณผ์ ๊ทธ๋ฆผ์๋ ํฌํจํด์ฃผ์ธ์.
|
355 |
-
6. ์ํ์ ๋ ๋๋ณด์ด๊ฒ ํ๋ ๋ฐฐ๊ฒฝ ํ๊ฒฝ์ ์ค๋ช
ํด์ฃผ์ธ์.
|
356 |
-
7. ๊ณ ๊ธ์ค๋ฌ์ด ์์
๊ด๊ณ ํ์ง์ ์ด๋ฏธ์ง๊ฐ ๋๋๋ก ํ๊ฒฝ ์ค๋ช
์ ํด์ฃผ์ธ์.
|
357 |
-
8. ํ๋กฌํํธ ๋์ ๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ "--ar 1:1 --s 750 --q 2"๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.
|
358 |
-
ํ๊ตญ์ด ์
๋ ฅ ๋ด์ฉ์ ์์ด๋ก ์ ์ ํ ๋ฒ์ญํ์ฌ ๋ฐ์ํด์ฃผ์ธ์.
|
359 |
-
"""
|
360 |
-
|
361 |
-
# google-generativeai ํจํค์ง ์ฌ์ฉ ๋ฐฉ์์ผ๋ก ๋ณ๊ฒฝ
|
362 |
-
system_instruction = generate_system_instruction()
|
363 |
-
|
364 |
-
# GenerativeModel ๋์ genai.chat ์ฌ์ฉ
|
365 |
-
chat = genai.chat(
|
366 |
-
model="gemini-2.0-flash",
|
367 |
-
messages=[
|
368 |
-
{"role": "system", "content": system_instruction},
|
369 |
-
{"role": "user", "content": prompt_request}
|
370 |
-
],
|
371 |
-
generation_config={
|
372 |
-
"temperature": 0.7,
|
373 |
-
"top_p": 0.95,
|
374 |
-
"top_k": 64,
|
375 |
-
"max_output_tokens": 1024,
|
376 |
-
}
|
377 |
-
)
|
378 |
-
|
379 |
-
response_text = chat.last.text.strip()
|
380 |
-
|
381 |
-
if "--ar 1:1" not in response_text:
|
382 |
-
response_text = response_text.rstrip(".") + ". --ar 1:1 --s 750 --q 2"
|
383 |
-
|
384 |
-
# ๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ ์ ๊ฑฐ (Gemini API์๋ ๋ฌ๋ฆฌ ๋ถํ์ํ๋ฏ๋ก)
|
385 |
-
response_text = response_text.replace(" --ar 1:1 --s 750 --q 2", "")
|
386 |
-
|
387 |
-
return response_text
|
388 |
-
except Exception as e:
|
389 |
-
return f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
390 |
-
|
391 |
-
# ์ ํ๋ ๋ฐฐ๊ฒฝ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
392 |
-
def get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract):
|
393 |
-
if bg_type == "์ฌํ ๋ฐฐ๊ฒฝ":
|
394 |
-
return {
|
395 |
-
"category": "์ฌํ ๋ฐฐ๊ฒฝ",
|
396 |
-
"name": simple,
|
397 |
-
"english": SIMPLE_BACKGROUNDS.get(simple, "white background")
|
398 |
-
}
|
399 |
-
elif bg_type == "์คํ๋์ค ๋ฐฐ๊ฒฝ":
|
400 |
-
return {
|
401 |
-
"category": "์คํ๋์ค ๋ฐฐ๊ฒฝ",
|
402 |
-
"name": studio,
|
403 |
-
"english": STUDIO_BACKGROUNDS.get(studio, "product photography studio")
|
404 |
-
}
|
405 |
-
elif bg_type == "์์ฐ ํ๊ฒฝ":
|
406 |
-
return {
|
407 |
-
"category": "์์ฐ ํ๊ฒฝ",
|
408 |
-
"name": nature,
|
409 |
-
"english": NATURE_BACKGROUNDS.get(nature, "natural environment")
|
410 |
-
}
|
411 |
-
elif bg_type == "์ค๋ด ํ๊ฒฝ":
|
412 |
-
return {
|
413 |
-
"category": "์ค๋ด ํ๊ฒฝ",
|
414 |
-
"name": indoor,
|
415 |
-
"english": INDOOR_BACKGROUNDS.get(indoor, "indoor environment")
|
416 |
-
}
|
417 |
-
elif bg_type == "์ถ์/ํน์ ๋ฐฐ๊ฒฝ":
|
418 |
-
return {
|
419 |
-
"category": "์ถ์/ํน์ ๋ฐฐ๊ฒฝ",
|
420 |
-
"name": abstract,
|
421 |
-
"english": ABSTRACT_BACKGROUNDS.get(abstract, "abstract background")
|
422 |
-
}
|
423 |
-
else:
|
424 |
-
return {
|
425 |
-
"category": "๊ธฐ๋ณธ ๋ฐฐ๊ฒฝ",
|
426 |
-
"name": "ํ์ดํธ ๋ฐฐ๊ฒฝ",
|
427 |
-
"english": "white background"
|
428 |
-
}
|
429 |
-
|
430 |
-
# ํ๋กฌํํธ ์์ฑ ํจ์
|
431 |
-
def create_prompt(image, bg_type, simple, studio, nature, indoor, abstract, product_text, additional_text):
|
432 |
-
if image is None:
|
433 |
-
return "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์."
|
434 |
-
|
435 |
-
product_text = product_text.strip() or "์ ํ"
|
436 |
-
|
437 |
-
# ๋ฐฐ๊ฒฝ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
438 |
-
background_info = get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract)
|
439 |
|
440 |
-
try:
|
441 |
-
prompt = generate_prompt_with_gemini(product_text, background_info, additional_text)
|
442 |
-
return prompt
|
443 |
-
except Exception as e:
|
444 |
-
error_msg = f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
445 |
-
return error_msg
|
446 |
-
|
447 |
-
|
448 |
-
with gr.Blocks() as demo:
|
449 |
with gr.Row():
|
450 |
-
with gr.Column():
|
451 |
# ์ด๋ฏธ์ง ์
๋ก๋ ์น์
|
452 |
-
gr.
|
453 |
-
with gr.Row():
|
454 |
-
image1_input = gr.Image(type="pil", label="์ด๋ฏธ์ง ์
๋ก๋", image_mode="RGB")
|
455 |
|
456 |
-
#
|
457 |
-
gr.
|
458 |
-
product_name = gr.Textbox(label="์ ํ๋ช
(ํ๊ตญ์ด ์
๋ ฅ)", placeholder="์: ์คํจ์ผ์ด ํ๋ธ, ํ
๋ธ๋ฌ ๋ฑ")
|
459 |
|
460 |
-
# ๋ฐฐ๊ฒฝ
|
461 |
-
gr.
|
462 |
-
background_type = gr.Radio(
|
463 |
choices=["์ฌํ ๋ฐฐ๊ฒฝ", "์คํ๋์ค ๋ฐฐ๊ฒฝ", "์์ฐ ํ๊ฒฝ", "์ค๋ด ํ๊ฒฝ", "์ถ์/ํน์ ๋ฐฐ๊ฒฝ"],
|
464 |
label="๋ฐฐ๊ฒฝ ์ ํ",
|
465 |
value="์ฌํ ๋ฐฐ๊ฒฝ"
|
466 |
)
|
467 |
|
468 |
# ๊ฐ ๋ฐฐ๊ฒฝ ์ ํ์ ๋ง๋ ๋๋กญ๋ค์ด ์ปดํฌ๋ํธ๋ค
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
|
477 |
-
studio_dropdown = gr.Dropdown(
|
478 |
-
choices=list(STUDIO_BACKGROUNDS.keys()),
|
479 |
-
value=list(STUDIO_BACKGROUNDS.keys())[0] if STUDIO_BACKGROUNDS else None,
|
480 |
-
label="์คํ๋์ค ๋ฐฐ๊ฒฝ ์ ํ",
|
481 |
-
visible=False,
|
482 |
-
interactive=True
|
483 |
-
)
|
484 |
-
|
485 |
-
nature_dropdown = gr.Dropdown(
|
486 |
-
choices=list(NATURE_BACKGROUNDS.keys()),
|
487 |
-
value=list(NATURE_BACKGROUNDS.keys())[0] if NATURE_BACKGROUNDS else None,
|
488 |
-
label="์์ฐ ํ๊ฒฝ ์ ํ",
|
489 |
-
visible=False,
|
490 |
-
interactive=True
|
491 |
-
)
|
492 |
-
|
493 |
-
indoor_dropdown = gr.Dropdown(
|
494 |
-
choices=list(INDOOR_BACKGROUNDS.keys()),
|
495 |
-
value=list(INDOOR_BACKGROUNDS.keys())[0] if INDOOR_BACKGROUNDS else None,
|
496 |
-
label="์ค๋ด ํ๊ฒฝ ์ ํ",
|
497 |
-
visible=False,
|
498 |
-
interactive=True
|
499 |
-
)
|
500 |
-
|
501 |
-
abstract_dropdown = gr.Dropdown(
|
502 |
-
choices=list(ABSTRACT_BACKGROUNDS.keys()),
|
503 |
-
value=list(ABSTRACT_BACKGROUNDS.keys())[0] if ABSTRACT_BACKGROUNDS else None,
|
504 |
-
label="์ถ์/ํน์ ๋ฐฐ๊ฒฝ ์ ํ",
|
505 |
-
visible=False,
|
506 |
-
interactive=True
|
507 |
-
)
|
508 |
-
|
509 |
-
# ์ถ๊ฐ ์์ฒญ์ฌํญ
|
510 |
additional_info = gr.Textbox(
|
511 |
label="์ถ๊ฐ ์์ฒญ์ฌํญ (์ ํ์ฌํญ)",
|
512 |
placeholder="์: ๊ณ ๊ธ์ค๋ฌ์ด ๋๋, ๋ฐ์ ์กฐ๋ช
, ์์ฐ์ค๋ฌ์ด ๋ณด์กฐ์ ์ธ ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์ ๋ฑ",
|
513 |
-
lines=
|
|
|
514 |
)
|
515 |
|
516 |
-
# ํ๋กฌํํธ
|
517 |
-
gr.Markdown("## ํ๋กฌํํธ ์ค์ ")
|
518 |
-
|
519 |
generate_prompt_btn = gr.Button("ํ๋กฌํํธ ์์ฑ")
|
520 |
|
521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
lines=3,
|
523 |
-
|
524 |
-
label="์์ฑ๋ ํ๋กฌํํธ"
|
525 |
)
|
526 |
|
527 |
with gr.Row():
|
528 |
-
submit_single_btn = gr.Button('์ด๋ฏธ์ง
|
529 |
-
submit_btn = gr.Button('์ด๋ฏธ์ง
|
530 |
|
531 |
-
with gr.Column():
|
532 |
-
|
533 |
with gr.Row():
|
534 |
with gr.Column():
|
535 |
output_image1 = gr.Image(label="์ด๋ฏธ์ง #1", type="filepath")
|
@@ -538,9 +424,10 @@ with gr.Blocks() as demo:
|
|
538 |
output_image2 = gr.Image(label="์ด๋ฏธ์ง #2", type="filepath")
|
539 |
output_image4 = gr.Image(label="์ด๋ฏธ์ง #4", type="filepath")
|
540 |
|
|
|
541 |
output_text = gr.Textbox(label="๊ฒฐ๊ณผ ์ ๋ณด", lines=2)
|
542 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", lines=2)
|
543 |
-
|
544 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ๋๋กญ๋ค์ด ํ์ ์
๋ฐ์ดํธ
|
545 |
def update_dropdowns(bg_type):
|
546 |
return {
|
@@ -550,20 +437,43 @@ with gr.Blocks() as demo:
|
|
550 |
indoor_dropdown: gr.update(visible=(bg_type == "์ค๋ด ํ๊ฒฝ")),
|
551 |
abstract_dropdown: gr.update(visible=(bg_type == "์ถ์/ํน์ ๋ฐฐ๊ฒฝ"))
|
552 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
|
554 |
-
#
|
555 |
-
|
|
|
|
|
|
|
|
|
556 |
fn=update_dropdowns,
|
557 |
-
inputs=[
|
558 |
outputs=[simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown]
|
559 |
)
|
560 |
-
|
561 |
-
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
562 |
generate_prompt_btn.click(
|
563 |
-
fn=
|
564 |
inputs=[
|
565 |
-
|
566 |
-
|
567 |
simple_dropdown,
|
568 |
studio_dropdown,
|
569 |
nature_dropdown,
|
@@ -572,22 +482,30 @@ with gr.Blocks() as demo:
|
|
572 |
product_name,
|
573 |
additional_info
|
574 |
],
|
575 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
)
|
577 |
|
578 |
# ๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
579 |
submit_single_btn.click(
|
580 |
fn=lambda image1, prompt: process_images_with_prompt(image1, prompt, 0),
|
581 |
-
inputs=[
|
582 |
outputs=[output_image1, output_text, prompt_display],
|
583 |
)
|
584 |
|
585 |
# 4์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
586 |
submit_btn.click(
|
587 |
fn=generate_multiple_images,
|
588 |
-
inputs=[
|
589 |
outputs=[output_image1, output_image2, output_image3, output_image4, output_text, prompt_display],
|
590 |
)
|
591 |
|
592 |
-
|
593 |
-
demo.
|
|
|
|
1 |
import os
|
2 |
import tempfile
|
|
|
3 |
from PIL import Image
|
4 |
import gradio as gr
|
5 |
import logging
|
6 |
import re
|
7 |
import time
|
8 |
+
import json
|
9 |
|
10 |
+
from google import genai
|
11 |
+
from google.genai import types
|
12 |
from dotenv import load_dotenv
|
13 |
|
14 |
load_dotenv()
|
|
|
19 |
|
20 |
# Gemini API ํค ์ค์
|
21 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", "")
|
22 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
|
|
|
|
|
|
23 |
|
24 |
+
# ๋ฐฐ๊ฒฝ JSON ํ์ผ ๊ฒฝ๋ก ์ค์
|
25 |
BACKGROUNDS_DIR = "./background"
|
26 |
|
27 |
+
# ๋๋ ํ ๋ฆฌ๊ฐ ์์ผ๋ฉด ์์ฑ
|
28 |
if not os.path.exists(BACKGROUNDS_DIR):
|
29 |
os.makedirs(BACKGROUNDS_DIR)
|
30 |
logger.info(f"๋ฐฐ๊ฒฝ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ์ต๋๋ค: {BACKGROUNDS_DIR}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# JSON ํ์ผ ๋ก๋ ํจ์
|
33 |
def load_background_json(filename):
|
|
|
39 |
return data
|
40 |
except FileNotFoundError:
|
41 |
logger.warning(f"๊ฒฝ๊ณ : {filename} ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
return {}
|
43 |
except json.JSONDecodeError:
|
44 |
logger.warning(f"๊ฒฝ๊ณ : {filename} ํ์ผ์ JSON ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.")
|
|
|
54 |
INDOOR_BACKGROUNDS = load_background_json("indoor_backgrounds.json")
|
55 |
ABSTRACT_BACKGROUNDS = load_background_json("abstract_backgrounds.json")
|
56 |
|
57 |
+
# ๋ฐฐ๊ฒฝ์ด ๋ก๋๋์ง ์์ ๊ฒฝ์ฐ ๊ธฐ๋ณธ๊ฐ ์ค์
|
58 |
+
if not SIMPLE_BACKGROUNDS:
|
59 |
+
SIMPLE_BACKGROUNDS = {"ํ์ดํธ ๋ฐฐ๊ฒฝ": "white background"}
|
60 |
+
if not STUDIO_BACKGROUNDS:
|
61 |
+
STUDIO_BACKGROUNDS = {"์ ํ ์ฌ์ง ์คํ๋์ค": "product photography studio"}
|
62 |
+
if not NATURE_BACKGROUNDS:
|
63 |
+
NATURE_BACKGROUNDS = {"์ด๋ ํด๋ณ": "tropical beach"}
|
64 |
+
if not INDOOR_BACKGROUNDS:
|
65 |
+
INDOOR_BACKGROUNDS = {"๋ชจ๋ ๋ฆฌ๋น๋ฃธ": "modern living room"}
|
66 |
+
if not ABSTRACT_BACKGROUNDS:
|
67 |
+
ABSTRACT_BACKGROUNDS = {"๋ค์จ ์กฐ๋ช
": "neon lights"}
|
68 |
+
|
69 |
+
def generate_system_instruction():
|
70 |
+
return """๋น์ ์ ์ํ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝํ๊ธฐ ์ํ ๊ณ ํ์ง ํ๋กฌํํธ๋ฅผ ์์ฑํ๋ ์ ๋ฌธ๊ฐ์
๋๋ค.
|
71 |
+
์ฌ์ฉ์๊ฐ ์ ๊ณตํ๋ ์ํ๋ช
, ๋ฐฐ๊ฒฝ ์ ํ, ์ถ๊ฐ ์์ฒญ์ฌํญ์ ๋ฐํ์ผ๋ก ๋ฏธ๋์ ๋(Midjourney)์ ์ฌ์ฉํ ์ ์๋
|
72 |
+
์์ธํ๊ณ ์ ๋ฌธ์ ์ธ ํ๋กฌํํธ๋ฅผ ์์ด๋ก ์์ฑํด์ฃผ์ธ์.
|
73 |
+
๋ค์ ๊ฐ์ด๋๋ผ์ธ์ ๋ฐ๋์ ๋ฐ๋ผ์ผ ํฉ๋๋ค:
|
74 |
+
1. ์ํ์ "#1"๋ก ์ง์ ํ์ฌ ์ฐธ์กฐํฉ๋๋ค. (์: "skincare tube (#1)")
|
75 |
+
2. *** ๋งค์ฐ ์ค์: ์ํ์ ์๋ ํน์ฑ(๋์์ธ, ์์, ํํ, ๋ก๊ณ , ํจํค์ง ๋ฑ)์ ์ด๋ค ์ํฉ์์๋ ์ ๋ ๋ณ๊ฒฝํ์ง ์์ต๏ฟฝ๏ฟฝ๋ค. ***
|
76 |
+
3. *** ์ํ์ ๋ณธ์ง์ ํน์ฑ์ ์ ์งํ๋, ์์ฐ์ค๋ฌ์ด ํ๊ฒฝ ํตํฉ์ ์ํ ์กฐ๋ช
๊ณผ ๊ทธ๋ฆผ์๋ ํ์ฉํฉ๋๋ค: ***
|
77 |
+
- ์ํ ์์ฒด์ ์์, ๋์์ธ, ํํ, ํ
์ค์ฒ๋ ์ ๋ ์์ ํ์ง ์์ต๋๋ค.
|
78 |
+
- ํ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ธ๋ฆฌ๋ ๊ทธ๋ฆผ์, ์ฃผ๋ณ ์กฐ๋ช
ํจ๊ณผ๋ ํ์ฉ๋ฉ๋๋ค.
|
79 |
+
- ์ํ์ ๋ฌผ๋ฐฉ์ธ, ์์ถ, ๊ธ, ์๊ณผ ๊ฐ์ ์ถ๊ฐ ์์๋ ๋ฌผ๋ฆฌ์ ํจ๊ณผ๋ ์ ์ฉํ์ง ์์ต๋๋ค.
|
80 |
+
- ํ๊ฒฝ์ ์ด์ธ๋ฆฌ๋ ์์ฐ์ค๋ฌ์ด ๋น ๋ฐ์ฌ, ์ฃผ๋ณ ์กฐ๋ช
, ๊ทธ๋ฆผ์๋ ์ฌ์ค์ ํตํฉ๊ฐ์ ์ํด ์ ์ฉํ ์ ์์ต๋๋ค.
|
81 |
+
4. ์ด๋ฏธ์ง ๋น์จ์ ์ ํํ 1:1(์ ์ฌ๊ฐํ) ํ์์ผ๋ก ์ง์ ํฉ๋๋ค. ํ๋กฌํํธ์ "square format", "1:1 ratio" ๋๋ "aspect ratio 1:1"์ ๋ช
์์ ์ผ๋ก ํฌํจํฉ๋๋ค.
|
82 |
+
5. ์ํ์ ๋ฐ๋์ ์ ์ฌ๊ฐํ ๊ตฌ๋์ ์ ์ค์์ ๋ฐฐ์น๋์ด์ผ ํฉ๋๋ค.
|
83 |
+
6. ์ํ์ ์ด๋ฏธ์ง์ ์ฃผ์ ์ด์ ์ผ๋ก ๋ถ๊ฐ์ํค๊ณ , ์ํ์ ๋น์จ์ด ์ ์ฒด ์ด๋ฏธ์ง์์ ํฌ๊ฒ ์ฐจ์งํ๋๋ก ํฉ๋๋ค.
|
84 |
+
7. ์ํ ์ด๋ฏธ์ง ์ปท์์(#1)์ ๊ธฐ๋ณธ ํํ์ ์์์ ์ ์งํ๋ฉด์, ์ ํํ ํ๊ฒฝ์ ์์ฐ์ค๋ฝ๊ฒ ํตํฉ๋๋๋ก ํฉ๋๋ค.
|
85 |
+
8. ๊ณ ๊ธ์ค๋ฌ์ด ์์
์ ์ด๋ฏธ์ง๋ฅผ ์ํ ๋ค์ ํ๊ฒฝ ์์๋ค์ ํฌํจํ์ธ์:
|
86 |
+
- ์ํ๊ณผ ์ด์ธ๋ฆฌ๋ ์ฃผ๋ณ ํ๊ฒฝ/๋ฐฐ๊ฒฝ ์์๋ฅผ ์ถ๊ฐํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ํ์ฅํ ์ฃผ๋ณ์ ๊ฝ์ด๋ ํ๋ธ, ์๋ฃ ์ ํ ์์ ๊ณผ์ผ, ์ ์์ ํ ๊ทผ์ฒ์ ํ๋์ ์ํ ๋ฑ.
|
87 |
+
- ํ๊ฒฝ์ ์กฐ๋ช
ํจ๊ณผ(๋ฆผ ๋ผ์ดํธ, ๋ฐฑ๋ผ์ดํธ, ์ํํธ๋ฐ์ค ๋ฑ)๋ฅผ ์ค๋ช
ํฉ๋๋ค.
|
88 |
+
- ์ํ์ด ํ๊ฒฝ์ ์์ฐ์ค๋ฝ๊ฒ ์กด์ฌํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋๋ก ์ ์ ํ ๊ทธ๋ฆผ์์ ๋น ํํ์ ํฌํจํฉ๋๋ค.
|
89 |
+
- ์ํ์ ์ฉ๋๋ ์ฅ์ ์ ๊ฐ์ ์ ์ผ๋ก ์์ํ๋ ๋ฐฐ๊ฒฝ ์์๋ฅผ ํฌํจํฉ๋๋ค.
|
90 |
+
- ํ๋กํ์
๋ํ ์์
์ฌ์ง ํจ๊ณผ(์ ํ์ ํผ์ฌ๊ณ ์ฌ๋, ์ํํธ ํฌ์ปค์ค, ์คํ๋์ค ์กฐ๋ช
๋ฑ)๋ฅผ ๋ช
์ํฉ๋๋ค.
|
91 |
+
9. ํ๋กฌํํธ์ ๋ค์ ์์๋ค์ ๋ช
์์ ์ผ๋ก ํฌํจํ์ธ์:
|
92 |
+
- "highly detailed commercial photography"
|
93 |
+
- "award-winning product photography"
|
94 |
+
- "professional advertising imagery"
|
95 |
+
- "studio quality"
|
96 |
+
- "magazine advertisement quality"
|
97 |
+
10. ๋ฐฐ๊ฒฝ ํ๊ฒฝ ์์๋ฅผ ์ํ ์นดํ
๊ณ ๋ฆฌ์ ๋ง๊ฒ ์ ํํฉ๋๋ค:
|
98 |
+
- ์คํจ์ผ์ด ์ ํ: ๊นจ๋ํ ์์ค ์ ๋ฐ, ์ฐ์ํ ํ์ฅ๋, ์คํ ๊ฐ์ ํ๊ฒฝ ๋ฑ
|
99 |
+
- ์๋ฃ ์ ํ: ์ธ๋ จ๋ ํ
์ด๋ธ, ํํฐ ํ๊ฒฝ, ์ผ์ธ ํผํฌ๋ ์ฅ๋ฉด ๋ฑ
|
100 |
+
- ์ ์ ์ ํ: ์ธ๋ จ๋ ์์
๊ณต๊ฐ, ํ๋์ ์ธ ๊ฑฐ์ค, ๋ฏธ๋๋ฉํ ์ฑ
์ ๋ฑ
|
101 |
+
- ํจ์
/์๋ฅ: ์ธ๋ จ๋ ์ผ๋ฃธ, ๋์ ๊ฑฐ๋ฆฌ, ์๋ ๊ฐ์คํ ๋ผ์ดํ์คํ์ผ ํ๊ฒฝ ๋ฑ
|
102 |
+
- ์ํ ์ ํ: ๊น๋ํ ์ฃผ๋ฐฉ, ์ํ, ์๋ฆฌ ํ๊ฒฝ ๋ฑ
|
103 |
+
11. ์ฌ์ฉ์๊ฐ ์ ๊ณตํ ๊ตฌ์ฒด์ ์ธ ๋ฐฐ๊ฒฝ๊ณผ ์ถ๊ฐ ์์ฒญ์ฌํญ์ ์ ํํ ๋ฐ์ํฉ๋๋ค.
|
104 |
+
12. ํ๋กฌํํธ๋ ๋ฏธ๋์ ๋ AI์ ์ต์ ํ๋์ด์ผ ํฉ๋๋ค.
|
105 |
+
13. ํ๋กฌํํธ ๋์ "--ar 1:1 --s 750 --q 2" ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ์ฌ ๋ฏธ๋์ ๋์์ ๊ณ ํ์ง ์ ์ฌ๊ฐํ ๋น์จ์ ๊ฐ์ ํฉ๋๋ค.
|
106 |
+
์ถ๋ ฅ ํ์์ ์์ด๋ก ๋ ๋จ์ผ ๋จ๋ฝ์ ์์ธํ ํ๋กฌํํธ์ฌ์ผ ํ๋ฉฐ, ๋์ ๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ๊ฐ ํฌํจ๋์ด์ผ ํฉ๋๋ค.
|
107 |
+
"""
|
108 |
+
|
109 |
def save_binary_file(file_name, data):
|
110 |
with open(file_name, "wb") as f:
|
111 |
f.write(data)
|
112 |
|
113 |
+
def generate_prompt_with_gemini(product_name, background_info, additional_info=""):
|
114 |
+
if not GEMINI_API_KEY:
|
115 |
+
return "Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ ๋ณ์ GEMINI_API_KEY๋ฅผ ์ค์ ํ๊ฑฐ๋ ์ฝ๋์ ์ง์ ์
๋ ฅํ์ธ์."
|
|
|
|
|
|
|
116 |
try:
|
117 |
+
prompt_request = f"""
|
118 |
+
์ํ๋ช
: {product_name}
|
119 |
+
๋ฐฐ๊ฒฝ ์ ํ: {background_info.get('english', 'studio')}
|
120 |
+
๋ฐฐ๊ฒฝ ์นดํ
๊ณ ๋ฆฌ: {background_info.get('category', '')}
|
121 |
+
๋ฐฐ๊ฒฝ ์ด๋ฆ: {background_info.get('name', '')}
|
122 |
+
์ถ๊ฐ ์์ฒญ์ฌํญ: {additional_info}
|
123 |
+
์ค์ ์๊ตฌ์ฌํญ:
|
124 |
+
1. ์ํ์ด ํฌ๊ฒ ๋ถ๊ฐ๋๊ณ ์ด๋ฏธ์ง์์ ์ค์ฌ์ ์ธ ์์น๋ฅผ ์ฐจ์งํ๋๋ก ํ๋กฌํํธ๋ฅผ ์์ฑํด์ฃผ์ธ์.
|
125 |
+
2. ์ด๋ฏธ์ง๋ ์ ํํ 1:1 ๋น์จ(์ ์ฌ๊ฐํ)์ด์ด์ผ ํฉ๋๋ค.
|
126 |
+
3. ์ํ์ ์ ์ฌ๊ฐํ ํ๋ ์์ ์ ์ค์์ ์์นํด์ผ ํฉ๋๋ค.
|
127 |
+
4. ์ํ์ ๋์์ธ, ์์, ํํ, ๋ก๊ณ ๋ฑ ๋ณธ์ง์ ํน์ฑ์ ์ ๋ ์์ ํ์ง ๋ง์ธ์.
|
128 |
+
5. ํ๊ฒฝ๊ณผ์ ์์ฐ์ค๋ฌ์ด ํตํฉ์ ์ํ ์กฐ๋ช
ํจ๊ณผ์ ๊ทธ๋ฆผ์๋ ํฌํจํด์ฃผ์ธ์.
|
129 |
+
6. ์ํ์ ๋ ๋๋ณด์ด๊ฒ ํ๋ ๋ฐฐ๊ฒฝ ํ๊ฒฝ์ ์ค๋ช
ํด์ฃผ์ธ์.
|
130 |
+
7. ๊ณ ๊ธ์ค๋ฌ์ด ์์
๊ด๊ณ ํ์ง์ ์ด๋ฏธ์ง๊ฐ ๋๋๋ก ํ๊ฒฝ ์ค๋ช
์ ํด์ฃผ์ธ์.
|
131 |
+
8. ํ๋กฌํํธ ๋์ ๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ "--ar 1:1 --s 750 --q 2"๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.
|
132 |
+
ํ๊ตญ์ด ์
๋ ฅ ๋ด์ฉ์ ์์ด๋ก ์ ์ ํ ๋ฒ์ญํ์ฌ ๋ฐ์ํด์ฃผ์ธ์.
|
133 |
+
"""
|
134 |
+
model = genai.GenerativeModel(
|
135 |
+
'gemini-2.0-flash',
|
136 |
+
system_instruction=generate_system_instruction()
|
|
|
|
|
|
|
|
|
137 |
)
|
138 |
+
response = model.generate_content(
|
139 |
+
prompt_request,
|
140 |
+
generation_config=genai.types.GenerationConfig(
|
141 |
+
temperature=0.7,
|
142 |
+
top_p=0.95,
|
143 |
+
top_k=64,
|
144 |
+
max_output_tokens=1024,
|
145 |
+
)
|
146 |
+
)
|
147 |
+
response_text = response.text.strip()
|
148 |
+
if "--ar 1:1" not in response_text:
|
149 |
+
response_text = response_text.rstrip(".") + ". --ar 1:1 --s 750 --q 2"
|
150 |
|
151 |
+
# ๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ ์ ๊ฑฐํ๊ณ ๋ฐํ (์ด๋ฏธ์ง ์์ฑ์์๋ ํ์์์)
|
152 |
+
cleaned_response = re.sub(r'--ar \d+:\d+|--s \d+|--q \d+', '', response_text).strip()
|
153 |
+
return cleaned_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
except Exception as e:
|
155 |
+
return f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
+
def get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract):
|
158 |
+
if bg_type == "์ฌํ ๋ฐฐ๊ฒฝ":
|
159 |
+
return {
|
160 |
+
"category": "์ฌํ ๋ฐฐ๊ฒฝ",
|
161 |
+
"name": simple,
|
162 |
+
"english": SIMPLE_BACKGROUNDS.get(simple, "white background")
|
163 |
+
}
|
164 |
+
elif bg_type == "์คํ๋์ค ๋ฐฐ๊ฒฝ":
|
165 |
+
return {
|
166 |
+
"category": "์คํ๋์ค ๋ฐฐ๊ฒฝ",
|
167 |
+
"name": studio,
|
168 |
+
"english": STUDIO_BACKGROUNDS.get(studio, "product photography studio")
|
169 |
+
}
|
170 |
+
elif bg_type == "์์ฐ ํ๊ฒฝ":
|
171 |
+
return {
|
172 |
+
"category": "์์ฐ ํ๊ฒฝ",
|
173 |
+
"name": nature,
|
174 |
+
"english": NATURE_BACKGROUNDS.get(nature, "natural environment")
|
175 |
+
}
|
176 |
+
elif bg_type == "์ค๋ด ํ๊ฒฝ":
|
177 |
+
return {
|
178 |
+
"category": "์ค๋ด ํ๊ฒฝ",
|
179 |
+
"name": indoor,
|
180 |
+
"english": INDOOR_BACKGROUNDS.get(indoor, "indoor environment")
|
181 |
+
}
|
182 |
+
elif bg_type == "์ถ์/ํน์ ๋ฐฐ๊ฒฝ":
|
183 |
+
return {
|
184 |
+
"category": "์ถ์/ํน์ ๋ฐฐ๊ฒฝ",
|
185 |
+
"name": abstract,
|
186 |
+
"english": ABSTRACT_BACKGROUNDS.get(abstract, "abstract background")
|
187 |
+
}
|
188 |
else:
|
189 |
+
return {
|
190 |
+
"category": "๊ธฐ๋ณธ ๋ฐฐ๊ฒฝ",
|
191 |
+
"name": "ํ์ดํธ ๋ฐฐ๊ฒฝ",
|
192 |
+
"english": "white background"
|
193 |
+
}
|
194 |
|
195 |
def generate_with_images(prompt, images, variation_index=0):
|
196 |
try:
|
197 |
+
api_key = os.environ.get("GEMINI_API_KEY")
|
198 |
+
if not api_key:
|
199 |
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
200 |
|
201 |
+
client = genai.Client(api_key=api_key)
|
202 |
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}, ๋ณํ ์ธ๋ฑ์ค: {variation_index}")
|
203 |
|
204 |
variation_suffixes = [
|
|
|
272 |
return None, "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", ""
|
273 |
|
274 |
if prompt and prompt.strip():
|
275 |
+
final_prompt = prompt
|
|
|
|
|
|
|
|
|
276 |
else:
|
277 |
final_prompt = "Please creatively transform this image into a more vivid and artistic version. Do not include any text or watermarks in the generated image."
|
278 |
logger.info("Default prompt generated for single image")
|
|
|
328 |
|
329 |
return results[0], results[1], results[2], results[3], combined_status, combined_prompts
|
330 |
|
331 |
+
# UI ๊ตฌ์ฑ
|
332 |
+
with gr.Blocks(title="์ด๋ฏธ์ง ์์ฑ๊ธฐ & ํ๋กฌํํธ ์์ฑ๊ธฐ") as demo:
|
333 |
+
gr.Markdown("# ์ด์ปค๋จธ์ค ์ด๋ฏธ์ง ๋ณํ ์์ฑ๊ธฐ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
with gr.Row():
|
336 |
+
with gr.Column(scale=1):
|
337 |
# ์ด๋ฏธ์ง ์
๋ก๋ ์น์
|
338 |
+
image_input = gr.Image(type="pil", label="์ํ ์ด๋ฏธ์ง ์
๋ก๋", image_mode="RGB")
|
|
|
|
|
339 |
|
340 |
+
# ์ํ๋ช
์น์
|
341 |
+
product_name = gr.Textbox(label="์ํ๋ช
", placeholder="์: ์คํจ์ผ์ด ํ๋ธ, ํ
๋ธ๋ฌ ๋ฑ", interactive=True)
|
|
|
342 |
|
343 |
+
# ๋ฐฐ๊ฒฝ ์ ํ์ ์ ํํ๊ธฐ ์ํ ๋ผ๋์ค ๋ฒํผ
|
344 |
+
bg_type = gr.Radio(
|
|
|
345 |
choices=["์ฌํ ๋ฐฐ๊ฒฝ", "์คํ๋์ค ๋ฐฐ๊ฒฝ", "์์ฐ ํ๊ฒฝ", "์ค๋ด ํ๊ฒฝ", "์ถ์/ํน์ ๋ฐฐ๊ฒฝ"],
|
346 |
label="๋ฐฐ๊ฒฝ ์ ํ",
|
347 |
value="์ฌํ ๋ฐฐ๊ฒฝ"
|
348 |
)
|
349 |
|
350 |
# ๊ฐ ๋ฐฐ๊ฒฝ ์ ํ์ ๋ง๋ ๋๋กญ๋ค์ด ์ปดํฌ๋ํธ๋ค
|
351 |
+
with gr.Group():
|
352 |
+
simple_dropdown = gr.Dropdown(
|
353 |
+
choices=list(SIMPLE_BACKGROUNDS.keys()),
|
354 |
+
value=list(SIMPLE_BACKGROUNDS.keys())[0] if SIMPLE_BACKGROUNDS else None,
|
355 |
+
label="์ฌํ ๋ฐฐ๊ฒฝ ์ ํ",
|
356 |
+
visible=True,
|
357 |
+
interactive=True
|
358 |
+
)
|
359 |
+
|
360 |
+
studio_dropdown = gr.Dropdown(
|
361 |
+
choices=list(STUDIO_BACKGROUNDS.keys()),
|
362 |
+
value=list(STUDIO_BACKGROUNDS.keys())[0] if STUDIO_BACKGROUNDS else None,
|
363 |
+
label="์คํ๋์ค ๋ฐฐ๊ฒฝ ์ ํ",
|
364 |
+
visible=False,
|
365 |
+
interactive=True
|
366 |
+
)
|
367 |
+
|
368 |
+
nature_dropdown = gr.Dropdown(
|
369 |
+
choices=list(NATURE_BACKGROUNDS.keys()),
|
370 |
+
value=list(NATURE_BACKGROUNDS.keys())[0] if NATURE_BACKGROUNDS else None,
|
371 |
+
label="์์ฐ ํ๊ฒฝ ์ ํ",
|
372 |
+
visible=False,
|
373 |
+
interactive=True
|
374 |
+
)
|
375 |
+
|
376 |
+
indoor_dropdown = gr.Dropdown(
|
377 |
+
choices=list(INDOOR_BACKGROUNDS.keys()),
|
378 |
+
value=list(INDOOR_BACKGROUNDS.keys())[0] if INDOOR_BACKGROUNDS else None,
|
379 |
+
label="์ค๋ด ํ๊ฒฝ ์ ํ",
|
380 |
+
visible=False,
|
381 |
+
interactive=True
|
382 |
+
)
|
383 |
+
|
384 |
+
abstract_dropdown = gr.Dropdown(
|
385 |
+
choices=list(ABSTRACT_BACKGROUNDS.keys()),
|
386 |
+
value=list(ABSTRACT_BACKGROUNDS.keys())[0] if ABSTRACT_BACKGROUNDS else None,
|
387 |
+
label="์ถ์/ํน์ ๋ฐฐ๊ฒฝ ์ ํ",
|
388 |
+
visible=False,
|
389 |
+
interactive=True
|
390 |
+
)
|
391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
additional_info = gr.Textbox(
|
393 |
label="์ถ๊ฐ ์์ฒญ์ฌํญ (์ ํ์ฌํญ)",
|
394 |
placeholder="์: ๊ณ ๊ธ์ค๋ฌ์ด ๋๋, ๋ฐ์ ์กฐ๋ช
, ์์ฐ์ค๋ฌ์ด ๋ณด์กฐ์ ์ธ ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์ ๋ฑ",
|
395 |
+
lines=3,
|
396 |
+
interactive=True
|
397 |
)
|
398 |
|
399 |
+
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ
|
|
|
|
|
400 |
generate_prompt_btn = gr.Button("ํ๋กฌํํธ ์์ฑ")
|
401 |
|
402 |
+
# ์์ฑ๋ ํ๋กฌํํธ ํ์
|
403 |
+
prompt_output = gr.Textbox(label="์์ฑ๋ ํ๋กฌํํธ", lines=5)
|
404 |
+
|
405 |
+
# ์ปค์คํ
ํ๋กฌํํธ ์
๋ ฅ (์ ํ์ )
|
406 |
+
custom_prompt = gr.Textbox(
|
407 |
+
label="์ปค์คํ
ํ๋กฌํํธ (์ ํ์ฌํญ)",
|
408 |
+
placeholder="์ง์ ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ์์์ ์์ฑ๋ ํ๋กฌํํธ๋ฅผ ์์ ํ ์ ์์ต๋๋ค",
|
409 |
lines=3,
|
410 |
+
interactive=True
|
|
|
411 |
)
|
412 |
|
413 |
with gr.Row():
|
414 |
+
submit_single_btn = gr.Button('์ด๋ฏธ์ง 1์ฅ ์์ฑ')
|
415 |
+
submit_btn = gr.Button('์ด๋ฏธ์ง 4์ฅ ์์ฑ')
|
416 |
|
417 |
+
with gr.Column(scale=1):
|
418 |
+
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ์น์
|
419 |
with gr.Row():
|
420 |
with gr.Column():
|
421 |
output_image1 = gr.Image(label="์ด๋ฏธ์ง #1", type="filepath")
|
|
|
424 |
output_image2 = gr.Image(label="์ด๋ฏธ์ง #2", type="filepath")
|
425 |
output_image4 = gr.Image(label="์ด๋ฏธ์ง #4", type="filepath")
|
426 |
|
427 |
+
# ๊ฒฐ๊ณผ ์ ๋ณด
|
428 |
output_text = gr.Textbox(label="๊ฒฐ๊ณผ ์ ๋ณด", lines=2)
|
429 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", lines=2)
|
430 |
+
|
431 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ๋๋กญ๋ค์ด ํ์ ์
๋ฐ์ดํธ
|
432 |
def update_dropdowns(bg_type):
|
433 |
return {
|
|
|
437 |
indoor_dropdown: gr.update(visible=(bg_type == "์ค๋ด ํ๊ฒฝ")),
|
438 |
abstract_dropdown: gr.update(visible=(bg_type == "์ถ์/ํน์ ๋ฐฐ๊ฒฝ"))
|
439 |
}
|
440 |
+
|
441 |
+
# ํ๋กฌํํธ ์์ฑ ํจ์
|
442 |
+
def generate_product_prompt(image, bg_type, simple, studio, nature, indoor, abstract, product_text, additional_text):
|
443 |
+
if image is None:
|
444 |
+
return "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์."
|
445 |
+
|
446 |
+
product_text = product_text.strip() or "์ ํ"
|
447 |
+
|
448 |
+
# ๋ฐฐ๊ฒฝ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
449 |
+
background_info = get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract)
|
450 |
+
|
451 |
+
try:
|
452 |
+
prompt = generate_prompt_with_gemini(product_text, background_info, additional_text)
|
453 |
+
|
454 |
+
if not GEMINI_API_KEY:
|
455 |
+
return "Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ ๋ณ์ GEMINI_API_KEY๋ฅผ ์ค์ ํ๊ฑฐ๋ ์ฝ๋์ ์ง์ ์
๋ ฅํ์ธ์."
|
456 |
+
|
457 |
+
return prompt
|
458 |
+
except Exception as e:
|
459 |
+
return f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
460 |
|
461 |
+
# ํ๋กฌํํธ ์ถ๋ ฅ์ ์ปค์คํ
ํ๋กฌํํธ์ ๋ณต์ฌ
|
462 |
+
def copy_to_custom(prompt):
|
463 |
+
return prompt
|
464 |
+
|
465 |
+
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
466 |
+
bg_type.change(
|
467 |
fn=update_dropdowns,
|
468 |
+
inputs=[bg_type],
|
469 |
outputs=[simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, abstract_dropdown]
|
470 |
)
|
471 |
+
|
|
|
472 |
generate_prompt_btn.click(
|
473 |
+
fn=generate_product_prompt,
|
474 |
inputs=[
|
475 |
+
image_input,
|
476 |
+
bg_type,
|
477 |
simple_dropdown,
|
478 |
studio_dropdown,
|
479 |
nature_dropdown,
|
|
|
482 |
product_name,
|
483 |
additional_info
|
484 |
],
|
485 |
+
outputs=prompt_output
|
486 |
+
)
|
487 |
+
|
488 |
+
# ์์ฑ๋ ํ๋กฌํํธ๋ฅผ ์ปค์คํ
ํ๋กฌํํธ ํ๋์ ๋ณต์ฌ
|
489 |
+
prompt_output.change(
|
490 |
+
fn=copy_to_custom,
|
491 |
+
inputs=[prompt_output],
|
492 |
+
outputs=[custom_prompt]
|
493 |
)
|
494 |
|
495 |
# ๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
496 |
submit_single_btn.click(
|
497 |
fn=lambda image1, prompt: process_images_with_prompt(image1, prompt, 0),
|
498 |
+
inputs=[image_input, custom_prompt],
|
499 |
outputs=[output_image1, output_text, prompt_display],
|
500 |
)
|
501 |
|
502 |
# 4์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
503 |
submit_btn.click(
|
504 |
fn=generate_multiple_images,
|
505 |
+
inputs=[image_input, custom_prompt],
|
506 |
outputs=[output_image1, output_image2, output_image3, output_image4, output_text, prompt_display],
|
507 |
)
|
508 |
|
509 |
+
if __name__ == "__main__":
|
510 |
+
demo.queue()
|
511 |
+
demo.launch()
|