Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
import google.generativeai as genai
|
| 4 |
from PIL import Image
|
|
@@ -436,84 +435,95 @@ def create_app():
|
|
| 436 |
image_preview = gr.Image(label="์
๋ก๋๋ ์ด๋ฏธ์ง (#1)", type="pil")
|
| 437 |
preview_html = gr.HTML("ํ๋กฌํํธ ์์ฑ ์ ์ฌ๊ธฐ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ ํ์๋ฉ๋๋ค.", visible=True)
|
| 438 |
|
| 439 |
-
#
|
| 440 |
-
def
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
-
|
| 454 |
-
def update_style_specific(style_main):
|
| 455 |
if style_main == "ํ์์ ์ ํํ์ธ์":
|
| 456 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
specific_styles = get_specific_styles(style_main)
|
| 458 |
first_specific = specific_styles[0] if specific_styles else None
|
| 459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
|
| 461 |
-
def
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
<
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
-
#
|
| 475 |
bg_main_category.change(
|
| 476 |
-
fn=
|
| 477 |
-
inputs=
|
| 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=
|
| 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=
|
| 497 |
-
inputs=
|
| 498 |
-
outputs=
|
| 499 |
-
style_specific.choices,
|
| 500 |
-
style_specific.value
|
| 501 |
-
]
|
| 502 |
)
|
| 503 |
|
| 504 |
-
|
| 505 |
submit_btn.click(
|
| 506 |
-
fn=
|
| 507 |
-
inputs=[
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
|
|
|
| 513 |
)
|
| 514 |
|
| 515 |
return demo
|
| 516 |
|
| 517 |
if __name__ == "__main__":
|
| 518 |
app = create_app()
|
| 519 |
-
app.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import google.generativeai as genai
|
| 3 |
from PIL import Image
|
|
|
|
| 435 |
image_preview = gr.Image(label="์
๋ก๋๋ ์ด๋ฏธ์ง (#1)", type="pil")
|
| 436 |
preview_html = gr.HTML("ํ๋กฌํํธ ์์ฑ ์ ์ฌ๊ธฐ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ ํ์๋ฉ๋๋ค.", visible=True)
|
| 437 |
|
| 438 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๋ค
|
| 439 |
+
def on_bg_main_change(bg_main):
|
| 440 |
subcategories = get_subcategories_background(bg_main)
|
| 441 |
first_sub = subcategories[0] if subcategories else None
|
| 442 |
specific_options = get_specific_backgrounds(bg_main, first_sub) if first_sub else []
|
| 443 |
first_specific = specific_options[0] if specific_options else None
|
| 444 |
+
|
| 445 |
+
return {
|
| 446 |
+
"choices": subcategories,
|
| 447 |
+
"value": first_sub
|
| 448 |
+
}, {
|
| 449 |
+
"choices": specific_options,
|
| 450 |
+
"value": first_specific
|
| 451 |
+
}
|
| 452 |
|
| 453 |
+
def on_bg_sub_change(bg_main, bg_sub):
|
|
|
|
| 454 |
specific_options = get_specific_backgrounds(bg_main, bg_sub)
|
| 455 |
first_specific = specific_options[0] if specific_options else None
|
| 456 |
+
|
| 457 |
+
return {
|
| 458 |
+
"choices": specific_options,
|
| 459 |
+
"value": first_specific
|
| 460 |
+
}
|
| 461 |
|
| 462 |
+
def on_style_main_change(style_main):
|
|
|
|
| 463 |
if style_main == "ํ์์ ์ ํํ์ธ์":
|
| 464 |
+
return {
|
| 465 |
+
"choices": [default_style_specific],
|
| 466 |
+
"value": default_style_specific
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
specific_styles = get_specific_styles(style_main)
|
| 470 |
first_specific = specific_styles[0] if specific_styles else None
|
| 471 |
+
|
| 472 |
+
return {
|
| 473 |
+
"choices": specific_styles,
|
| 474 |
+
"value": first_specific
|
| 475 |
+
}
|
| 476 |
|
| 477 |
+
def on_submit(img, bg_main, bg_sub, bg_specific, style_main, style_specific, prod_name, add_info):
|
| 478 |
+
output, preview_img = process_inputs(img, bg_main, bg_sub, bg_specific, style_main, style_specific, prod_name, add_info)
|
| 479 |
+
|
| 480 |
+
preview_visible = not (not output or "API ํค" in output)
|
| 481 |
+
preview_content = ""
|
| 482 |
+
|
| 483 |
+
if preview_visible:
|
| 484 |
+
preview_content = f"""
|
| 485 |
+
<div style="padding:10px; border:1px solid #ddd; border-radius:8px; margin-top:10px;">
|
| 486 |
+
<h3>ํ๋กฌํํธ ์์ฝ</h3>
|
| 487 |
+
<p><strong>์ด ๊ธธ์ด:</strong> {len(output)} ๊ธ์</p>
|
| 488 |
+
<p><strong>์ฃผ์ ์์:</strong> {", ".join([kw for kw in ["commercial photography", "product", "square format", "centered", "detailed"] if kw.lower() in output.lower()])}</p>
|
| 489 |
+
<p><strong>๋ฏธ๋์ ๋ ํ๋ผ๋ฏธํฐ:</strong> {" ".join([param for param in ["--ar 1:1", "--s 750", "--q 2"] if param in output])}</p>
|
| 490 |
+
</div>
|
| 491 |
+
"""
|
| 492 |
+
|
| 493 |
+
return output, preview_img, preview_content, preview_visible
|
| 494 |
|
| 495 |
+
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 496 |
bg_main_category.change(
|
| 497 |
+
fn=on_bg_main_change,
|
| 498 |
+
inputs=bg_main_category,
|
| 499 |
+
outputs=[bg_subcategory, bg_specific]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
)
|
| 501 |
|
| 502 |
bg_subcategory.change(
|
| 503 |
+
fn=on_bg_sub_change,
|
| 504 |
inputs=[bg_main_category, bg_subcategory],
|
| 505 |
+
outputs=bg_specific
|
|
|
|
|
|
|
|
|
|
| 506 |
)
|
| 507 |
|
| 508 |
style_main.change(
|
| 509 |
+
fn=on_style_main_change,
|
| 510 |
+
inputs=style_main,
|
| 511 |
+
outputs=style_specific
|
|
|
|
|
|
|
|
|
|
| 512 |
)
|
| 513 |
|
|
|
|
| 514 |
submit_btn.click(
|
| 515 |
+
fn=on_submit,
|
| 516 |
+
inputs=[
|
| 517 |
+
image_input, bg_main_category, bg_subcategory, bg_specific,
|
| 518 |
+
style_main, style_specific, product_name, additional_info
|
| 519 |
+
],
|
| 520 |
+
outputs=[
|
| 521 |
+
prompt_output, image_preview, preview_html, preview_html
|
| 522 |
+
]
|
| 523 |
)
|
| 524 |
|
| 525 |
return demo
|
| 526 |
|
| 527 |
if __name__ == "__main__":
|
| 528 |
app = create_app()
|
| 529 |
+
app.launch()
|