Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -601,7 +601,6 @@ def add_text_to_image(
|
|
601 |
# Convert PIL image back to numpy array for Gradio
|
602 |
return np.array(output_image)
|
603 |
|
604 |
-
# UI ๊ตฌ์ฑ
|
605 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
606 |
gr.HTML("""
|
607 |
<div class="main-title">
|
@@ -668,35 +667,88 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
668 |
interactive=False
|
669 |
)
|
670 |
|
671 |
-
# ๊ฐ ๋ฒํผ์ ๋ํ ํด๋ฆญ ์ด๋ฒคํธ ์ฒ๋ฆฌ
|
672 |
-
def update_position(new_position):
|
673 |
-
return new_position
|
674 |
-
|
675 |
-
btn_top_left.click(fn=lambda: update_position("top-left"), outputs=position)
|
676 |
-
btn_top_center.click(fn=lambda: update_position("top-center"), outputs=position)
|
677 |
-
btn_top_right.click(fn=lambda: update_position("top-right"), outputs=position)
|
678 |
-
btn_middle_left.click(fn=lambda: update_position("middle-left"), outputs=position)
|
679 |
-
btn_middle_center.click(fn=lambda: update_position("middle-center"), outputs=position)
|
680 |
-
btn_middle_right.click(fn=lambda: update_position("middle-right"), outputs=position)
|
681 |
-
btn_bottom_left.click(fn=lambda: update_position("bottom-left"), outputs=position)
|
682 |
-
btn_bottom_center.click(fn=lambda: update_position("bottom-center"), outputs=position)
|
683 |
-
btn_bottom_right.click(fn=lambda: update_position("bottom-right"), outputs=position)
|
684 |
-
|
685 |
with gr.Column(scale=1):
|
686 |
-
with gr.
|
687 |
combined_image = gr.Image(
|
688 |
label="Combined Result",
|
689 |
show_download_button=True,
|
690 |
type="pil",
|
691 |
height=512
|
692 |
)
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
|
701 |
# Event bindings
|
702 |
input_image.change(
|
@@ -742,6 +794,21 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
742 |
queue=True
|
743 |
)
|
744 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
745 |
|
746 |
demo.queue(max_size=5) # ํ ํฌ๊ธฐ ์ ํ
|
747 |
demo.launch(
|
@@ -749,4 +816,4 @@ demo.launch(
|
|
749 |
server_port=7860,
|
750 |
share=False,
|
751 |
max_threads=2 # ์ค๋ ๋ ์ ์ ํ
|
752 |
-
)
|
|
|
601 |
# Convert PIL image back to numpy array for Gradio
|
602 |
return np.array(output_image)
|
603 |
|
|
|
604 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
605 |
gr.HTML("""
|
606 |
<div class="main-title">
|
|
|
667 |
interactive=False
|
668 |
)
|
669 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
with gr.Column(scale=1):
|
671 |
+
with gr.Tab("Result"):
|
672 |
combined_image = gr.Image(
|
673 |
label="Combined Result",
|
674 |
show_download_button=True,
|
675 |
type="pil",
|
676 |
height=512
|
677 |
)
|
678 |
+
|
679 |
+
# ํ
์คํธ ์ฝ์
์ปจํธ๋กค์ ๋ ๋ช
ํํ๊ฒ ๊ตฌ๋ถ
|
680 |
+
with gr.Box():
|
681 |
+
gr.Markdown("### Add Text to Image")
|
682 |
+
text_input = gr.Textbox(
|
683 |
+
label="Text Content",
|
684 |
+
placeholder="Enter text to add to image..."
|
685 |
+
)
|
686 |
+
with gr.Row():
|
687 |
+
with gr.Column(scale=1):
|
688 |
+
font_size = gr.Slider(
|
689 |
+
minimum=10,
|
690 |
+
maximum=200,
|
691 |
+
value=40,
|
692 |
+
step=5,
|
693 |
+
label="Font Size"
|
694 |
+
)
|
695 |
+
color_dropdown = gr.Dropdown(
|
696 |
+
choices=["White", "Black", "Red", "Green", "Blue", "Yellow", "Purple"],
|
697 |
+
value="White",
|
698 |
+
label="Text Color"
|
699 |
+
)
|
700 |
+
thickness = gr.Slider(
|
701 |
+
minimum=0,
|
702 |
+
maximum=10,
|
703 |
+
value=1,
|
704 |
+
step=1,
|
705 |
+
label="Text Thickness"
|
706 |
+
)
|
707 |
+
with gr.Column(scale=1):
|
708 |
+
opacity_slider = gr.Slider(
|
709 |
+
minimum=0,
|
710 |
+
maximum=255,
|
711 |
+
value=255,
|
712 |
+
step=1,
|
713 |
+
label="Opacity"
|
714 |
+
)
|
715 |
+
x_position = gr.Slider(
|
716 |
+
minimum=0,
|
717 |
+
maximum=100,
|
718 |
+
value=50,
|
719 |
+
step=1,
|
720 |
+
label="X Position (%)"
|
721 |
+
)
|
722 |
+
y_position = gr.Slider(
|
723 |
+
minimum=0,
|
724 |
+
maximum=100,
|
725 |
+
value=50,
|
726 |
+
step=1,
|
727 |
+
label="Y Position (%)"
|
728 |
+
)
|
729 |
+
add_text_btn = gr.Button("Apply Text", variant="primary")
|
730 |
+
|
731 |
+
with gr.Row():
|
732 |
+
extracted_image = gr.Image(
|
733 |
+
label="Extracted Object",
|
734 |
+
show_download_button=True,
|
735 |
+
type="pil",
|
736 |
+
height=256
|
737 |
+
)
|
738 |
+
|
739 |
+
# ๊ฐ ๋ฒํผ์ ๋ํ ํด๋ฆญ ์ด๋ฒคํธ ์ฒ๋ฆฌ
|
740 |
+
def update_position(new_position):
|
741 |
+
return new_position
|
742 |
+
|
743 |
+
btn_top_left.click(fn=lambda: update_position("top-left"), outputs=position)
|
744 |
+
btn_top_center.click(fn=lambda: update_position("top-center"), outputs=position)
|
745 |
+
btn_top_right.click(fn=lambda: update_position("top-right"), outputs=position)
|
746 |
+
btn_middle_left.click(fn=lambda: update_position("middle-left"), outputs=position)
|
747 |
+
btn_middle_center.click(fn=lambda: update_position("middle-center"), outputs=position)
|
748 |
+
btn_middle_right.click(fn=lambda: update_position("middle-right"), outputs=position)
|
749 |
+
btn_bottom_left.click(fn=lambda: update_position("bottom-left"), outputs=position)
|
750 |
+
btn_bottom_center.click(fn=lambda: update_position("bottom-center"), outputs=position)
|
751 |
+
btn_bottom_right.click(fn=lambda: update_position("bottom-right"), outputs=position)
|
752 |
|
753 |
# Event bindings
|
754 |
input_image.change(
|
|
|
794 |
queue=True
|
795 |
)
|
796 |
|
797 |
+
# ํ
์คํธ ์ถ๊ฐ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
798 |
+
add_text_btn.click(
|
799 |
+
fn=add_text_to_image,
|
800 |
+
inputs=[
|
801 |
+
combined_image,
|
802 |
+
text_input,
|
803 |
+
font_size,
|
804 |
+
color_dropdown,
|
805 |
+
opacity_slider,
|
806 |
+
x_position,
|
807 |
+
y_position,
|
808 |
+
thickness
|
809 |
+
],
|
810 |
+
outputs=combined_image
|
811 |
+
)
|
812 |
|
813 |
demo.queue(max_size=5) # ํ ํฌ๊ธฐ ์ ํ
|
814 |
demo.launch(
|
|
|
816 |
server_port=7860,
|
817 |
share=False,
|
818 |
max_threads=2 # ์ค๋ ๋ ์ ์ ํ
|
819 |
+
)
|