Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import google.generativeai as genai
|
| 3 |
from PIL import Image
|
|
@@ -439,25 +440,27 @@ def create_app():
|
|
| 439 |
def update_bg_subcategory(bg_main):
|
| 440 |
subcategories = get_subcategories_background(bg_main)
|
| 441 |
first_sub = subcategories[0] if subcategories else None
|
| 442 |
-
|
|
|
|
|
|
|
| 443 |
|
| 444 |
# 배경 서브 카테고리 변경 시 구체적 배경 드롭다운 업데이트
|
| 445 |
def update_bg_specific(bg_main, bg_sub):
|
| 446 |
specific_options = get_specific_backgrounds(bg_main, bg_sub)
|
| 447 |
first_specific = specific_options[0] if specific_options else None
|
| 448 |
-
return
|
| 449 |
|
| 450 |
# 스타일 메인 카테고리 변경 시 구체적 스타일 드롭다운 업데이트
|
| 451 |
def update_style_specific(style_main):
|
| 452 |
if style_main == "필요시 선택하세요":
|
| 453 |
-
return
|
| 454 |
specific_styles = get_specific_styles(style_main)
|
| 455 |
first_specific = specific_styles[0] if specific_styles else None
|
| 456 |
-
return
|
| 457 |
|
| 458 |
def update_preview(prompt):
|
| 459 |
if not prompt or "API 키" in prompt:
|
| 460 |
-
return
|
| 461 |
preview = f"""
|
| 462 |
<div style="padding:10px; border:1px solid #ddd; border-radius:8px; margin-top:10px;">
|
| 463 |
<h3>프롬프트 요약</h3>
|
|
@@ -466,31 +469,39 @@ def create_app():
|
|
| 466 |
<p><strong>미드저니 파라미터:</strong> {" ".join([param for param in ["--ar 1:1", "--s 750", "--q 2"] if param in prompt])}</p>
|
| 467 |
</div>
|
| 468 |
"""
|
| 469 |
-
return
|
| 470 |
|
| 471 |
# 드롭다운 변경 이벤트 연결
|
| 472 |
bg_main_category.change(
|
| 473 |
fn=update_bg_subcategory,
|
| 474 |
inputs=[bg_main_category],
|
| 475 |
-
outputs=[
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
|
|
|
| 480 |
)
|
| 481 |
|
| 482 |
bg_subcategory.change(
|
| 483 |
fn=update_bg_specific,
|
| 484 |
inputs=[bg_main_category, bg_subcategory],
|
| 485 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
| 486 |
)
|
| 487 |
|
| 488 |
style_main.change(
|
| 489 |
fn=update_style_specific,
|
| 490 |
inputs=[style_main],
|
| 491 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
| 492 |
)
|
| 493 |
|
|
|
|
| 494 |
submit_btn.click(
|
| 495 |
fn=process_inputs,
|
| 496 |
inputs=[image_input, bg_main_category, bg_subcategory, bg_specific, style_main, style_specific, product_name, additional_info],
|
|
|
|
| 1 |
+
|
| 2 |
import gradio as gr
|
| 3 |
import google.generativeai as genai
|
| 4 |
from PIL import Image
|
|
|
|
| 440 |
def update_bg_subcategory(bg_main):
|
| 441 |
subcategories = get_subcategories_background(bg_main)
|
| 442 |
first_sub = subcategories[0] if subcategories else None
|
| 443 |
+
specific_options = get_specific_backgrounds(bg_main, first_sub) if first_sub else []
|
| 444 |
+
first_specific = specific_options[0] if specific_options else None
|
| 445 |
+
return subcategories, first_sub, specific_options, first_specific
|
| 446 |
|
| 447 |
# 배경 서브 카테고리 변경 시 구체적 배경 드롭다운 업데이트
|
| 448 |
def update_bg_specific(bg_main, bg_sub):
|
| 449 |
specific_options = get_specific_backgrounds(bg_main, bg_sub)
|
| 450 |
first_specific = specific_options[0] if specific_options else None
|
| 451 |
+
return specific_options, first_specific
|
| 452 |
|
| 453 |
# 스타일 메인 카테고리 변경 시 구체적 스타일 드롭다운 업데이트
|
| 454 |
def update_style_specific(style_main):
|
| 455 |
if style_main == "필요시 선택하세요":
|
| 456 |
+
return [default_style_specific], default_style_specific
|
| 457 |
specific_styles = get_specific_styles(style_main)
|
| 458 |
first_specific = specific_styles[0] if specific_styles else None
|
| 459 |
+
return specific_styles, first_specific
|
| 460 |
|
| 461 |
def update_preview(prompt):
|
| 462 |
if not prompt or "API 키" in prompt:
|
| 463 |
+
return False, ""
|
| 464 |
preview = f"""
|
| 465 |
<div style="padding:10px; border:1px solid #ddd; border-radius:8px; margin-top:10px;">
|
| 466 |
<h3>프롬프트 요약</h3>
|
|
|
|
| 469 |
<p><strong>미드저니 파라미터:</strong> {" ".join([param for param in ["--ar 1:1", "--s 750", "--q 2"] if param in prompt])}</p>
|
| 470 |
</div>
|
| 471 |
"""
|
| 472 |
+
return True, preview
|
| 473 |
|
| 474 |
# 드롭다운 변경 이벤트 연결
|
| 475 |
bg_main_category.change(
|
| 476 |
fn=update_bg_subcategory,
|
| 477 |
inputs=[bg_main_category],
|
| 478 |
+
outputs=[
|
| 479 |
+
bg_subcategory.choices,
|
| 480 |
+
bg_subcategory.value,
|
| 481 |
+
bg_specific.choices,
|
| 482 |
+
bg_specific.value
|
| 483 |
+
]
|
| 484 |
)
|
| 485 |
|
| 486 |
bg_subcategory.change(
|
| 487 |
fn=update_bg_specific,
|
| 488 |
inputs=[bg_main_category, bg_subcategory],
|
| 489 |
+
outputs=[
|
| 490 |
+
bg_specific.choices,
|
| 491 |
+
bg_specific.value
|
| 492 |
+
]
|
| 493 |
)
|
| 494 |
|
| 495 |
style_main.change(
|
| 496 |
fn=update_style_specific,
|
| 497 |
inputs=[style_main],
|
| 498 |
+
outputs=[
|
| 499 |
+
style_specific.choices,
|
| 500 |
+
style_specific.value
|
| 501 |
+
]
|
| 502 |
)
|
| 503 |
|
| 504 |
+
|
| 505 |
submit_btn.click(
|
| 506 |
fn=process_inputs,
|
| 507 |
inputs=[image_input, bg_main_category, bg_subcategory, bg_specific, style_main, style_specific, product_name, additional_info],
|