Update app.py
Browse files
app.py
CHANGED
@@ -151,6 +151,7 @@ def generate_with_images(prompt, images, variation_index=0):
|
|
151 |
"""
|
152 |
API ํธ์ถ์ ํตํด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
153 |
variation_index๋ก ๋ค์ํ ๋ณํ๋ฅผ ์ค๋๋ค.
|
|
|
154 |
"""
|
155 |
try:
|
156 |
api_key = os.environ.get("GEMINI_API_KEY")
|
@@ -206,6 +207,11 @@ def generate_with_images(prompt, images, variation_index=0):
|
|
206 |
result_img = Image.open(temp_path)
|
207 |
if result_img.mode == "RGBA":
|
208 |
result_img = result_img.convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
209 |
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}"
|
210 |
except Exception as e:
|
211 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
@@ -293,6 +299,7 @@ with gr.Blocks() as demo:
|
|
293 |
<div style="text-align: center; margin-bottom: 1rem;">
|
294 |
<h1>4์ฅ ์ด๋ฏธ์ง ์์ฑ๊ธฐ (์์ ํฌํจ)</h1>
|
295 |
<p>์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ "์ด๋ฏธ์ง ์์ฑ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ฐจ๋ก๋ก 4์ฅ์ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ฉ๋๋ค.</p>
|
|
|
296 |
</div>
|
297 |
"""
|
298 |
)
|
@@ -300,9 +307,9 @@ with gr.Blocks() as demo:
|
|
300 |
with gr.Row():
|
301 |
with gr.Column():
|
302 |
with gr.Row():
|
303 |
-
image1_input = gr.Image(type="pil", label="#1", image_mode="RGB")
|
304 |
-
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
|
305 |
-
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
|
306 |
prompt_input = gr.Textbox(
|
307 |
lines=3,
|
308 |
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.",
|
@@ -318,15 +325,15 @@ with gr.Blocks() as demo:
|
|
318 |
|
319 |
with gr.Row():
|
320 |
with gr.Column():
|
321 |
-
output_image1 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #1")
|
322 |
with gr.Column():
|
323 |
-
output_image2 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #2")
|
324 |
|
325 |
with gr.Row():
|
326 |
with gr.Column():
|
327 |
-
output_image3 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #3")
|
328 |
with gr.Column():
|
329 |
-
output_image4 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #4")
|
330 |
|
331 |
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง")
|
332 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True)
|
@@ -343,7 +350,7 @@ with gr.Blocks() as demo:
|
|
343 |
outputs=prompt_input
|
344 |
)
|
345 |
clothes_change_btn.click(
|
346 |
-
fn=lambda: "
|
347 |
inputs=[],
|
348 |
outputs=prompt_input
|
349 |
)
|
|
|
151 |
"""
|
152 |
API ํธ์ถ์ ํตํด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
153 |
variation_index๋ก ๋ค์ํ ๋ณํ๋ฅผ ์ค๋๋ค.
|
154 |
+
์์ฑ๋ ์ด๋ฏธ์ง๋ ์ผ๊ด๋ ํฌ๊ธฐ๋ก ์กฐ์ ๋ฉ๋๋ค.
|
155 |
"""
|
156 |
try:
|
157 |
api_key = os.environ.get("GEMINI_API_KEY")
|
|
|
207 |
result_img = Image.open(temp_path)
|
208 |
if result_img.mode == "RGBA":
|
209 |
result_img = result_img.convert("RGB")
|
210 |
+
|
211 |
+
# ์ด๋ฏธ์ง ํฌ๊ธฐ๋ฅผ 512x512๋ก ์กฐ์ ํ์ฌ ์ผ๊ด๋ ์ถ๋ ฅ ํฌ๊ธฐ ์ ์ง
|
212 |
+
target_size = (512, 512)
|
213 |
+
result_img = result_img.resize(target_size, Image.Resampling.LANCZOS)
|
214 |
+
|
215 |
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}"
|
216 |
except Exception as e:
|
217 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
|
|
299 |
<div style="text-align: center; margin-bottom: 1rem;">
|
300 |
<h1>4์ฅ ์ด๋ฏธ์ง ์์ฑ๊ธฐ (์์ ํฌํจ)</h1>
|
301 |
<p>์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ "์ด๋ฏธ์ง ์์ฑ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ฐจ๋ก๋ก 4์ฅ์ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ฉ๋๋ค.</p>
|
302 |
+
<p>๋ชจ๋ ์ด๋ฏธ์ง๋ ๊ณ ์ ๋ ํฌ๊ธฐ๋ก ํ์๋ฉ๋๋ค.</p>
|
303 |
</div>
|
304 |
"""
|
305 |
)
|
|
|
307 |
with gr.Row():
|
308 |
with gr.Column():
|
309 |
with gr.Row():
|
310 |
+
image1_input = gr.Image(type="pil", label="#1", image_mode="RGB", height=256, width=256)
|
311 |
+
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB", height=256, width=256)
|
312 |
+
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB", height=256, width=256)
|
313 |
prompt_input = gr.Textbox(
|
314 |
lines=3,
|
315 |
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.",
|
|
|
325 |
|
326 |
with gr.Row():
|
327 |
with gr.Column():
|
328 |
+
output_image1 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #1", height=300, width=300)
|
329 |
with gr.Column():
|
330 |
+
output_image2 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #2", height=300, width=300)
|
331 |
|
332 |
with gr.Row():
|
333 |
with gr.Column():
|
334 |
+
output_image3 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #3", height=300, width=300)
|
335 |
with gr.Column():
|
336 |
+
output_image4 = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง #4", height=300, width=300)
|
337 |
|
338 |
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง")
|
339 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True)
|
|
|
350 |
outputs=prompt_input
|
351 |
)
|
352 |
clothes_change_btn.click(
|
353 |
+
fn=lambda: "#1์ด๋ฏธ์ง์์ [์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด] ์์[์คํ์ผ๊ณผ ์์์]#2, #3์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์.",
|
354 |
inputs=[],
|
355 |
outputs=prompt_input
|
356 |
)
|