Kims12 commited on
Commit
0fee2a2
ยท
verified ยท
1 Parent(s): 4718cfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -62
app.py CHANGED
@@ -184,16 +184,16 @@ def process_images_with_prompt(image1, image2, image3, prompt):
184
 
185
  # ํ”„๋กฌํ”„ํŠธ ์ฒ˜๋ฆฌ
186
  if not prompt or not prompt.strip():
187
- # ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์—†์œผ๋ฉด ์—…๋กœ๋“œ๋œ ์ด๋ฏธ์ง€ ์ˆ˜์— ๋”ฐ๋ผ ์ž๋™ ํ•ฉ์„ฑ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
188
  if len(valid_images) == 1:
189
- prompt = "์ด ์ด๋ฏธ์ง€๋ฅผ ์ฐฝ์˜์ ์œผ๋กœ ๋ณ€ํ˜•ํ•ด์ฃผ์„ธ์š”. ๋” ์ƒ์ƒํ•˜๊ณ  ์˜ˆ์ˆ ์ ์ธ ๋ฒ„์ „์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
190
- logger.info("๋‹จ์ผ ์ด๋ฏธ์ง€ ํ”„๋กฌํ”„ํŠธ ์ž๋™ ์ƒ์„ฑ")
191
  elif len(valid_images) == 2:
192
- prompt = "์ด ๋‘ ์ด๋ฏธ์ง€๋ฅผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”. ๋‘ ์ด๋ฏธ์ง€์˜ ์š”์†Œ๋ฅผ ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉํ•˜์—ฌ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
193
- logger.info("๋‘ ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ ํ”„๋กฌํ”„ํŠธ ์ž๋™ ์ƒ์„ฑ")
194
  else:
195
- prompt = "์ด ์„ธ ์ด๋ฏธ์ง€๋ฅผ ์ฐฝ์˜์ ์œผ๋กœ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”. ๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๋˜ ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ์ผ๊ด€๋œ ํ•˜๋‚˜์˜ ์žฅ๋ฉด์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
196
- logger.info("์„ธ ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ ํ”„๋กฌํ”„ํŠธ ์ž๋™ ์ƒ์„ฑ")
197
  else:
198
  # ํ”„๋กฌํ”„ํŠธ ์ „์ฒ˜๋ฆฌ ๋ฐ ๊ธฐ๋Šฅ ๋ช…๋ น ํ•ด์„
199
  prompt = preprocess_prompt(prompt, image1, image2, image3)
