Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -684,17 +684,66 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
684 |
height=256
|
685 |
)
|
686 |
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
|
699 |
# ์์น ๋ฒํผ ์ด๋ฒคํธ
|
700 |
for btn, pos in [
|
@@ -716,29 +765,20 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
716 |
scale_slider,
|
717 |
gr.State(get_text_params)
|
718 |
],
|
719 |
-
outputs=[combined_image, extracted_image]
|
|
|
720 |
)
|
721 |
|
722 |
-
|
723 |
-
|
724 |
-
fn=update_process_button,
|
725 |
-
inputs=[input_image, text_prompt],
|
726 |
-
outputs=process_btn
|
727 |
-
)
|
728 |
-
|
729 |
-
text_prompt.change(
|
730 |
-
fn=update_process_button,
|
731 |
-
inputs=[input_image, text_prompt],
|
732 |
-
outputs=process_btn
|
733 |
-
)
|
734 |
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
|
|
740 |
|
741 |
-
# ๋ฐ์ฒ ์ค์
|
742 |
demo.queue(max_size=5)
|
743 |
demo.launch(
|
744 |
server_name="0.0.0.0",
|
|
|
684 |
height=256
|
685 |
)
|
686 |
|
687 |
+
|
688 |
+
# UI ๊ตฌ์ฑ ๋ถ๋ถ์์ ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๋ค์ ๋จผ์ ์ ์
|
689 |
+
def update_controls(bg_prompt):
|
690 |
+
"""๋ฐฐ๊ฒฝ ํ๋กฌํํธ ์
๋ ฅ ์ฌ๋ถ์ ๋ฐ๋ผ ์ปจํธ๋กค ํ์ ์
๋ฐ์ดํธ"""
|
691 |
+
is_visible = bool(bg_prompt)
|
692 |
+
return [
|
693 |
+
gr.update(visible=True), # aspect_ratio๋ ํญ์ ํ์
|
694 |
+
gr.update(visible=is_visible) # object_controls
|
695 |
+
]
|
696 |
+
|
697 |
+
def update_process_button(img, prompt):
|
698 |
+
"""ํ๋ก์ธ์ค ๋ฒํผ ์ํ ์
๋ฐ์ดํธ"""
|
699 |
+
return gr.update(
|
700 |
+
interactive=bool(img and prompt),
|
701 |
+
variant="primary" if bool(img and prompt) else "secondary"
|
702 |
+
)
|
703 |
+
|
704 |
+
def get_text_params():
|
705 |
+
"""ํ
์คํธ ํ๋ผ๋ฏธํฐ ๊ฐ์ ธ์ค๊ธฐ"""
|
706 |
+
return {
|
707 |
+
'text': text_input.value,
|
708 |
+
'font_size': font_size.value,
|
709 |
+
'thickness': thickness.value,
|
710 |
+
'color': color_dropdown.value,
|
711 |
+
'opacity': opacity_slider.value,
|
712 |
+
'x_position': text_x_position.value,
|
713 |
+
'y_position': text_y_position.value
|
714 |
+
}
|
715 |
+
|
716 |
+
|
717 |
+
|
718 |
+
# ์์น ๋ฒํผ ์ด๋ฒคํธ
|
719 |
+
for btn, pos in [
|
720 |
+
(btn_top_left, "top-left"), (btn_top_center, "top-center"), (btn_top_right, "top-right"),
|
721 |
+
(btn_middle_left, "middle-left"), (btn_middle_center, "middle-center"), (btn_middle_right, "middle-right"),
|
722 |
+
(btn_bottom_left, "bottom-left"), (btn_bottom_center, "bottom-center"), (btn_bottom_right, "bottom-right")
|
723 |
+
]:
|
724 |
+
btn.click(fn=lambda p=pos: p, outputs=position)
|
725 |
+
|
726 |
+
# ์ด๋ฒคํธ ๋ฐ์ธ๋ฉ
|
727 |
+
input_image.change(
|
728 |
+
fn=update_process_button,
|
729 |
+
inputs=[input_image, text_prompt],
|
730 |
+
outputs=process_btn,
|
731 |
+
queue=False
|
732 |
+
)
|
733 |
+
|
734 |
+
text_prompt.change(
|
735 |
+
fn=update_process_button,
|
736 |
+
inputs=[input_image, text_prompt],
|
737 |
+
outputs=process_btn,
|
738 |
+
queue=False
|
739 |
+
)
|
740 |
+
|
741 |
+
bg_prompt.change(
|
742 |
+
fn=update_controls,
|
743 |
+
inputs=[bg_prompt],
|
744 |
+
outputs=[aspect_ratio, object_controls],
|
745 |
+
queue=False
|
746 |
+
)
|
747 |
|
748 |
# ์์น ๋ฒํผ ์ด๋ฒคํธ
|
749 |
for btn, pos in [
|
|
|
765 |
scale_slider,
|
766 |
gr.State(get_text_params)
|
767 |
],
|
768 |
+
outputs=[combined_image, extracted_image],
|
769 |
+
queue=True
|
770 |
)
|
771 |
|
772 |
+
if HF_TOKEN:
|
773 |
+
login(token=HF_TOKEN, add_to_git_credential=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
774 |
|
775 |
+
# FLUX ํ์ดํ๋ผ์ธ ์ด๊ธฐํ ์์
|
776 |
+
pipe = FluxPipeline.from_pretrained(
|
777 |
+
"black-forest-labs/FLUX.1-dev",
|
778 |
+
torch_dtype=torch.float16,
|
779 |
+
token=HF_TOKEN # use_auth_token ๋์ token ์ฌ์ฉ
|
780 |
+
)
|
781 |
|
|
|
782 |
demo.queue(max_size=5)
|
783 |
demo.launch(
|
784 |
server_name="0.0.0.0",
|