Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -805,7 +805,7 @@ def update_controls(bg_prompt):
|
|
805 |
]
|
806 |
|
807 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
808 |
-
position = gr.State(value="bottom-center")
|
809 |
|
810 |
gr.HTML("""
|
811 |
<div class="main-title">
|
@@ -818,63 +818,78 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
818 |
# 왼쪽 패널 (입력)
|
819 |
with gr.Column(scale=1):
|
820 |
with gr.Group(elem_classes="input-panel"):
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
placeholder="Enter what you want to extract...",
|
830 |
-
interactive=True
|
831 |
-
)
|
832 |
-
with gr.Row():
|
833 |
-
bg_prompt = gr.Textbox(
|
834 |
-
label="Background Prompt (optional)",
|
835 |
-
placeholder="Describe the background...",
|
836 |
-
interactive=True,
|
837 |
-
scale=3
|
838 |
-
)
|
839 |
-
aspect_ratio = gr.Dropdown(
|
840 |
-
choices=["1:1", "16:9", "9:16", "4:3"],
|
841 |
-
value="1:1",
|
842 |
-
label="Aspect Ratio",
|
843 |
-
interactive=True,
|
844 |
-
visible=True,
|
845 |
-
scale=1
|
846 |
-
)
|
847 |
-
|
848 |
-
with gr.Group(elem_classes="controls-panel", visible=False) as object_controls:
|
849 |
-
with gr.Column(scale=1):
|
850 |
-
position = gr.State(value="bottom-center") # 초기값 설정
|
851 |
-
with gr.Row():
|
852 |
-
btn_top_left = gr.Button("↖", elem_classes="position-btn")
|
853 |
-
btn_top_center = gr.Button("↑", elem_classes="position-btn")
|
854 |
-
btn_top_right = gr.Button("↗", elem_classes="position-btn")
|
855 |
-
with gr.Row():
|
856 |
-
btn_middle_left = gr.Button("←", elem_classes="position-btn")
|
857 |
-
btn_middle_center = gr.Button("•", elem_classes="position-btn")
|
858 |
-
btn_middle_right = gr.Button("→", elem_classes="position-btn")
|
859 |
-
with gr.Row():
|
860 |
-
btn_bottom_left = gr.Button("↙", elem_classes="position-btn")
|
861 |
-
btn_bottom_center = gr.Button("↓", elem_classes="position-btn", value="selected")
|
862 |
-
btn_bottom_right = gr.Button("↘", elem_classes="position-btn")
|
863 |
-
with gr.Column(scale=1):
|
864 |
-
scale_slider = gr.Slider(
|
865 |
-
minimum=10,
|
866 |
-
maximum=200,
|
867 |
-
value=50,
|
868 |
-
step=5,
|
869 |
-
label="Object Size (%)"
|
870 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
871 |
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
|
879 |
# 오른쪽 패널 (출력)
|
880 |
with gr.Column(scale=1):
|
@@ -887,7 +902,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
887 |
height=400
|
888 |
)
|
889 |
|
890 |
-
# 텍스트 삽입 옵션을 Accordion으로 변경
|
891 |
with gr.Accordion("Text Insertion Options", open=False):
|
892 |
with gr.Group():
|
893 |
with gr.Row():
|
@@ -904,14 +918,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
904 |
with gr.Row():
|
905 |
with gr.Column(scale=1):
|
906 |
font_choice = gr.Dropdown(
|
907 |
-
choices=["Default", "Korean Regular"],
|
908 |
-
|
909 |
value="Default",
|
910 |
label="Font Selection",
|
911 |
interactive=True
|
912 |
)
|
913 |
-
|
914 |
-
|
915 |
font_size = gr.Slider(
|
916 |
minimum=10,
|
917 |
maximum=200,
|
@@ -962,7 +973,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
962 |
height=200
|
963 |
)
|
964 |
|
965 |
-
# CSS
|
966 |
gr.HTML("""
|
967 |
<style>
|
968 |
.position-btn.selected {
|
@@ -972,7 +983,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
972 |
</style>
|
973 |
""")
|
974 |
|
975 |
-
#
|
976 |
position_mapping = {
|
977 |
btn_top_left: "top-left",
|
978 |
btn_top_center: "top-center",
|
@@ -987,12 +998,16 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
987 |
|
988 |
for btn, pos in position_mapping.items():
|
989 |
btn.click(
|
990 |
-
fn=lambda pos=pos: update_position(pos),
|
991 |
outputs=position
|
992 |
)
|
993 |
-
|
994 |
|
995 |
-
|
|
|
|
|
|
|
|
|
|
|
996 |
bg_prompt.change(
|
997 |
fn=update_controls,
|
998 |
inputs=bg_prompt,
|
@@ -1028,12 +1043,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
1028 |
queue=True
|
1029 |
)
|
1030 |
|
1031 |
-
# 이벤트 바인딩 부분에서
|
1032 |
add_text_btn.click(
|
1033 |
fn=add_text_to_image,
|
1034 |
inputs=[
|
1035 |
-
combined_image,
|
1036 |
-
text_input,
|
1037 |
font_size,
|
1038 |
color_dropdown,
|
1039 |
opacity_slider,
|
@@ -1044,10 +1058,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
1044 |
font_choice
|
1045 |
],
|
1046 |
outputs=combined_image,
|
1047 |
-
api_name="add_text"
|
1048 |
)
|
1049 |
-
|
1050 |
-
|
1051 |
|
1052 |
demo.queue(max_size=5)
|
1053 |
demo.launch(
|
|
|
805 |
]
|
806 |
|
807 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
808 |
+
position = gr.State(value="bottom-center")
|
809 |
|
810 |
gr.HTML("""
|
811 |
<div class="main-title">
|
|
|
818 |
# 왼쪽 패널 (입력)
|
819 |
with gr.Column(scale=1):
|
820 |
with gr.Group(elem_classes="input-panel"):
|
821 |
+
with gr.Tabs():
|
822 |
+
# 첫 번째 탭: 이미지 업로드 및 인페인팅
|
823 |
+
with gr.Tab("Image Upload & Inpainting"):
|
824 |
+
input_image = gr.Image(
|
825 |
+
type="pil",
|
826 |
+
label="Upload Image",
|
827 |
+
interactive=True,
|
828 |
+
height=400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
829 |
)
|
830 |
+
with gr.Group():
|
831 |
+
inpaint_prompt = gr.Textbox(
|
832 |
+
label="Inpainting Prompt",
|
833 |
+
placeholder="Describe what you want to add in the masked area..."
|
834 |
+
)
|
835 |
+
mask_input = image_annotator(
|
836 |
+
label="Draw mask for inpainting",
|
837 |
+
height=400
|
838 |
+
)
|
839 |
+
inpaint_btn = gr.Button("Apply Inpainting", variant="primary")
|
840 |
+
|
841 |
+
# 두 번째 탭: 배경 제거 및 생성
|
842 |
+
with gr.Tab("Background Removal"):
|
843 |
+
text_prompt = gr.Textbox(
|
844 |
+
label="Object to Extract",
|
845 |
+
placeholder="Enter what you want to extract...",
|
846 |
+
interactive=True
|
847 |
+
)
|
848 |
+
with gr.Row():
|
849 |
+
bg_prompt = gr.Textbox(
|
850 |
+
label="Background Prompt (optional)",
|
851 |
+
placeholder="Describe the background...",
|
852 |
+
interactive=True,
|
853 |
+
scale=3
|
854 |
+
)
|
855 |
+
aspect_ratio = gr.Dropdown(
|
856 |
+
choices=["1:1", "16:9", "9:16", "4:3"],
|
857 |
+
value="1:1",
|
858 |
+
label="Aspect Ratio",
|
859 |
+
interactive=True,
|
860 |
+
visible=True,
|
861 |
+
scale=1
|
862 |
+
)
|
863 |
+
|
864 |
+
with gr.Group(elem_classes="controls-panel", visible=False) as object_controls:
|
865 |
+
with gr.Column(scale=1):
|
866 |
+
with gr.Row():
|
867 |
+
btn_top_left = gr.Button("↖", elem_classes="position-btn")
|
868 |
+
btn_top_center = gr.Button("↑", elem_classes="position-btn")
|
869 |
+
btn_top_right = gr.Button("↗", elem_classes="position-btn")
|
870 |
+
with gr.Row():
|
871 |
+
btn_middle_left = gr.Button("←", elem_classes="position-btn")
|
872 |
+
btn_middle_center = gr.Button("•", elem_classes="position-btn")
|
873 |
+
btn_middle_right = gr.Button("→", elem_classes="position-btn")
|
874 |
+
with gr.Row():
|
875 |
+
btn_bottom_left = gr.Button("↙", elem_classes="position-btn")
|
876 |
+
btn_bottom_center = gr.Button("↓", elem_classes="position-btn", value="selected")
|
877 |
+
btn_bottom_right = gr.Button("↘", elem_classes="position-btn")
|
878 |
+
with gr.Column(scale=1):
|
879 |
+
scale_slider = gr.Slider(
|
880 |
+
minimum=10,
|
881 |
+
maximum=200,
|
882 |
+
value=50,
|
883 |
+
step=5,
|
884 |
+
label="Object Size (%)"
|
885 |
+
)
|
886 |
|
887 |
+
process_btn = gr.Button(
|
888 |
+
"Process",
|
889 |
+
variant="primary",
|
890 |
+
interactive=False,
|
891 |
+
size="lg"
|
892 |
+
)
|
893 |
|
894 |
# 오른쪽 패널 (출력)
|
895 |
with gr.Column(scale=1):
|
|
|
902 |
height=400
|
903 |
)
|
904 |
|
|
|
905 |
with gr.Accordion("Text Insertion Options", open=False):
|
906 |
with gr.Group():
|
907 |
with gr.Row():
|
|
|
918 |
with gr.Row():
|
919 |
with gr.Column(scale=1):
|
920 |
font_choice = gr.Dropdown(
|
921 |
+
choices=["Default", "Korean Regular"],
|
|
|
922 |
value="Default",
|
923 |
label="Font Selection",
|
924 |
interactive=True
|
925 |
)
|
|
|
|
|
926 |
font_size = gr.Slider(
|
927 |
minimum=10,
|
928 |
maximum=200,
|
|
|
973 |
height=200
|
974 |
)
|
975 |
|
976 |
+
# CSS 스타일
|
977 |
gr.HTML("""
|
978 |
<style>
|
979 |
.position-btn.selected {
|
|
|
983 |
</style>
|
984 |
""")
|
985 |
|
986 |
+
# 이벤트 바인딩
|
987 |
position_mapping = {
|
988 |
btn_top_left: "top-left",
|
989 |
btn_top_center: "top-center",
|
|
|
998 |
|
999 |
for btn, pos in position_mapping.items():
|
1000 |
btn.click(
|
1001 |
+
fn=lambda pos=pos: update_position(pos),
|
1002 |
outputs=position
|
1003 |
)
|
|
|
1004 |
|
1005 |
+
inpaint_btn.click(
|
1006 |
+
fn=process_inpainting,
|
1007 |
+
inputs=[input_image, mask_input, inpaint_prompt],
|
1008 |
+
outputs=input_image
|
1009 |
+
)
|
1010 |
+
|
1011 |
bg_prompt.change(
|
1012 |
fn=update_controls,
|
1013 |
inputs=bg_prompt,
|
|
|
1043 |
queue=True
|
1044 |
)
|
1045 |
|
|
|
1046 |
add_text_btn.click(
|
1047 |
fn=add_text_to_image,
|
1048 |
inputs=[
|
1049 |
+
combined_image,
|
1050 |
+
text_input,
|
1051 |
font_size,
|
1052 |
color_dropdown,
|
1053 |
opacity_slider,
|
|
|
1058 |
font_choice
|
1059 |
],
|
1060 |
outputs=combined_image,
|
1061 |
+
api_name="add_text"
|
1062 |
)
|
|
|
|
|
1063 |
|
1064 |
demo.queue(max_size=5)
|
1065 |
demo.launch(
|