aiqcamp commited on
Commit
03b18cc
Β·
verified Β·
1 Parent(s): 1df16d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -49
app.py CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
  import os
4
  import gradio as gr
5
  import random
@@ -44,10 +42,7 @@ def choose_alternative(transformation):
44
  else:
45
  return random.choice([left, right])
46
 
47
- # 창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™” 아이디어λ₯Ό μœ„ν•œ μΉ΄ν…Œκ³ λ¦¬ (κΈ°μ‘΄ '물리적 λ³€ν™”' 사전 μœ μ§€)
48
-
49
-
50
- # 창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™” 아이디어λ₯Ό μœ„ν•œ μΉ΄ν…Œκ³ λ¦¬ (κΈ°μ‘΄ '물리적 λ³€ν™”' 사전 μœ μ§€)
51
  physical_transformation_categories = {
52
  "곡간 이동": [
53
  "μ•ž/λ’€ 이동", "쒌/우 이동", "μœ„/μ•„λž˜ 이동", "μ„Έλ‘œμΆ• νšŒμ „(고개 λ„λ•μž„)",
@@ -287,7 +282,6 @@ def generate_three_objects_interaction(obj1, obj2, obj3):
287
  # μƒμ„±λœ κΈ°λ³Έ μ„€λͺ…을 LLM을 톡해 ν™•μž₯
288
  ##############################################################################
289
  def enhance_descriptions(results, objects):
290
- # progress 인자 제거
291
  obj_name = " 및 ".join([obj for obj in objects if obj])
292
 
293
  for category, result in results.items():
@@ -299,8 +293,6 @@ def enhance_descriptions(results, objects):
299
  # μ‚¬μš©μž μž…λ ₯(μ΅œλŒ€ 3개 ν‚€μ›Œλ“œ)에 따라 창의적 λ³€ν™” 아이디어 생성
300
  ##############################################################################
301
  def generate_transformations(text1, text2=None, text3=None):
302
- # progress 인자 제거
303
-
304
  if text2 and text3:
305
  results = generate_three_objects_interaction(text1, text2, text3)
306
  objects = [text1, text2, text3]
@@ -325,7 +317,7 @@ def format_results(results):
325
  ##############################################################################
326
  # Gradio UIμ—μ„œ ν˜ΈμΆœν•  ν•¨μˆ˜
327
  ##############################################################################
328
- def process_inputs(text1, text2, text3, progress=gr.Progress()):
329
  text1 = text1.strip() if text1 else None
330
  text2 = text2.strip() if text2 else None
331
  text3 = text3.strip() if text3 else None
@@ -333,36 +325,30 @@ def process_inputs(text1, text2, text3, progress=gr.Progress()):
333
  if not text1:
334
  return "였λ₯˜: μ΅œμ†Œ ν•˜λ‚˜μ˜ ν‚€μ›Œλ“œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”."
335
 
336
- # μ§„ν–‰ μƒνƒœ λ©”μ‹œμ§€ (쀑첩 리슀트 λŒ€μ‹  λ‹¨μˆœ λ¬Έμžμ—΄ μ‚¬μš©)
337
- status_message = ""
338
-
339
- # ν‚€μ›Œλ“œ 정보 확인
340
  keyword_info = f"ν‚€μ›Œλ“œ: {text1}"
341
  if text2:
342
  keyword_info += f", {text2}"
343
  if text3:
344
  keyword_info += f", {text3}"
345
 
346
- # κ²°κ³Ό 생성 (progress 인자 μ „λ‹¬ν•˜μ§€ μ•ŠμŒ)
347
- try:
348
- # μ§„ν–‰ μƒνƒœλ₯Ό λ‹¨κ³„λ³„λ‘œ ν‘œμ‹œ
349
- progress(0.05, desc="아이디어 생성 μ€€λΉ„ 쀑...")
350
- time.sleep(0.3) # μ‹œκ°μ  효과λ₯Ό μœ„ν•œ 짧은 μ§€μ—°
351
-
352
- progress(0.1, desc="창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™” 아이디어 생성 μ‹œμž‘...")
353
-
354
- # text1, text2, text3만 μ „λ‹¬ν•˜κ³  progressλŠ” μ „λ‹¬ν•˜μ§€ μ•ŠμŒ
355
- results = generate_transformations(text1, text2, text3)
356
-
357
- progress(0.8, desc="κ²°κ³Ό ν¬λ§·νŒ… 쀑...")
358
- formatted = format_results(results)
359
-
360
- progress(1.0, desc="μ™„λ£Œ!")
361
- return formatted
362
-
363
- except Exception as e:
364
- logger.error(f"Error in process_inputs: {e}")
365
- return f"처리 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
366
 
367
  ##############################################################################
368
  # API ν‚€ κ²½κ³  λ©”μ‹œμ§€
@@ -392,7 +378,7 @@ with gr.Blocks(title="ν‚€μ›Œλ“œ 기반 창의적 λ³€ν™” 아이디어 생성기",
392
  """)
393
 
394
  gr.Markdown("# πŸš€ ν‚€μ›Œλ“œ 기반 창의적 λ³€ν™” 아이디어 생성기")
395
- gr.Markdown("μž…λ ₯ν•œ **ν‚€μ›Œλ“œ**(μ΅œλŒ€ 3개)λ₯Ό λ°”νƒ•μœΌλ‘œ, **창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™”**에 λŒ€ν•œ 이해와 **ν˜μ‹  포인트**, **κΈ°λŠ₯μ„±** 등을 μ€‘μ‹¬μœΌλ‘œ ν™•μž₯된 아이디어λ₯Ό μ œμ‹œν•©λ‹ˆλ‹€.")
396
 
397
  warning = gr.Markdown(get_warning_message())
398
 
@@ -402,11 +388,16 @@ with gr.Blocks(title="ν‚€μ›Œλ“œ 기반 창의적 λ³€ν™” 아이디어 생성기",
402
  text_input1 = gr.Textbox(label="ν‚€μ›Œλ“œ 1 (ν•„μˆ˜)", placeholder="예: 슀마트폰")
403
  text_input2 = gr.Textbox(label="ν‚€μ›Œλ“œ 2 (선택)", placeholder="예: 인곡지λŠ₯")
404
  text_input3 = gr.Textbox(label="ν‚€μ›Œλ“œ 3 (선택)", placeholder="예: ν—¬μŠ€μΌ€μ–΄")
 
 
 
 
 
 
 
405
 
406
- # μž…λ ₯κ³Ό λ²„νŠΌ 사이에 μƒνƒœ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•  μ˜μ—­ μΆ”κ°€
407
  status_msg = gr.Markdown("πŸ’‘ '아이디어 μƒμ„±ν•˜κΈ°' λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄ 아이디어 생성이 μ‹œμž‘λ©λ‹ˆλ‹€.")
408
 
409
- # 처리 쀑일 λ•Œλ§Œ ν‘œμ‹œλ˜λŠ” μƒνƒœ λ©”μ‹œμ§€
410
  processing_indicator = gr.HTML("""
411
  <div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
412
  <div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
@@ -426,34 +417,30 @@ with gr.Blocks(title="ν‚€μ›Œλ“œ 기반 창의적 λ³€ν™” 아이디어 생성기",
426
  with gr.Column(scale=2):
427
  idea_output = gr.Markdown(label="아이디어 κ²°κ³Ό")
428
 
429
- # μ˜ˆμ‹œ μž…λ ₯
430
  gr.Examples(
431
  examples=[
432
- ["슀마트폰", "", ""],
433
- ["μžλ™μ°¨", "", ""],
434
- ["μžλ™μ°¨", "인곡지λŠ₯", ""],
435
- ["λ“œλ‘ ", "인곡지λŠ₯", ""],
436
- ["μš΄λ™ν™”", "μ›¨μ–΄λŸ¬λΈ”", "건강"],
437
  ],
438
- inputs=[text_input1, text_input2, text_input3],
439
  )
440
 
441
- # 처리 μ‹œμž‘ μ „ ν•¨μˆ˜ (λ‘œλ”© ν‘œμ‹œκΈ° 보이게)
442
  def show_processing_indicator():
443
  return gr.update(visible=True)
444
 
445
- # 처리 μ™„λ£Œ ν›„ ν•¨μˆ˜ (λ‘œλ”© ν‘œμ‹œκΈ° 숨기기)
446
  def hide_processing_indicator():
447
  return gr.update(visible=False)
448
 
449
- # λ²„νŠΌ 이벀트 - μ—¬λŸ¬ ν•¨μˆ˜ 순차 μ‹€ν–‰
450
  submit_button.click(
451
  fn=show_processing_indicator,
452
  inputs=None,
453
  outputs=processing_indicator
454
  ).then(
455
  fn=process_inputs,
456
- inputs=[text_input1, text_input2, text_input3],
457
  outputs=idea_output
458
  ).then(
459
  fn=hide_processing_indicator,
@@ -462,4 +449,4 @@ with gr.Blocks(title="ν‚€μ›Œλ“œ 기반 창의적 λ³€ν™” 아이디어 생성기",
462
  )
463
 
464
  if __name__ == "__main__":
465
- demo.launch(debug=True)
 
 
 
1
  import os
2
  import gradio as gr
3
  import random
 
42
  else:
43
  return random.choice([left, right])
44
 
45
+ # 창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™” 아이디어λ₯Ό μœ„ν•œ μΉ΄ν…Œκ³ λ¦¬
 
 
 
46
  physical_transformation_categories = {
47
  "곡간 이동": [
48
  "μ•ž/λ’€ 이동", "쒌/우 이동", "μœ„/μ•„λž˜ 이동", "μ„Έλ‘œμΆ• νšŒμ „(고개 λ„λ•μž„)",
 
282
  # μƒμ„±λœ κΈ°λ³Έ μ„€λͺ…을 LLM을 톡해 ν™•μž₯
283
  ##############################################################################
284
  def enhance_descriptions(results, objects):
 
285
  obj_name = " 및 ".join([obj for obj in objects if obj])
286
 
287
  for category, result in results.items():
 
293
  # μ‚¬μš©μž μž…λ ₯(μ΅œλŒ€ 3개 ν‚€μ›Œλ“œ)에 따라 창의적 λ³€ν™” 아이디어 생성
294
  ##############################################################################
295
  def generate_transformations(text1, text2=None, text3=None):
 
 
296
  if text2 and text3:
297
  results = generate_three_objects_interaction(text1, text2, text3)
298
  objects = [text1, text2, text3]
 
317
  ##############################################################################
318
  # Gradio UIμ—μ„œ ν˜ΈμΆœν•  ν•¨μˆ˜
319
  ##############################################################################
320
+ def process_inputs(text1, text2, text3, selected_category, progress=gr.Progress()):
321
  text1 = text1.strip() if text1 else None
322
  text2 = text2.strip() if text2 else None
323
  text3 = text3.strip() if text3 else None
 
325
  if not text1:
326
  return "였λ₯˜: μ΅œμ†Œ ν•˜λ‚˜μ˜ ν‚€μ›Œλ“œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”."
327
 
 
 
 
 
328
  keyword_info = f"ν‚€μ›Œλ“œ: {text1}"
329
  if text2:
330
  keyword_info += f", {text2}"
331
  if text3:
332
  keyword_info += f", {text3}"
333
 
334
+ progress(0.05, desc="아이디어 생성 μ€€λΉ„ 쀑...")
335
+ time.sleep(0.3) # μ‹œκ°μ  효과λ₯Ό μœ„ν•œ 짧은 μ§€μ—°
336
+
337
+ progress(0.1, desc="창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™” 아이디어 생성 μ‹œμž‘...")
338
+
339
+ results = generate_transformations(text1, text2, text3)
340
+
341
+ # μ„ νƒν•œ μΉ΄ν…Œκ³ λ¦¬μ— ν•΄λ‹Ήν•˜λŠ” 결과만 필터링
342
+ if selected_category in results:
343
+ results = {selected_category: results[selected_category]}
344
+ else:
345
+ return "μ„ νƒν•œ μΉ΄ν…Œκ³ λ¦¬κ°€ 결과에 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."
346
+
347
+ progress(0.8, desc="κ²°κ³Ό ν¬λ§·νŒ… 쀑...")
348
+ formatted = format_results(results)
349
+
350
+ progress(1.0, desc="μ™„λ£Œ!")
351
+ return formatted
 
 
352
 
353
  ##############################################################################
354
  # API ν‚€ κ²½κ³  λ©”μ‹œμ§€
 
378
  """)
379
 
380
  gr.Markdown("# πŸš€ ν‚€μ›Œλ“œ 기반 창의적 λ³€ν™” 아이디어 생성기")
381
+ gr.Markdown("μž…λ ₯ν•œ **ν‚€μ›Œλ“œ**(μ΅œλŒ€ 3개)와 **μΉ΄ν…Œκ³ λ¦¬**λ₯Ό λ°”νƒ•μœΌλ‘œ, **창의적인 λͺ¨λΈ/컨셉/ν˜•μƒ λ³€ν™”**에 λŒ€ν•œ 이해와 **ν˜μ‹  포인트**, **κΈ°λŠ₯μ„±** 등을 μ€‘μ‹¬μœΌλ‘œ ν™•μž₯된 아이디어λ₯Ό μ œμ‹œν•©λ‹ˆλ‹€.")
382
 
383
  warning = gr.Markdown(get_warning_message())
384
 
 
388
  text_input1 = gr.Textbox(label="ν‚€μ›Œλ“œ 1 (ν•„μˆ˜)", placeholder="예: 슀마트폰")
389
  text_input2 = gr.Textbox(label="ν‚€μ›Œλ“œ 2 (선택)", placeholder="예: 인곡지λŠ₯")
390
  text_input3 = gr.Textbox(label="ν‚€μ›Œλ“œ 3 (선택)", placeholder="예: ν—¬μŠ€μΌ€μ–΄")
391
+ # μΉ΄ν…Œκ³ λ¦¬ 선택 λ“œλ‘­λ‹€μš΄ μΆ”κ°€
392
+ category_dropdown = gr.Dropdown(
393
+ label="μΉ΄ν…Œκ³ λ¦¬ 선택",
394
+ choices=list(physical_transformation_categories.keys()),
395
+ value=list(physical_transformation_categories.keys())[0],
396
+ info="좜λ ₯ν•  μΉ΄ν…Œκ³ λ¦¬λ₯Ό μ„ νƒν•˜μ„Έμš”."
397
+ )
398
 
 
399
  status_msg = gr.Markdown("πŸ’‘ '아이디어 μƒμ„±ν•˜κΈ°' λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄ 아이디어 생성이 μ‹œμž‘λ©λ‹ˆλ‹€.")
400
 
 
401
  processing_indicator = gr.HTML("""
402
  <div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
403
  <div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
 
417
  with gr.Column(scale=2):
418
  idea_output = gr.Markdown(label="아이디어 κ²°κ³Ό")
419
 
 
420
  gr.Examples(
421
  examples=[
422
+ ["슀마트폰", "", "", list(physical_transformation_categories.keys())[0]],
423
+ ["μžλ™μ°¨", "", "", list(physical_transformation_categories.keys())[0]],
424
+ ["μžλ™μ°¨", "인곡지λŠ₯", "", list(physical_transformation_categories.keys())[0]],
425
+ ["λ“œλ‘ ", "인곡지λŠ₯", "", list(physical_transformation_categories.keys())[0]],
426
+ ["μš΄λ™ν™”", "μ›¨μ–΄λŸ¬λΈ”", "건강", list(physical_transformation_categories.keys())[0]],
427
  ],
428
+ inputs=[text_input1, text_input2, text_input3, category_dropdown],
429
  )
430
 
 
431
  def show_processing_indicator():
432
  return gr.update(visible=True)
433
 
 
434
  def hide_processing_indicator():
435
  return gr.update(visible=False)
436
 
 
437
  submit_button.click(
438
  fn=show_processing_indicator,
439
  inputs=None,
440
  outputs=processing_indicator
441
  ).then(
442
  fn=process_inputs,
443
+ inputs=[text_input1, text_input2, text_input3, category_dropdown],
444
  outputs=idea_output
445
  ).then(
446
  fn=hide_processing_indicator,
 
449
  )
450
 
451
  if __name__ == "__main__":
452
+ demo.launch(debug=True)