aiqtech commited on
Commit
168fce2
ยท
verified ยท
1 Parent(s): 2eff0d8

Update app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +83 -15
app-backup.py CHANGED
@@ -668,20 +668,6 @@ 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.Row():
687
  combined_image = gr.Image(
@@ -690,6 +676,59 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
690
  type="pil",
691
  height=512
692
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
693
  with gr.Row():
694
  extracted_image = gr.Image(
695
  label="Extracted Object",
@@ -698,6 +737,20 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
698
  height=256
699
  )
700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
  # Event bindings
702
  input_image.change(
703
  fn=update_process_button,
@@ -742,6 +795,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 +817,4 @@ demo.launch(
749
  server_port=7860,
750
  share=False,
751
  max_threads=2 # ์Šค๋ ˆ๋“œ ์ˆ˜ ์ œํ•œ
752
- )
 
668
  interactive=False
669
  )
670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  with gr.Column(scale=1):
672
  with gr.Row():
673
  combined_image = gr.Image(
 
676
  type="pil",
677
  height=512
678
  )
679
+
680
+ # ํ…์ŠคํŠธ ์‚ฝ์ž… ์ปจํŠธ๋กค ์„น์…˜ ์ถ”๊ฐ€
681
+ with gr.Accordion("Add Text to Image", open=False):
682
+ text_input = gr.Textbox(
683
+ label="Text to Add",
684
+ placeholder="Enter text to overlay on 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
+
730
+ add_text_btn = gr.Button("Apply Text", variant="secondary")
731
+
732
  with gr.Row():
733
  extracted_image = gr.Image(
734
  label="Extracted Object",
 
737
  height=256
738
  )
739
 
740
+ # ๊ฐ ๋ฒ„ํŠผ์— ๋Œ€ํ•œ ํด๋ฆญ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
741
+ def update_position(new_position):
742
+ return new_position
743
+
744
+ btn_top_left.click(fn=lambda: update_position("top-left"), outputs=position)
745
+ btn_top_center.click(fn=lambda: update_position("top-center"), outputs=position)
746
+ btn_top_right.click(fn=lambda: update_position("top-right"), outputs=position)
747
+ btn_middle_left.click(fn=lambda: update_position("middle-left"), outputs=position)
748
+ btn_middle_center.click(fn=lambda: update_position("middle-center"), outputs=position)
749
+ btn_middle_right.click(fn=lambda: update_position("middle-right"), outputs=position)
750
+ btn_bottom_left.click(fn=lambda: update_position("bottom-left"), outputs=position)
751
+ btn_bottom_center.click(fn=lambda: update_position("bottom-center"), outputs=position)
752
+ btn_bottom_right.click(fn=lambda: update_position("bottom-right"), outputs=position)
753
+
754
  # Event bindings
755
  input_image.change(
756
  fn=update_process_button,
 
795
  queue=True
796
  )
797
 
798
+ # ํ…์ŠคํŠธ ์ถ”๊ฐ€ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
799
+ add_text_btn.click(
800
+ fn=add_text_to_image,
801
+ inputs=[
802
+ combined_image,
803
+ text_input,
804
+ font_size,
805
+ color_dropdown,
806
+ opacity_slider,
807
+ x_position,
808
+ y_position,
809
+ thickness
810
+ ],
811
+ outputs=combined_image
812
+ )
813
 
814
  demo.queue(max_size=5) # ํ ํฌ๊ธฐ ์ œํ•œ
815
  demo.launch(
 
817
  server_port=7860,
818
  share=False,
819
  max_threads=2 # ์Šค๋ ˆ๋“œ ์ˆ˜ ์ œํ•œ
820
+ )