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 |
"""
|
@@ -103,8 +103,17 @@ def preprocess_prompt(prompt, image1, image2, image3):
|
|
103 |
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt:
|
104 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
105 |
|
106 |
-
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt:
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
elif "์ํํฉ์ฑ" in prompt:
|
110 |
prompt = "#1 ์ํ ์ด๋ฏธ์ง์ #2 ์ด๋ฏธ์ง ๋๋ #3 ์ด๋ฏธ์ง๋ฅผ [๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ๋๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํ์ฌ]์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํ๋ผ."
|
@@ -164,7 +173,7 @@ def generate_with_images(prompt, images):
|
|
164 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
165 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
166 |
|
167 |
-
def process_images_with_prompt(image1, image2, image3, prompt):
|
168 |
"""
|
169 |
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ์ฌ ์ต์ข
์์ด ํ๋กฌํํธ(final_prompt)๋ฅผ ์์ฑํ ํ,
|
170 |
API๋ฅผ ํธ์ถํ์ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
@@ -176,7 +185,7 @@ def process_images_with_prompt(image1, image2, image3, prompt):
|
|
176 |
return None, "์ ์ด๋ ํ๋์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", ""
|
177 |
|
178 |
if prompt and prompt.strip():
|
179 |
-
processed_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
180 |
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
181 |
final_prompt = translate_prompt_to_english(processed_prompt)
|
182 |
else:
|
@@ -198,13 +207,46 @@ def process_images_with_prompt(image1, image2, image3, prompt):
|
|
198 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
199 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
200 |
|
201 |
-
def process_and_show_prompt(image1, image2, image3, prompt):
|
202 |
try:
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
except Exception as e:
|
206 |
logger.exception("์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
207 |
-
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
# Gradio ์ธํฐํ์ด์ค
|
210 |
with gr.Blocks() as demo:
|
@@ -217,6 +259,8 @@ with gr.Blocks() as demo:
|
|
217 |
"""
|
218 |
)
|
219 |
|
|
|
|
|
220 |
with gr.Row():
|
221 |
with gr.Column():
|
222 |
with gr.Row():
|
@@ -228,50 +272,133 @@ with gr.Blocks() as demo:
|
|
228 |
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.",
|
229 |
label="ํ๋กฌํํธ (์ ํ ์ฌํญ)"
|
230 |
)
|
|
|
231 |
with gr.Row():
|
232 |
image_change_btn = gr.Button("์ด๋ฏธ์ง ๋ณ๊ฒฝ")
|
233 |
text_remove_btn = gr.Button("๊ธ์์ง์ฐ๊ธฐ")
|
234 |
clothes_change_btn = gr.Button("์ท๋ฐ๊พธ๊ธฐ")
|
235 |
background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ")
|
236 |
-
# ๋ฒํผ ๋ผ๋ฒจ๊ณผ ํด๋ฆญ ์ ๋ฐํ๋๋ ํ๋กฌํํธ ์์
|
237 |
composite_product_btn = gr.Button("์ํํฉ์ฑ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
submit_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ", variant="primary")
|
|
|
239 |
with gr.Column():
|
240 |
output_image = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
241 |
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง")
|
242 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True)
|
|
|
243 |
|
244 |
# ์ ํ ์ต์
๋ฒํผ ํด๋ฆญ ์ ํ๋กฌํํธ ์
๋ ฅ๋ ์
๋ฐ์ดํธ (ํ๊ตญ์ด ๋ฌธ๊ตฌ)
|
245 |
image_change_btn.click(
|
246 |
fn=lambda: "#1 ์ด๋ฏธ์ง์ [๋ค๋ฅธ ๋ชจ์ต]์ผ๋ก ๋ณ๊ฒฝํ๋ผ.",
|
247 |
inputs=[],
|
248 |
outputs=prompt_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
)
|
|
|
250 |
text_remove_btn.click(
|
251 |
fn=lambda: "#1 ์ด๋ฏธ์ง์ [์ค๊ตญ์ด๋ฅผ ๋ชจ๋]๋ฅผ ์ ๊ฑฐํ๋ผ.",
|
252 |
inputs=[],
|
253 |
outputs=prompt_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
)
|
|
|
255 |
clothes_change_btn.click(
|
256 |
fn=lambda: "#1์ด๋ฏธ์ง์์ [์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด] ์์[์คํ์ผ๊ณผ ์์์]#2, #3์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์.",
|
257 |
inputs=[],
|
258 |
outputs=prompt_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
)
|
|
|
260 |
background_change_btn.click(
|
261 |
-
fn=lambda: "
|
262 |
inputs=[],
|
263 |
outputs=prompt_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
)
|
|
|
265 |
composite_product_btn.click(
|
266 |
fn=lambda: "์ด๋ฏธ์ง #1์ ๋ชจ๋ธ์ด ํ์์ ๋ฐ๋ผ ์์ธ๋ ํ์ ์ ์ ๋์ ์ผ๋ก ๋ณํํ ํ, ์ด๋ฏธ์ง #2(๋๋ #3)์ ์ํ์ ์ต๋ํ ์๋ ํํ์ ๋ํ
์ผ์ ์ ์งํ๋ฉด์ ์์ฐ์ค๋ฝ๊ฒ ์ฐฉ์ฉํ ๋ชจ์ต์ ํฉ์ฑํ๋ผ.",
|
267 |
inputs=[],
|
268 |
outputs=prompt_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
)
|
270 |
|
|
|
271 |
submit_btn.click(
|
272 |
fn=process_and_show_prompt,
|
273 |
-
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
274 |
-
outputs=[output_image, output_text, prompt_display],
|
275 |
)
|
276 |
|
277 |
gr.Markdown(
|
@@ -281,10 +408,11 @@ with gr.Blocks() as demo:
|
|
281 |
1. **์๋ ํฉ์ฑ**: ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํ๋กฌํํธ๋ฅผ ๋น์๋๋ฉด ์๋์ผ๋ก ํฉ์ฑ๋ฉ๋๋ค.
|
282 |
2. **์ด๋ฏธ์ง ์ฐธ์กฐ**: #1, #2, #3์ผ๋ก ๊ฐ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
|
283 |
3. **์ ํ ์ต์
**: ์์ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํ๋กฌํํธ ์
๋ ฅ๋์ ํ๊ตญ์ด ๋ฌธ๊ตฌ๋ก ์
๋ ฅํ์๋ฉด ๋ฉ๋๋ค.
|
|
|
284 |
|
285 |
> **ํ**: ํ๋กฌํํธ๋ฅผ ์ง์ ์์ ํ ์๋ ์์ต๋๋ค.
|
286 |
"""
|
287 |
)
|
288 |
|
289 |
if __name__ == "__main__":
|
290 |
-
demo.launch(share=True)
|
|
|
61 |
logger.exception("๋ฒ์ญ ์ค ์ค๋ฅ ๋ฐ์:")
|
62 |
return prompt
|
63 |
|
64 |
+
def preprocess_prompt(prompt, image1, image2, image3, background_options=None):
|
65 |
"""
|
66 |
ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๊ณ ๊ธฐ๋ฅ ๋ช
๋ น์ ํด์
|
67 |
"""
|
|
|
103 |
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt:
|
104 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
105 |
|
106 |
+
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt or "๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ" in prompt:
|
107 |
+
# ๋ฐฐ๊ฒฝ ์ต์
์ด ์์ผ๋ฉด ๊ทธ๊ฒ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋กฌํํธ ์์ฑ
|
108 |
+
if background_options and all(background_options.values()):
|
109 |
+
product_category = background_options.get("product_category", "์ผ๋ฐ ์ํ")
|
110 |
+
background_type = background_options.get("background_type", "์์ฐ ๋ฐฐ๊ฒฝ")
|
111 |
+
background_style = background_options.get("background_style", "์ฒ")
|
112 |
+
|
113 |
+
# ์ํ ์นดํ
๊ณ ๋ฆฌ๋ณ ํนํ๋ ํ๋กฌํํธ ์์ฑ
|
114 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ {product_category} ์ํ์ ๊ทธ๋๋ก ์ ์งํ๋ฉด์, ๋ฐฐ๊ฒฝ์ {background_type} ์ค {background_style}์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ํ์ ์์, ์ง๊ฐ, ํํ๋ ์๋ฒฝํ๊ฒ ๋ณด์กดํ๊ณ ๊ณ ํ์ง ์ํ ์ฌ์ง ์คํ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
115 |
+
else:
|
116 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
117 |
|
118 |
elif "์ํํฉ์ฑ" in prompt:
|
119 |
prompt = "#1 ์ํ ์ด๋ฏธ์ง์ #2 ์ด๋ฏธ์ง ๋๋ #3 ์ด๋ฏธ์ง๋ฅผ [๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ๋๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํ์ฌ]์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํ๋ผ."
|
|
|
173 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
174 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
175 |
|
176 |
+
def process_images_with_prompt(image1, image2, image3, prompt, background_options=None):
|
177 |
"""
|
178 |
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ์ฌ ์ต์ข
์์ด ํ๋กฌํํธ(final_prompt)๋ฅผ ์์ฑํ ํ,
|
179 |
API๋ฅผ ํธ์ถํ์ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
|
|
185 |
return None, "์ ์ด๋ ํ๋์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", ""
|
186 |
|
187 |
if prompt and prompt.strip():
|
188 |
+
processed_prompt = preprocess_prompt(prompt, image1, image2, image3, background_options)
|
189 |
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
190 |
final_prompt = translate_prompt_to_english(processed_prompt)
|
191 |
else:
|
|
|
207 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
208 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
209 |
|
210 |
+
def process_and_show_prompt(image1, image2, image3, prompt, product_category=None, background_type=None, background_style=None):
|
211 |
try:
|
212 |
+
# ๋ฐฐ๊ฒฝ ์ต์
์ด ์์ ๊ฒฝ์ฐ ๋์
๋๋ฆฌ๋ก ์ ๋ฌ
|
213 |
+
background_options = None
|
214 |
+
if all([product_category, background_type, background_style]):
|
215 |
+
background_options = {
|
216 |
+
"product_category": product_category,
|
217 |
+
"background_type": background_type,
|
218 |
+
"background_style": background_style
|
219 |
+
}
|
220 |
+
|
221 |
+
result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, background_options)
|
222 |
+
|
223 |
+
# ์ ํ๋ ์ต์
์ ๋ฌธ์์ด๋ก ๊ตฌ์ฑ
|
224 |
+
options_summary = ""
|
225 |
+
if background_options:
|
226 |
+
options_summary = f"์ ํ๊ตฐ: {product_category}\n๋ฐฐ๊ฒฝ ์ ํ: {background_type}\n์ธ๋ถ ์คํ์ผ: {background_style}"
|
227 |
+
|
228 |
+
return result_img, status, final_prompt, options_summary
|
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), gr.update(visible=True)
|
237 |
+
else:
|
238 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
239 |
+
|
240 |
+
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ฅธ ์ธ๋ถ ์คํ์ผ ์ต์
์
๋ฐ์ดํธ
|
241 |
+
def update_background_style_options(background_type):
|
242 |
+
if background_type == "์์ฐ ๋ฐฐ๊ฒฝ":
|
243 |
+
return gr.update(choices=["์ฒ", "ํด๋ณ", "์ฐ", "๋คํ", "๊ณ๊ณก", "์ด๋ ์ ์", "์ฌ๋ง", "๋ ํ๊ฒฝ"], value="์ฒ")
|
244 |
+
elif background_type == "์ค๋ด ๋ฐฐ๊ฒฝ":
|
245 |
+
return gr.update(choices=["๊ฑฐ์ค", "์ฃผ๋ฐฉ", "์์ฌ", "ํ์ฅ๋", "ํธํ
๋ก๋น", "์นดํ", "๋ฏธ๋๋ฉ ๊ณต๊ฐ"], value="๊ฑฐ์ค")
|
246 |
+
elif background_type == "ํน์ ๋ฐฐ๊ฒฝ":
|
247 |
+
return gr.update(choices=["๋์ ํ๊ฒฝ", "๋ฃจํํ", "ํด์๊ฐ", "๋ชจ๋ ์คํ๋์ค", "๋นํฐ์ง ๊ณต๊ฐ", "๋ฏธ๋์ด์ฒ ๊ณต๊ฐ"], value="๋์ ํ๊ฒฝ")
|
248 |
+
else:
|
249 |
+
return gr.update(choices=["์ ํํ์ธ์"], value="์ ํํ์ธ์")
|
250 |
|
251 |
# Gradio ์ธํฐํ์ด์ค
|
252 |
with gr.Blocks() as demo:
|
|
|
259 |
"""
|
260 |
)
|
261 |
|
262 |
+
current_selection = gr.State("")
|
263 |
+
|
264 |
with gr.Row():
|
265 |
with gr.Column():
|
266 |
with gr.Row():
|
|
|
272 |
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.",
|
273 |
label="ํ๋กฌํํธ (์ ํ ์ฌํญ)"
|
274 |
)
|
275 |
+
|
276 |
with gr.Row():
|
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 background_options_row:
|
285 |
+
gr.HTML("<h3>๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ์ต์
</h3>")
|
286 |
+
|
287 |
+
# ์ ํ๊ตฐ ์นดํ
๊ณ ๋ฆฌ ๋๋กญ๋ค์ด
|
288 |
+
product_category = gr.Dropdown(
|
289 |
+
choices=["ํ์ฅํ", "๊ฐ๋ฐฉ", "์ก์ธ์๋ฆฌ", "๋ณด์๋ฅ", "ํ ๋ฐ์ฝ", "์ ๋ฐ", "์๋ฅ", "์ฃผ๋ฐฉ์ฉํ", "์ ์๊ธฐ๊ธฐ", "๊ธฐํ"],
|
290 |
+
label="์ ํ๊ตฐ ์ ํ",
|
291 |
+
value="๊ธฐํ",
|
292 |
+
visible=False
|
293 |
+
)
|
294 |
+
|
295 |
+
# ๋ฐฐ๊ฒฝ ์ ํ ๋๋กญ๋ค์ด
|
296 |
+
background_type = gr.Dropdown(
|
297 |
+
choices=["์์ฐ ๋ฐฐ๊ฒฝ", "์ค๋ด ๋ฐฐ๊ฒฝ", "ํน์ ๋ฐฐ๊ฒฝ"],
|
298 |
+
label="๋ฐฐ๊ฒฝ ์ ํ ์ ํ",
|
299 |
+
value="์์ฐ ๋ฐฐ๊ฒฝ",
|
300 |
+
visible=False
|
301 |
+
)
|
302 |
+
|
303 |
+
# ๋ฐฐ๊ฒฝ ์ธ๋ถ ์คํ์ผ ๋๋กญ๋ค์ด (๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ๋์ ๋ณ๊ฒฝ)
|
304 |
+
background_style = gr.Dropdown(
|
305 |
+
choices=["์ฒ", "ํด๋ณ", "์ฐ", "๋คํ", "๊ณ๊ณก", "์ด๋ ์ ์", "์ฌ๋ง", "๋ ํ๊ฒฝ"],
|
306 |
+
label="๋ฐฐ๊ฒฝ ์ธ๋ถ ์คํ์ผ ์ ํ",
|
307 |
+
value="์ฒ",
|
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 |
+
options_summary = gr.Textbox(label="์ ํ๋ ์ต์
", visible=True)
|
318 |
|
319 |
# ์ ํ ์ต์
๋ฒํผ ํด๋ฆญ ์ ํ๋กฌํํธ ์
๋ ฅ๋ ์
๋ฐ์ดํธ (ํ๊ตญ์ด ๋ฌธ๊ตฌ)
|
320 |
image_change_btn.click(
|
321 |
fn=lambda: "#1 ์ด๋ฏธ์ง์ [๋ค๋ฅธ ๋ชจ์ต]์ผ๋ก ๋ณ๊ฒฝํ๋ผ.",
|
322 |
inputs=[],
|
323 |
outputs=prompt_input
|
324 |
+
).then(
|
325 |
+
fn=lambda: "์ด๋ฏธ์ง ๋ณ๊ฒฝ",
|
326 |
+
inputs=[],
|
327 |
+
outputs=current_selection
|
328 |
+
).then(
|
329 |
+
fn=toggle_background_options,
|
330 |
+
inputs=[current_selection],
|
331 |
+
outputs=[background_options_row, product_category, background_type, background_style]
|
332 |
)
|
333 |
+
|
334 |
text_remove_btn.click(
|
335 |
fn=lambda: "#1 ์ด๋ฏธ์ง์ [์ค๊ตญ์ด๋ฅผ ๋ชจ๋]๋ฅผ ์ ๊ฑฐํ๋ผ.",
|
336 |
inputs=[],
|
337 |
outputs=prompt_input
|
338 |
+
).then(
|
339 |
+
fn=lambda: "๊ธ์์ง์ฐ๊ธฐ",
|
340 |
+
inputs=[],
|
341 |
+
outputs=current_selection
|
342 |
+
).then(
|
343 |
+
fn=toggle_background_options,
|
344 |
+
inputs=[current_selection],
|
345 |
+
outputs=[background_options_row, product_category, background_type, background_style]
|
346 |
)
|
347 |
+
|
348 |
clothes_change_btn.click(
|
349 |
fn=lambda: "#1์ด๋ฏธ์ง์์ [์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด] ์์[์คํ์ผ๊ณผ ์์์]#2, #3์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์.",
|
350 |
inputs=[],
|
351 |
outputs=prompt_input
|
352 |
+
).then(
|
353 |
+
fn=lambda: "์ท๋ฐ๊พธ๊ธฐ",
|
354 |
+
inputs=[],
|
355 |
+
outputs=current_selection
|
356 |
+
).then(
|
357 |
+
fn=toggle_background_options,
|
358 |
+
inputs=[current_selection],
|
359 |
+
outputs=[background_options_row, product_category, background_type, background_style]
|
360 |
)
|
361 |
+
|
362 |
background_change_btn.click(
|
363 |
+
fn=lambda: "๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ",
|
364 |
inputs=[],
|
365 |
outputs=prompt_input
|
366 |
+
).then(
|
367 |
+
fn=lambda: "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ",
|
368 |
+
inputs=[],
|
369 |
+
outputs=current_selection
|
370 |
+
).then(
|
371 |
+
fn=toggle_background_options,
|
372 |
+
inputs=[current_selection],
|
373 |
+
outputs=[background_options_row, product_category, background_type, background_style]
|
374 |
)
|
375 |
+
|
376 |
composite_product_btn.click(
|
377 |
fn=lambda: "์ด๋ฏธ์ง #1์ ๋ชจ๋ธ์ด ํ์์ ๋ฐ๋ผ ์์ธ๋ ํ์ ์ ์ ๋์ ์ผ๋ก ๋ณํํ ํ, ์ด๋ฏธ์ง #2(๋๋ #3)์ ์ํ์ ์ต๋ํ ์๋ ํํ์ ๋ํ
์ผ์ ์ ์งํ๋ฉด์ ์์ฐ์ค๋ฝ๊ฒ ์ฐฉ์ฉํ ๋ชจ์ต์ ํฉ์ฑํ๋ผ.",
|
378 |
inputs=[],
|
379 |
outputs=prompt_input
|
380 |
+
).then(
|
381 |
+
fn=lambda: "์ํํฉ์ฑ",
|
382 |
+
inputs=[],
|
383 |
+
outputs=current_selection
|
384 |
+
).then(
|
385 |
+
fn=toggle_background_options,
|
386 |
+
inputs=[current_selection],
|
387 |
+
outputs=[background_options_row, product_category, background_type, background_style]
|
388 |
+
)
|
389 |
+
|
390 |
+
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ์ธ๋ถ ์คํ์ผ ์ต์
์
๋ฐ์ดํธ
|
391 |
+
background_type.change(
|
392 |
+
fn=update_background_style_options,
|
393 |
+
inputs=[background_type],
|
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, product_category, background_type, background_style],
|
401 |
+
outputs=[output_image, output_text, prompt_display, options_summary],
|
402 |
)
|
403 |
|
404 |
gr.Markdown(
|
|
|
408 |
1. **์๋ ํฉ์ฑ**: ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํ๋กฌํํธ๋ฅผ ๋น์๋๋ฉด ์๋์ผ๋ก ํฉ์ฑ๋ฉ๋๋ค.
|
409 |
2. **์ด๋ฏธ์ง ์ฐธ์กฐ**: #1, #2, #3์ผ๋ก ๊ฐ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
|
410 |
3. **์ ํ ์ต์
**: ์์ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํ๋กฌํํธ ์
๋ ฅ๋์ ํ๊ตญ์ด ๋ฌธ๊ตฌ๋ก ์
๋ ฅํ์๋ฉด ๋ฉ๋๋ค.
|
411 |
+
4. **๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ**: ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ถ๊ฐ ์ต์
์ด ๋ํ๋ฉ๋๋ค.
|
412 |
|
413 |
> **ํ**: ํ๋กฌํํธ๋ฅผ ์ง์ ์์ ํ ์๋ ์์ต๋๋ค.
|
414 |
"""
|
415 |
)
|
416 |
|
417 |
if __name__ == "__main__":
|
418 |
+
demo.launch(share=True)
|