@@ -205,27 +205,15 @@ def process_images_with_prompt(image1, image2, image3, prompt):
205
  logger.exception("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
206
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
207
 
208
- # ๊ธฐ๋Šฅ ์„ ํƒ ์ฝœ๋ฐฑ (๊ธฐ์กด ์ฝ”๋“œ ์œ ์ง€)
209
- def update_prompt_from_function(function_choice, custom_text=""):
210
- function_templates = {
211
- "1. ์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ": f'#1์„ "{custom_text if custom_text else "์›ํ•˜๋Š” ์„ค๋ช…"}"์œผ๋กœ ๋ฐ”๊ฟ”๋ผ',
212
- "2. ๊ธ€์ž์ง€์šฐ๊ธฐ": f'#1์—์„œ "{custom_text if custom_text else "์ง€์šธ ํ…์ŠคํŠธ"}"๋ฅผ ์ง€์›Œ๋ผ',
213
- "3. ์–ผ๊ตด๋ฐ”๊พธ๊ธฐ": "#1์˜ ์ธ๋ฌผ์„ #2์˜ ์–ผ๊ตด๋กœ ๋ฐ”๊ฟ”๋ผ",
214
- "4. ์˜ท๋ฐ”๊พธ๊ธฐ": "#1์˜ ์ธ๋ฌผ์— #2 ๋˜๋Š” #3์˜ ์˜ท์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ",
215
- "5. ๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ": "#1์˜ ์ด๋ฏธ์ง€์— #2์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ฐ”๊ฟ”๋ผ",
216
- "6. ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์ƒํ’ˆํฌํ•จ)": "#1์™€ #2 ๋˜๋Š” #3์˜ ๋ฅผ ํ•ฉ์„ฑํ•˜๋ผ",
217
- "7. ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์Šคํƒ€์ผ์ ์šฉ)": "#1์™€ #2๋ฅผ ์Šคํƒ€์ผ๋กœ ๋ณ€ํ™˜ํ•˜๋ผ"
218
- }
219
-
220
- return function_templates.get(function_choice, "")
221
 
222
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค (๊ธฐ์กด ์ฝ”๋“œ ์œ ์ง€)
223
  with gr.Blocks() as demo:
224
  gr.HTML(
225
  """
226
  <div style="text-align: center; margin-bottom: 1rem;">
227
  <h1>๊ฐ„๋‹จํ•œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ๊ธฐ</h1>
228
- <p>์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ๋ฐ”๋กœ ์‹คํ–‰ํ•˜๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋˜๋Š” ์•„๋ž˜ ๊ธฐ๋Šฅ์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</p>
229
  </div>
230
  """
231
  )
@@ -238,28 +226,6 @@ with gr.Blocks() as demo:
238
  image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
239
  image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
240
 
241
- # ๊ธฐ๋Šฅ ์„ ํƒ ๋“œ๋กญ๋‹ค์šด๊ณผ ์ปค์Šคํ…€ ํ…์ŠคํŠธ ์ž…๋ ฅ
242
- with gr.Row():
243
- function_dropdown = gr.Dropdown(
244
- choices=[
245
- "1. ์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ",
246
- "2. ๊ธ€์ž์ง€์šฐ๊ธฐ",
247
- "3. ์–ผ๊ตด๋ฐ”๊พธ๊ธฐ",
248
- "4. ์˜ท๋ฐ”๊พธ๊ธฐ",
249
- "5. ๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ",
250
- "6. ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์ƒํ’ˆํฌํ•จ)",
251
- "7. ์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์Šคํƒ€์ผ์ ์šฉ)"
252
- ],
253
- label="๊ธฐ๋Šฅ ์„ ํƒ",
254
- value=None
255
- )
256
- custom_text_input = gr.Textbox(
257
- label="์ปค์Šคํ…€ ํ…์ŠคํŠธ (1, 2๋ฒˆ ๊ธฐ๋Šฅ์šฉ)",
258
- placeholder="์˜ˆ: ๋ถ‰์€์ƒ‰, ์ˆ˜์ฑ„ํ™” ์Šคํƒ€์ผ, ์ค‘๊ตญ์–ด..."
259
- )
260
-
261
- apply_function_btn = gr.Button("๊ธฐ๋Šฅ ์ ์šฉ")
262
-
263
  # ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ (์„ ํƒ ์‚ฌํ•ญ)
264
  prompt_input = gr.Textbox(
265
  lines=3,
@@ -278,13 +244,6 @@ with gr.Blocks() as demo:
278
  # ์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ ํ‘œ์‹œ
279
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ", visible=True)
280
 
281
- # ๊ธฐ๋Šฅ ์ ์šฉ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
282
- apply_function_btn.click(
283
- fn=update_prompt_from_function,
284
- inputs=[function_dropdown, custom_text_input],
285
- outputs=[prompt_input]
286
- )
287
-
288
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
289
  def process_and_show_prompt(image1, image2, image3, prompt):
290
  # ์ด๋ฏธ์ง€ ๊ฐœ์ˆ˜ ํ™•์ธ
@@ -296,11 +255,11 @@ with gr.Blocks() as demo:
296
  auto_prompt = prompt
297
  if not prompt or not prompt.strip():
298
  if len(valid_images) == 1:
299
- auto_prompt = "์ด ์ด๋ฏธ์ง€๋ฅผ ์ฐฝ์˜์ ์œผ๋กœ ๋ณ€ํ˜•ํ•ด์ฃผ์„ธ์š”. ๋” ์ƒ์ƒํ•˜๊ณ  ์˜ˆ์ˆ ์ ์ธ ๋ฒ„์ „์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
300
  elif len(valid_images) == 2:
301
- auto_prompt = "์ด ๋‘ ์ด๋ฏธ์ง€๋ฅผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”. ๋‘ ์ด๋ฏธ์ง€์˜ ์š”์†Œ๋ฅผ ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉํ•˜์—ฌ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
302
  else:
303
- auto_prompt = "์ด ์„ธ ์ด๋ฏธ์ง€๋ฅผ ์ฐฝ์˜์ ์œผ๋กœ ํ•ฉ์„ฑํ•ด์ฃผ์„ธ์š”. ๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ฃผ์š” ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๋˜ ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ์ผ๊ด€๋œ ํ•˜๋‚˜์˜ ์žฅ๋ฉด์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."
304
  else:
305
  auto_prompt = preprocess_prompt(prompt, image1, image2, image3)
306
 
@@ -311,7 +270,7 @@ with gr.Blocks() as demo:
311
  except Exception as e:
312
  logger.exception("์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
313
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
314
-
315
  submit_btn.click(
316
  fn=process_and_show_prompt,
317
  inputs=[image1_input, image2_input, image3_input, prompt_input],
@@ -322,16 +281,14 @@ with gr.Blocks() as demo:
322
  """
323
  ### ์‚ฌ์šฉ ๋ฐฉ๋ฒ•:
324
 
325
- 1. **์ž๋™ ํ•ฉ์„ฑ**: ์ด๋ฏธ์ง€๋งŒ ์—…๋กœ๋“œํ•˜๊ณ  ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋น„์›Œ๋‘๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค
326
- 2. **๊ธฐ๋Šฅ ์‚ฌ์šฉ**: ๋“œ๋กญ๋‹ค์šด์—์„œ ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜๊ณ  '๊ธฐ๋Šฅ ์ ์šฉ' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”
327
- 3. **์ปค์Šคํ…€ ํ…์ŠคํŠธ**: ์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ์ด๋‚˜ ๊ธ€์ž์ง€์šฐ๊ธฐ ๊ธฐ๋Šฅ์„ ์„ ํƒํ•  ๋•Œ ์ถ”๊ฐ€ ์„ค๋ช…์„ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
328
- 4. **์ด๋ฏธ์ง€ ์ฐธ์กฐ**: #1, #2, #3์œผ๋กœ ๊ฐ ์ด๋ฏธ์ง€๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
329
- 5. **์ผ๋ถ€ ์ด๋ฏธ์ง€๋งŒ**: ํ•„์š”ํ•œ ์ด๋ฏธ์ง€๋งŒ ์—…๋กœ๋“œํ•ด๋„ ๊ธฐ๋Šฅ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค
330
 
331
- > **ํŒ**: ๊ธฐ๋Šฅ์„ ์„ ํƒํ•œ ํ›„์—๋„ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
332
  """
333
  )
334
 
335
  # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
336
  if __name__ == "__main__":
337
- demo.launch(share=True)
 
184
 
185
  # ํ”„๋กฌํ”„ํŠธ ์ฒ˜๋ฆฌ
186
  if not prompt or not prompt.strip():
187
+ # ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์—†์œผ๋ฉด ์—…๋กœ๋“œ๋œ ์ด๋ฏธ์ง€ ์ˆ˜์— ๋”ฐ๋ผ ์ž๋™ ํ•ฉ์„ฑ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์˜์–ด๋กœ ์ƒ์„ฑ
188
  if len(valid_images) == 1:
189
+ prompt = "Please creatively transform this image into a more vivid and artistic version."
190
+ logger.info("Default prompt generated for single image")
191
  elif len(valid_images) == 2:
192
+ prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image."
193
+ logger.info("Default prompt generated for two images")
194
  else:
195
+ prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene."
196
+ logger.info("Default prompt generated for three images")
197
  else:
198
  # ํ”„๋กฌํ”„ํŠธ ์ „์ฒ˜๋ฆฌ ๋ฐ ๊ธฐ๋Šฅ ๋ช…๋ น ํ•ด์„
199
  prompt = preprocess_prompt(prompt, image1, image2, image3)
 
205
  logger.exception("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
206
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
207
 
208
+ # (๊ธฐ๋Šฅ ์„ ํƒ ๊ด€๋ จ ์ฝ”๋“œ ์ „์ฒด ์‚ญ์ œ๋จ)
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค
211
  with gr.Blocks() as demo:
212
  gr.HTML(
213
  """
214
  <div style="text-align: center; margin-bottom: 1rem;">
215
  <h1>๊ฐ„๋‹จํ•œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ๊ธฐ</h1>
216
+ <p>์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ๋ฐ”๋กœ ์‹คํ–‰ํ•˜๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑํ•ฉ๋‹ˆ๋‹ค.</p>
217
  </div>
218
  """
219
  )
 
226
  image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
227
  image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  # ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ (์„ ํƒ ์‚ฌํ•ญ)
230
  prompt_input = gr.Textbox(
231
  lines=3,
 
244
  # ์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ ํ‘œ์‹œ
245
  prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ", visible=True)
246
 
 
 
 
 
 
 
 
247
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
248
  def process_and_show_prompt(image1, image2, image3, prompt):
249
  # ์ด๋ฏธ์ง€ ๊ฐœ์ˆ˜ ํ™•์ธ
 
255
  auto_prompt = prompt
256
  if not prompt or not prompt.strip():
257
  if len(valid_images) == 1:
258
+ auto_prompt = "Please creatively transform this image into a more vivid and artistic version."
259
  elif len(valid_images) == 2:
260
+ auto_prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image."
261
  else:
262
+ auto_prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene."
263
  else:
264
  auto_prompt = preprocess_prompt(prompt, image1, image2, image3)
265
 
 
270
  except Exception as e:
271
  logger.exception("์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:")
272
  return None, f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", prompt
273
+
274
  submit_btn.click(
275
  fn=process_and_show_prompt,
276
  inputs=[image1_input, image2_input, image3_input, prompt_input],
 
281
  """
282
  ### ์‚ฌ์šฉ ๋ฐฉ๋ฒ•:
283
 
284
+ 1. **์ž๋™ ํ•ฉ์„ฑ**: ์ด๋ฏธ์ง€๋งŒ ์—…๋กœ๋“œํ•˜๊ณ  ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋น„์›Œ๋‘๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.
285
+ 2. **์ด๋ฏธ์ง€ ์ฐธ์กฐ**: #1, #2, #3์œผ๋กœ ๊ฐ ์ด๋ฏธ์ง€๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
286
+ 3. **์ผ๋ถ€ ์ด๋ฏธ์ง€๋งŒ**: ํ•„์š”ํ•œ ์ด๋ฏธ์ง€๋งŒ ์—…๋กœ๋“œํ•ด๋„ ๊ธฐ๋Šฅ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
 
 
287
 
288
+ > **ํŒ**: ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
289
  """
290
  )
291
 
292
  # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
293
  if __name__ == "__main__":
294
+ demo.launch(share=True)