Kims12 commited on
Commit
b449e5c
ยท
verified ยท
1 Parent(s): b357fea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
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: "(#1์˜ ์—ฌ์„ฑ๋ชจ๋ธ)์ด ์‹ ์ฒด ๋น„์œจ๊ณผ ํฌ์ฆˆ๋Š” ์œ ์ง€ํ•œ ์ฒด (#2์˜ ์„ ๊ธ€๋ผ์Šค)์™€ (#3์˜ ์ฒญ๋ฐ”์ง€)๋ฅผ ์ฐฉ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๊ฐ€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์–ด์šฐ๋Ÿฌ์ง€๋„๋ก ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.",
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
  )