Kims12 commited on
Commit
d58b205
ยท
verified ยท
1 Parent(s): b04a329

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -144,7 +144,7 @@ def preprocess_prompt(prompt, image1, image2, image3):
144
  elif "6. ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์ƒํ’ˆํฌํ•จ)" in prompt:
145
  prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์™€ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€(๋˜๋Š” ์„ธ ๋ฒˆ์งธ ์ด๋ฏธ์ง€)๋ฅผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”. ๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๊ณ , ํŠนํžˆ ์ƒํ’ˆ์ด ๋‹๋ณด์ด๋„๋ก ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉํ•ด์ฃผ์„ธ์š”."
146
 
147
- prompt += " ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."
148
  return prompt
149
 
150
  def generate_with_images(prompt, images, variation_index=0):
@@ -162,14 +162,16 @@ def generate_with_images(prompt, images, variation_index=0):
162
 
163
  # ๋ณ€ํ˜• ์ธ๋ฑ์Šค์— ๋”ฐ๋ผ ํ”„๋กฌํ”„ํŠธ์— ์•ฝ๊ฐ„์˜ ๋ณ€ํ™” ์ถ”๊ฐ€
164
  variation_suffixes = [
165
- " ์ฒซ ๋ฒˆ์งธ ๋ณ€ํ˜•์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.",
166
- " ๋‘ ๋ฒˆ์งธ ๋ณ€ํ˜•์œผ๋กœ ๋” ์ƒ์ƒํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.",
167
- " ์„ธ ๋ฒˆ์งธ ๋ณ€ํ˜•์œผ๋กœ ๋” ์ฐฝ์˜์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.",
168
- " ๋„ค ๋ฒˆ์งธ ๋ณ€ํ˜•์œผ๋กœ ์ƒ‰๊ฐ์„ ๋” ๊ฐ•์กฐํ•ด์„œ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
169
  ]
170
 
171
  if variation_index < len(variation_suffixes):
172
  prompt = prompt + variation_suffixes[variation_index]
 
 
173
 
174
  contents = [prompt]
175
  for idx, img in enumerate(images, 1):
@@ -230,13 +232,13 @@ def process_images_with_prompt(image1, image2, image3, prompt, variation_index=0
230
  final_prompt = processed_prompt
231
  else:
232
  if len(valid_images) == 1:
233
- final_prompt = "Please creatively transform this image into a more vivid and artistic version."
234
  logger.info("Default prompt generated for single image")
235
  elif len(valid_images) == 2:
236
- final_prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image."
237
  logger.info("Default prompt generated for two images")
238
  else:
239
- final_prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene."
240
  logger.info("Default prompt generated for three images")
241
 
242
  result_img, status = generate_with_images(final_prompt, valid_images, variation_index)
@@ -302,9 +304,9 @@ with gr.Blocks() as demo:
302
  # ์™ผ์ชฝ ์ž…๋ ฅ ์˜์—ญ
303
  with gr.Column(scale=1):
304
  with gr.Row():
305
- image1_input = gr.Image(type="pil", label="#1", image_mode="RGB", height=300, width=200)
306
- image2_input = gr.Image(type="pil", label="#2", image_mode="RGB", height=300, width=200)
307
- image3_input = gr.Image(type="pil", label="#3", image_mode="RGB", height=300, width=200)
308
  prompt_input = gr.Textbox(
309
  lines=3,
310
  placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
@@ -322,11 +324,11 @@ with gr.Blocks() as demo:
322
  with gr.Column(scale=1):
323
  with gr.Row():
324
  with gr.Column():
325
- output_image1 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #1", height=450, width=450)
326
- output_image3 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #3", height=450, width=450)
327
  with gr.Column():
328
- output_image2 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #2", height=450, width=450)
329
- output_image4 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #4", height=450, width=450)
330
 
331
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€", lines=4)
332
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True, lines=4)
 
144
  elif "6. ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์ƒํ’ˆํฌํ•จ)" in prompt:
145
  prompt = "์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€์™€ ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€(๋˜๋Š” ์„ธ ๋ฒˆ์งธ ์ด๋ฏธ์ง€)๋ฅผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”. ๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๊ณ , ํŠนํžˆ ์ƒํ’ˆ์ด ๋‹๋ณด์ด๋„๋ก ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉํ•ด์ฃผ์„ธ์š”."
146
 
147
+ prompt += " ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋ฏธ์ง€์— ํ…์ŠคํŠธ๋‚˜ ๊ธ€์ž๋ฅผ ํฌํ•จํ•˜์ง€ ๋งˆ์„ธ์š”."
148
  return prompt
149
 
150
  def generate_with_images(prompt, images, variation_index=0):
 
162
 
163
  # ๋ณ€ํ˜• ์ธ๋ฑ์Šค์— ๋”ฐ๋ผ ํ”„๋กฌํ”„ํŠธ์— ์•ฝ๊ฐ„์˜ ๋ณ€ํ™” ์ถ”๊ฐ€
164
  variation_suffixes = [
165
+ " Create this as the first variation. Do not add any text, watermarks, or labels to the image.",
166
+ " Create this as the second variation with more vivid colors. Do not add any text, watermarks, or labels to the image.",
167
+ " Create this as the third variation with a more creative style. Do not add any text, watermarks, or labels to the image.",
168
+ " Create this as the fourth variation with enhanced details. Do not add any text, watermarks, or labels to the image."
169
  ]
170
 
171
  if variation_index < len(variation_suffixes):
172
  prompt = prompt + variation_suffixes[variation_index]
173
+ else:
174
+ prompt = prompt + " Do not add any text, watermarks, or labels to the image."
175
 
176
  contents = [prompt]
177
  for idx, img in enumerate(images, 1):
 
232
  final_prompt = processed_prompt
233
  else:
234
  if len(valid_images) == 1:
235
+ 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."
236
  logger.info("Default prompt generated for single image")
237
  elif len(valid_images) == 2:
238
+ final_prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image. Do not include any text or watermarks in the generated image."
239
  logger.info("Default prompt generated for two images")
240
  else:
241
+ final_prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene. Do not include any text or watermarks in the generated image."
242
  logger.info("Default prompt generated for three images")
243
 
244
  result_img, status = generate_with_images(final_prompt, valid_images, variation_index)
 
304
  # ์™ผ์ชฝ ์ž…๋ ฅ ์˜์—ญ
305
  with gr.Column(scale=1):
306
  with gr.Row():
307
+ image1_input = gr.Image(type="pil", label="#1", image_mode="RGB", height=200, width=200)
308
+ image2_input = gr.Image(type="pil", label="#2", image_mode="RGB", height=200, width=200)
309
+ image3_input = gr.Image(type="pil", label="#3", image_mode="RGB", height=200, width=200)
310
  prompt_input = gr.Textbox(
311
  lines=3,
312
  placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
 
324
  with gr.Column(scale=1):
325
  with gr.Row():
326
  with gr.Column():
327
+ output_image1 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #1", height=220, width=220)
328
+ output_image3 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #3", height=220, width=220)
329
  with gr.Column():
330
+ output_image2 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #2", height=220, width=220)
331
+ output_image4 = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ #4", height=220, width=220)
332
 
333
  output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€", lines=4)
334
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True, lines=4)