Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ def translate_prompt_to_english(prompt):
|
|
61 |
logger.exception("๋ฒ์ญ ์ค ์ค๋ฅ ๋ฐ์:")
|
62 |
return prompt
|
63 |
|
64 |
-
def preprocess_prompt(prompt, image1, image2, image3,
|
65 |
"""
|
66 |
ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๊ณ ๊ธฐ๋ฅ ๋ช
๋ น์ ํด์
|
67 |
"""
|
@@ -105,13 +105,30 @@ def preprocess_prompt(prompt, image1, image2, image3, background_options=None):
|
|
105 |
|
106 |
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt or "๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ" in prompt:
|
107 |
# ๋ฐฐ๊ฒฝ ์ต์
์ด ์์ผ๋ฉด ๊ทธ๊ฒ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋กฌํํธ ์์ฑ
|
108 |
-
if
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
#
|
114 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
else:
|
116 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
117 |
|
@@ -173,7 +190,7 @@ def generate_with_images(prompt, images):
|
|
173 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
174 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
175 |
|
176 |
-
def process_images_with_prompt(image1, image2, image3, prompt,
|
177 |
"""
|
178 |
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ์ฌ ์ต์ข
์์ด ํ๋กฌํํธ(final_prompt)๋ฅผ ์์ฑํ ํ,
|
179 |
API๋ฅผ ํธ์ถํ์ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
@@ -185,7 +202,7 @@ def process_images_with_prompt(image1, image2, image3, prompt, background_option
|
|
185 |
return None, "์ ์ด๋ ํ๋์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", ""
|
186 |
|
187 |
if prompt and prompt.strip():
|
188 |
-
processed_prompt = preprocess_prompt(prompt, image1, image2, image3,
|
189 |
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
190 |
final_prompt = translate_prompt_to_english(processed_prompt)
|
191 |
else:
|
@@ -207,35 +224,58 @@ def process_images_with_prompt(image1, image2, image3, prompt, background_option
|
|
207 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
208 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
209 |
|
210 |
-
def process_and_show_prompt(image1, image2, image3, prompt,
|
|
|
211 |
try:
|
212 |
-
# ๋ฐฐ๊ฒฝ
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
220 |
|
221 |
-
result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt,
|
222 |
|
223 |
# ์ ํ๋ ์ต์
์ ๋ฌธ์์ด๋ก ๊ตฌ์ฑ
|
224 |
-
options_summary = ""
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
-
|
|
|
|
|
|
|
229 |
except Exception as e:
|
230 |
logger.exception("์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
231 |
-
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt, ""
|
232 |
|
233 |
# ์ ํ ์ต์
ํ์/์จ๊น ์ฒ๋ฆฌ ํจ์
|
234 |
def toggle_background_options(selection):
|
235 |
if selection == "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ":
|
236 |
-
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
|
|
|
|
|
|
237 |
else:
|
238 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
|
|
|
|
|
|
239 |
|
240 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ฅธ ์ธ๋ถ ์คํ์ผ ์ต์
์
๋ฐ์ดํธ
|
241 |
def update_background_style_options(background_type):
|
@@ -248,13 +288,31 @@ def update_background_style_options(background_type):
|
|
248 |
else:
|
249 |
return gr.update(choices=["์ ํํ์ธ์"], value="์ ํํ์ธ์")
|
250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
# Gradio ์ธํฐํ์ด์ค
|
252 |
with gr.Blocks() as demo:
|
253 |
gr.HTML(
|
254 |
"""
|
255 |
<div style="text-align: center; margin-bottom: 1rem;">
|
256 |
-
<h1
|
257 |
-
<p
|
258 |
</div>
|
259 |
"""
|
260 |
)
|
@@ -262,11 +320,12 @@ with gr.Blocks() as demo:
|
|
262 |
current_selection = gr.State("")
|
263 |
|
264 |
with gr.Row():
|
265 |
-
with gr.Column():
|
266 |
with gr.Row():
|
267 |
-
image1_input = gr.Image(type="pil", label="#1", image_mode="RGB")
|
268 |
-
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
|
269 |
-
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
|
|
|
270 |
prompt_input = gr.Textbox(
|
271 |
lines=3,
|
272 |
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.",
|
@@ -277,12 +336,19 @@ with gr.Blocks() as demo:
|
|
277 |
image_change_btn = gr.Button("์ด๋ฏธ์ง ๋ณ๊ฒฝ")
|
278 |
text_remove_btn = gr.Button("๊ธ์์ง์ฐ๊ธฐ")
|
279 |
clothes_change_btn = gr.Button("์ท๋ฐ๊พธ๊ธฐ")
|
280 |
-
background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ")
|
281 |
composite_product_btn = gr.Button("์ํํฉ์ฑ")
|
282 |
|
283 |
-
# ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ๊ด๋ จ
|
284 |
-
with gr.Row(visible=False) as
|
285 |
-
gr.HTML("<h3>๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ์ต์
</h3>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
|
287 |
# ์ ํ๊ตฐ ์นดํ
๊ณ ๋ฆฌ ๋๋กญ๋ค์ด
|
288 |
product_category = gr.Dropdown(
|
@@ -308,13 +374,58 @@ with gr.Blocks() as demo:
|
|
308 |
visible=False
|
309 |
)
|
310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
submit_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ", variant="primary")
|
312 |
|
313 |
-
with gr.Column():
|
314 |
output_image = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
315 |
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง")
|
316 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True)
|
317 |
-
|
|
|
318 |
|
319 |
# ์ ํ ์ต์
๋ฒํผ ํด๋ฆญ ์ ํ๋กฌํํธ ์
๋ ฅ๋ ์
๋ฐ์ดํธ (ํ๊ตญ์ด ๋ฌธ๊ตฌ)
|
320 |
image_change_btn.click(
|
@@ -328,7 +439,9 @@ with gr.Blocks() as demo:
|
|
328 |
).then(
|
329 |
fn=toggle_background_options,
|
330 |
inputs=[current_selection],
|
331 |
-
outputs=[
|
|
|
|
|
332 |
)
|
333 |
|
334 |
text_remove_btn.click(
|
@@ -342,7 +455,9 @@ with gr.Blocks() as demo:
|
|
342 |
).then(
|
343 |
fn=toggle_background_options,
|
344 |
inputs=[current_selection],
|
345 |
-
outputs=[
|
|
|
|
|
346 |
)
|
347 |
|
348 |
clothes_change_btn.click(
|
@@ -356,7 +471,9 @@ with gr.Blocks() as demo:
|
|
356 |
).then(
|
357 |
fn=toggle_background_options,
|
358 |
inputs=[current_selection],
|
359 |
-
outputs=[
|
|
|
|
|
360 |
)
|
361 |
|
362 |
background_change_btn.click(
|
@@ -370,7 +487,9 @@ with gr.Blocks() as demo:
|
|
370 |
).then(
|
371 |
fn=toggle_background_options,
|
372 |
inputs=[current_selection],
|
373 |
-
outputs=[
|
|
|
|
|
374 |
)
|
375 |
|
376 |
composite_product_btn.click(
|
@@ -384,7 +503,9 @@ with gr.Blocks() as demo:
|
|
384 |
).then(
|
385 |
fn=toggle_background_options,
|
386 |
inputs=[current_selection],
|
387 |
-
outputs=[
|
|
|
|
|
388 |
)
|
389 |
|
390 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ์ธ๋ถ ์คํ์ผ ์ต์
์
๋ฐ์ดํธ
|
@@ -394,13 +515,58 @@ with gr.Blocks() as demo:
|
|
394 |
outputs=[background_style]
|
395 |
)
|
396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
398 |
submit_btn.click(
|
399 |
fn=process_and_show_prompt,
|
400 |
-
inputs=[image1_input, image2_input, image3_input, prompt_input,
|
401 |
-
|
|
|
|
|
402 |
)
|
403 |
|
|
|
404 |
gr.Markdown(
|
405 |
"""
|
406 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
|
|
61 |
logger.exception("๋ฒ์ญ ์ค ์ค๋ฅ ๋ฐ์:")
|
62 |
return prompt
|
63 |
|
64 |
+
def preprocess_prompt(prompt, image1, image2, image3, bg_options=None):
|
65 |
"""
|
66 |
ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๊ณ ๊ธฐ๋ฅ ๋ช
๋ น์ ํด์
|
67 |
"""
|
|
|
105 |
|
106 |
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt or "๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ" in prompt:
|
107 |
# ๋ฐฐ๊ฒฝ ์ต์
์ด ์์ผ๋ฉด ๊ทธ๊ฒ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋กฌํํธ ์์ฑ
|
108 |
+
if bg_options and all([bg_options.get("product_name"), bg_options.get("background_type"), bg_options.get("background_style")]):
|
109 |
+
product_name = bg_options.get("product_name", "")
|
110 |
+
product_category = bg_options.get("product_category", "์ผ๋ฐ ์ํ")
|
111 |
+
background_type = bg_options.get("background_type", "์์ฐ ๋ฐฐ๊ฒฝ")
|
112 |
+
background_style = bg_options.get("background_style", "์ฒ")
|
113 |
+
lighting = bg_options.get("lighting", "์์ฐ๊ด")
|
114 |
+
texture = bg_options.get("texture", "")
|
115 |
+
color_tone = bg_options.get("color_tone", "")
|
116 |
+
mood = bg_options.get("mood", "")
|
117 |
|
118 |
+
# ์์ธ ํ๋กฌํํธ ์์ฑ
|
119 |
+
prompt = f"{product_name} ์ํ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ {background_type} ์ค {background_style}์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. "
|
120 |
+
|
121 |
+
# ์ถ๊ฐ ์ธ๋ถ ์ฌํญ ํฌํจ
|
122 |
+
if lighting:
|
123 |
+
prompt += f"{lighting} ์กฐ๋ช
์ ์ฌ์ฉํ๊ณ , "
|
124 |
+
if texture:
|
125 |
+
prompt += f"{texture} ์ง๊ฐ์ ํํํ๋ฉฐ, "
|
126 |
+
if color_tone:
|
127 |
+
prompt += f"{color_tone} : ์ ์ฒด ์๊ฐ์ผ๋ก ์ฒ๋ฆฌํ๊ณ , "
|
128 |
+
if mood:
|
129 |
+
prompt += f"{mood}ํ ๋ถ์๊ธฐ๋ก "
|
130 |
+
|
131 |
+
prompt += f"์ฐ์ถํด์ฃผ์ธ์. {product_category} ์ํ์ ์์, ์ง๊ฐ, ํํ๋ ์๋ฒฝํ๊ฒ ๋ณด์กดํ๊ณ ๊ณ ํ์ง ์ํ ์ฌ์ง ์คํ์ผ๋ก ์ ์ํด์ฃผ์ธ์."
|
132 |
else:
|
133 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
134 |
|
|
|
190 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
191 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
192 |
|
193 |
+
def process_images_with_prompt(image1, image2, image3, prompt, bg_options=None):
|
194 |
"""
|
195 |
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ์ฌ ์ต์ข
์์ด ํ๋กฌํํธ(final_prompt)๋ฅผ ์์ฑํ ํ,
|
196 |
API๋ฅผ ํธ์ถํ์ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
|
|
202 |
return None, "์ ์ด๋ ํ๋์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", ""
|
203 |
|
204 |
if prompt and prompt.strip():
|
205 |
+
processed_prompt = preprocess_prompt(prompt, image1, image2, image3, bg_options)
|
206 |
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
207 |
final_prompt = translate_prompt_to_english(processed_prompt)
|
208 |
else:
|
|
|
224 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
225 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
226 |
|
227 |
+
def process_and_show_prompt(image1, image2, image3, prompt, product_name, product_category,
|
228 |
+
background_type, background_style, lighting, texture, color_tone, mood):
|
229 |
try:
|
230 |
+
# ๋ฐฐ๊ฒฝ ์ต์
์ ๋์
๋๋ฆฌ๋ก ๊ตฌ์ฑ
|
231 |
+
bg_options = {
|
232 |
+
"product_name": product_name,
|
233 |
+
"product_category": product_category,
|
234 |
+
"background_type": background_type,
|
235 |
+
"background_style": background_style,
|
236 |
+
"lighting": lighting,
|
237 |
+
"texture": texture,
|
238 |
+
"color_tone": color_tone,
|
239 |
+
"mood": mood
|
240 |
+
}
|
241 |
|
242 |
+
result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, bg_options)
|
243 |
|
244 |
# ์ ํ๋ ์ต์
์ ๋ฌธ์์ด๋ก ๊ตฌ์ฑ
|
245 |
+
options_summary = f"์ํ๋ช
: {product_name}\n"
|
246 |
+
options_summary += f"์ ํ๊ตฐ: {product_category}\n"
|
247 |
+
options_summary += f"๋ฐฐ๊ฒฝ ์ ํ: {background_type}\n"
|
248 |
+
options_summary += f"์ธ๋ถ ์คํ์ผ: {background_style}\n"
|
249 |
+
|
250 |
+
if lighting:
|
251 |
+
options_summary += f"์กฐ๋ช
: {lighting}\n"
|
252 |
+
if texture:
|
253 |
+
options_summary += f"๋ฐฐ๊ฒฝ ์ง๊ฐ: {texture}\n"
|
254 |
+
if color_tone:
|
255 |
+
options_summary += f"์๊ฐ: {color_tone}\n"
|
256 |
+
if mood:
|
257 |
+
options_summary += f"๋ถ์๊ธฐ: {mood}\n"
|
258 |
|
259 |
+
# ํ๊ตญ์ด์ ์์ด ํ๋กฌํํธ ๋น๊ต๋ฅผ ์ํด ์๋ณธ ํ๋กฌํํธ ํ์ธ
|
260 |
+
kr_prompt = preprocess_prompt(prompt, image1, image2, image3, bg_options)
|
261 |
+
|
262 |
+
return result_img, status, final_prompt, options_summary, kr_prompt
|
263 |
except Exception as e:
|
264 |
logger.exception("์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
265 |
+
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt, "", ""
|
266 |
|
267 |
# ์ ํ ์ต์
ํ์/์จ๊น ์ฒ๋ฆฌ ํจ์
|
268 |
def toggle_background_options(selection):
|
269 |
if selection == "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ":
|
270 |
+
return (gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
271 |
+
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
272 |
+
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
273 |
+
gr.update(visible=True))
|
274 |
else:
|
275 |
+
return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
276 |
+
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
277 |
+
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
278 |
+
gr.update(visible=False))
|
279 |
|
280 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ฅธ ์ธ๋ถ ์คํ์ผ ์ต์
์
๋ฐ์ดํธ
|
281 |
def update_background_style_options(background_type):
|
|
|
288 |
else:
|
289 |
return gr.update(choices=["์ ํํ์ธ์"], value="์ ํํ์ธ์")
|
290 |
|
291 |
+
# ์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์
๋ฐ์ดํธ ํจ์
|
292 |
+
def update_preview(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood):
|
293 |
+
preview = f"์ํ๋ช
: {product_name}\n"
|
294 |
+
preview += f"์ ํ๊ตฐ: {product_category}\n"
|
295 |
+
preview += f"๋ฐฐ๊ฒฝ ์ ํ: {background_type}\n"
|
296 |
+
preview += f"์ธ๋ถ ์คํ์ผ: {background_style}\n"
|
297 |
+
|
298 |
+
if lighting:
|
299 |
+
preview += f"์กฐ๋ช
: {lighting}\n"
|
300 |
+
if texture:
|
301 |
+
preview += f"๋ฐฐ๊ฒฝ ์ง๊ฐ: {texture}\n"
|
302 |
+
if color_tone:
|
303 |
+
preview += f"์๊ฐ: {color_tone}\n"
|
304 |
+
if mood:
|
305 |
+
preview += f"๋ถ์๊ธฐ: {mood}\n"
|
306 |
+
|
307 |
+
return preview
|
308 |
+
|
309 |
# Gradio ์ธํฐํ์ด์ค
|
310 |
with gr.Blocks() as demo:
|
311 |
gr.HTML(
|
312 |
"""
|
313 |
<div style="text-align: center; margin-bottom: 1rem;">
|
314 |
+
<h1>์ด์ปค๋จธ์ค ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ์์ฑ๊ธฐ</h1>
|
315 |
+
<p>์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ์ํ๋ ๋ฐฐ๊ฒฝ ์ต์
์ ์ ํํ์ฌ ์๋ก์ด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ธ์.</p>
|
316 |
</div>
|
317 |
"""
|
318 |
)
|
|
|
320 |
current_selection = gr.State("")
|
321 |
|
322 |
with gr.Row():
|
323 |
+
with gr.Column(scale=1):
|
324 |
with gr.Row():
|
325 |
+
image1_input = gr.Image(type="pil", label="#1 ์ํ ์ด๋ฏธ์ง", image_mode="RGB")
|
326 |
+
image2_input = gr.Image(type="pil", label="#2 (์ ํ์ฌํญ)", image_mode="RGB")
|
327 |
+
image3_input = gr.Image(type="pil", label="#3 (์ ํ์ฌํญ)", image_mode="RGB")
|
328 |
+
|
329 |
prompt_input = gr.Textbox(
|
330 |
lines=3,
|
331 |
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.",
|
|
|
336 |
image_change_btn = gr.Button("์ด๋ฏธ์ง ๋ณ๊ฒฝ")
|
337 |
text_remove_btn = gr.Button("๊ธ์์ง์ฐ๊ธฐ")
|
338 |
clothes_change_btn = gr.Button("์ท๋ฐ๊พธ๊ธฐ")
|
339 |
+
background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ", variant="primary")
|
340 |
composite_product_btn = gr.Button("์ํํฉ์ฑ")
|
341 |
|
342 |
+
# ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ๊ด๋ จ ์น์
(๊ธฐ๋ณธ์ ์ผ๋ก ์จ๊น ์ํ)
|
343 |
+
with gr.Row(visible=False) as background_header:
|
344 |
+
gr.HTML("<h3 style='margin-top: 20px; margin-bottom: 10px; width: 100%; text-align: center;'>๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ์ต์
</h3>")
|
345 |
+
|
346 |
+
# ์ํ๋ช
์
๋ ฅ
|
347 |
+
product_name = gr.Textbox(
|
348 |
+
label="์ํ๋ช
์
๋ ฅ",
|
349 |
+
placeholder="์ํ๋ช
์ ์
๋ ฅํด์ฃผ์ธ์",
|
350 |
+
visible=False
|
351 |
+
)
|
352 |
|
353 |
# ์ ํ๊ตฐ ์นดํ
๊ณ ๋ฆฌ ๋๋กญ๋ค์ด
|
354 |
product_category = gr.Dropdown(
|
|
|
374 |
visible=False
|
375 |
)
|
376 |
|
377 |
+
# ์ถ๊ฐ ์ ํ ์ต์
ํค๋
|
378 |
+
with gr.Row(visible=False) as additional_header:
|
379 |
+
gr.HTML("<h4 style='margin-top: 15px; margin-bottom: 10px; width: 100%; text-align: center;'>์ถ๊ฐ ์ ํ ์ต์
</h4>")
|
380 |
+
|
381 |
+
# ์กฐ๋ช
๋๋กญ๋ค์ด
|
382 |
+
lighting = gr.Dropdown(
|
383 |
+
choices=["์์ฐ๊ด", "๋ฐ๋ปํ ์กฐ๋ช
", "๊ทธ๋ฆผ์ ์๋ ์กฐ๋ช
", "๋ฏธ๋๋ฉ ์กฐ๋ช
"],
|
384 |
+
label="์กฐ๋ช
์ ํ",
|
385 |
+
value="์์ฐ๊ด",
|
386 |
+
visible=False
|
387 |
+
)
|
388 |
+
|
389 |
+
# ๋ฐฐ๊ฒฝ ์ง๊ฐ ๋๋กญ๋ค์ด
|
390 |
+
texture = gr.Dropdown(
|
391 |
+
choices=["ํฐ ๋ฒฝ", "๋๋ฆฌ์", "๋๋ฌด", "๋ฒฝ๋", "ํฐ ์ฒ", "์๋ฉํธ"],
|
392 |
+
label="๋ฐฐ๊ฒฝ ์ง๊ฐ ์ ํ",
|
393 |
+
value="",
|
394 |
+
visible=False
|
395 |
+
)
|
396 |
+
|
397 |
+
# ์๊ฐ ๋๋กญ๋ค์ด
|
398 |
+
color_tone = gr.Dropdown(
|
399 |
+
choices=["ํ์ดํธ ํค", "๋ธ๋ฃจ ํค", "๋ฐ๋ปํ ์์", "๋ชจ๋
ธํค", "ํ์คํ
"],
|
400 |
+
label="์๊ฐ ์ ํ",
|
401 |
+
value="",
|
402 |
+
visible=False
|
403 |
+
)
|
404 |
+
|
405 |
+
# ๋ถ์๊ธฐ ๋๋กญ๋ค์ด
|
406 |
+
mood = gr.Dropdown(
|
407 |
+
choices=["ํฌ๊ทผํ", "์ฌํํ", "๋ชจ๋ํ", "๋ด์ถ๋ด", "๋ฏธ๋๋ฉ"],
|
408 |
+
label="๋ถ์๊ธฐ ์ ํ",
|
409 |
+
value="",
|
410 |
+
visible=False
|
411 |
+
)
|
412 |
+
|
413 |
+
# ์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
414 |
+
selection_preview = gr.Textbox(
|
415 |
+
label="์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ",
|
416 |
+
lines=8,
|
417 |
+
readonly=True,
|
418 |
+
visible=False
|
419 |
+
)
|
420 |
+
|
421 |
submit_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ", variant="primary")
|
422 |
|
423 |
+
with gr.Column(scale=1):
|
424 |
output_image = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
425 |
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง")
|
426 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True)
|
427 |
+
kr_prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (ํ๊ตญ์ด)", visible=True)
|
428 |
+
options_summary = gr.Textbox(label="์ ํ๋ ์ต์
์์ฝ", lines=8, visible=True)
|
429 |
|
430 |
# ์ ํ ์ต์
๋ฒํผ ํด๋ฆญ ์ ํ๋กฌํํธ ์
๋ ฅ๋ ์
๋ฐ์ดํธ (ํ๊ตญ์ด ๋ฌธ๊ตฌ)
|
431 |
image_change_btn.click(
|
|
|
439 |
).then(
|
440 |
fn=toggle_background_options,
|
441 |
inputs=[current_selection],
|
442 |
+
outputs=[background_header, product_name, product_category, background_type,
|
443 |
+
background_style, additional_header, lighting, texture, color_tone,
|
444 |
+
mood, selection_preview]
|
445 |
)
|
446 |
|
447 |
text_remove_btn.click(
|
|
|
455 |
).then(
|
456 |
fn=toggle_background_options,
|
457 |
inputs=[current_selection],
|
458 |
+
outputs=[background_header, product_name, product_category, background_type,
|
459 |
+
background_style, additional_header, lighting, texture, color_tone,
|
460 |
+
mood, selection_preview]
|
461 |
)
|
462 |
|
463 |
clothes_change_btn.click(
|
|
|
471 |
).then(
|
472 |
fn=toggle_background_options,
|
473 |
inputs=[current_selection],
|
474 |
+
outputs=[background_header, product_name, product_category, background_type,
|
475 |
+
background_style, additional_header, lighting, texture, color_tone,
|
476 |
+
mood, selection_preview]
|
477 |
)
|
478 |
|
479 |
background_change_btn.click(
|
|
|
487 |
).then(
|
488 |
fn=toggle_background_options,
|
489 |
inputs=[current_selection],
|
490 |
+
outputs=[background_header, product_name, product_category, background_type,
|
491 |
+
background_style, additional_header, lighting, texture, color_tone,
|
492 |
+
mood, selection_preview]
|
493 |
)
|
494 |
|
495 |
composite_product_btn.click(
|
|
|
503 |
).then(
|
504 |
fn=toggle_background_options,
|
505 |
inputs=[current_selection],
|
506 |
+
outputs=[background_header, product_name, product_category, background_type,
|
507 |
+
background_style, additional_header, lighting, texture, color_tone,
|
508 |
+
mood, selection_preview]
|
509 |
)
|
510 |
|
511 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ์ธ๋ถ ์คํ์ผ ์ต์
์
๋ฐ์ดํธ
|
|
|
515 |
outputs=[background_style]
|
516 |
)
|
517 |
|
518 |
+
# ์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์
๋ฐ์ดํธ (๋ชจ๋ ์ ํ ์ปดํฌ๋ํธ์ ๋ณ๊ฒฝ ์ด๋ฒคํธ์ ์ฐ๊ฒฐ)
|
519 |
+
product_name.change(
|
520 |
+
fn=update_preview,
|
521 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
522 |
+
outputs=[selection_preview]
|
523 |
+
)
|
524 |
+
product_category.change(
|
525 |
+
fn=update_preview,
|
526 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
527 |
+
outputs=[selection_preview]
|
528 |
+
)
|
529 |
+
background_type.change(
|
530 |
+
fn=update_preview,
|
531 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
532 |
+
outputs=[selection_preview]
|
533 |
+
)
|
534 |
+
background_style.change(
|
535 |
+
fn=update_preview,
|
536 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
537 |
+
outputs=[selection_preview]
|
538 |
+
)
|
539 |
+
lighting.change(
|
540 |
+
fn=update_preview,
|
541 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
542 |
+
outputs=[selection_preview]
|
543 |
+
)
|
544 |
+
texture.change(
|
545 |
+
fn=update_preview,
|
546 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
547 |
+
outputs=[selection_preview]
|
548 |
+
)
|
549 |
+
color_tone.change(
|
550 |
+
fn=update_preview,
|
551 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
552 |
+
outputs=[selection_preview]
|
553 |
+
)
|
554 |
+
mood.change(
|
555 |
+
fn=update_preview,
|
556 |
+
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood],
|
557 |
+
outputs=[selection_preview]
|
558 |
+
)
|
559 |
+
|
560 |
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
561 |
submit_btn.click(
|
562 |
fn=process_and_show_prompt,
|
563 |
+
inputs=[image1_input, image2_input, image3_input, prompt_input,
|
564 |
+
product_name, product_category, background_type, background_style,
|
565 |
+
lighting, texture, color_tone, mood],
|
566 |
+
outputs=[output_image, output_text, prompt_display, options_summary, kr_prompt_display],
|
567 |
)
|
568 |
|
569 |
+
|
570 |
gr.Markdown(
|
571 |
"""
|
572 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|