ginipick commited on
Commit
8a2208e
ยท
verified ยท
1 Parent(s): 757d60f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -48
app.py CHANGED
@@ -678,6 +678,28 @@ def add_text_to_image(
678
  # ์ „์—ญ ๋ณ€์ˆ˜ ์„ค์ •
679
  current_position = None # position ์ƒํƒœ๋ฅผ ์ „์—ญ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜
680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
682
  gr.HTML("""
683
  <div class="main-title">
@@ -844,39 +866,19 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
844
  </style>
845
  """)
846
 
847
- # ์œ„์น˜ ์—…๋ฐ์ดํŠธ ํ•จ์ˆ˜ ์ˆ˜์ •
848
- def update_position(new_position):
849
- print(f"Position updated to: {new_position}") # ๋””๋ฒ„๊น…์šฉ
850
- return new_position
851
 
852
- # ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ ์ˆ˜์ •
853
- btn_top_left.click(fn=lambda: update_position("top-left"), outputs=position)
854
- btn_top_center.click(fn=lambda: update_position("top-center"), outputs=position)
855
- btn_top_right.click(fn=lambda: update_position("top-right"), outputs=position)
856
- btn_middle_left.click(fn=lambda: update_position("middle-left"), outputs=position)
857
- btn_middle_center.click(fn=lambda: update_position("middle-center"), outputs=position)
858
- btn_middle_right.click(fn=lambda: update_position("middle-right"), outputs=position)
859
- btn_bottom_left.click(fn=lambda: update_position("bottom-left"), outputs=position)
860
- btn_bottom_center.click(fn=lambda: update_position("bottom-center"), outputs=position)
861
- btn_bottom_right.click(fn=lambda: update_position("bottom-right"), outputs=position)
862
 
863
- def update_button_styles():
864
- return {
865
- btn: gr.update(elem_classes=["position-btn", "selected"] if pos == current_position else ["position-btn"])
866
- for btn, pos in [
867
- (btn_top_left, "top-left"),
868
- (btn_top_center, "top-center"),
869
- (btn_top_right, "top-right"),
870
- (btn_middle_left, "middle-left"),
871
- (btn_middle_center, "middle-center"),
872
- (btn_middle_right, "middle-right"),
873
- (btn_bottom_left, "bottom-left"),
874
- (btn_bottom_center, "bottom-center"),
875
- (btn_bottom_right, "bottom-right")
876
- ]
877
- }
878
-
879
- # ๊ธฐ์กด ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
880
  input_image.change(
881
  fn=update_process_button,
882
  inputs=[input_image, text_prompt],
@@ -898,7 +900,6 @@ def update_button_styles():
898
  queue=False
899
  )
900
 
901
- # Process ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ์ˆ˜์ •
902
  process_btn.click(
903
  fn=process_prompt,
904
  inputs=[
@@ -906,24 +907,13 @@ def update_button_styles():
906
  text_prompt,
907
  bg_prompt,
908
  aspect_ratio,
909
- position, # position ์ƒํƒœ ์ „๋‹ฌ
910
  scale_slider
911
  ],
912
  outputs=[combined_image, extracted_image],
913
  queue=True
914
  )
915
 
916
-
917
- def update_controls(bg_prompt):
918
- """๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์ปจํŠธ๋กค ํ‘œ์‹œ ์—…๋ฐ์ดํŠธ"""
919
- is_visible = bool(bg_prompt)
920
- return [
921
- gr.update(visible=is_visible), # aspect_ratio
922
- gr.update(visible=is_visible), # object_controls
923
- ]
924
-
925
-
926
- # ํ…์ŠคํŠธ ์ถ”๊ฐ€ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ์ˆ˜์ •
927
  add_text_btn.click(
928
  fn=add_text_to_image,
929
  inputs=[
@@ -936,16 +926,15 @@ def update_button_styles():
936
  y_position,
937
  thickness,
938
  text_position_type,
939
- font_choice # ์ƒˆ๋กœ์šด ์ž…๋ ฅ ์ถ”๊ฐ€
940
  ],
941
  outputs=combined_image
942
  )
943
 
944
-
945
- demo.queue(max_size=5) # ํ ํฌ๊ธฐ ์ œํ•œ
946
  demo.launch(
947
  server_name="0.0.0.0",
948
  server_port=7860,
949
  share=False,
950
- max_threads=2 # ์Šค๋ ˆ๋“œ ์ˆ˜ ์ œํ•œ
951
  )
 
678
  # ์ „์—ญ ๋ณ€์ˆ˜ ์„ค์ •
679
  current_position = None # position ์ƒํƒœ๋ฅผ ์ „์—ญ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜
680
 
681
+ # ์œ„์น˜ ์—…๋ฐ์ดํŠธ ํ•จ์ˆ˜ ์ˆ˜์ •
682
+ def update_position(new_position):
683
+ print(f"Position updated to: {new_position}") # ๋””๋ฒ„๊น…์šฉ
684
+ return new_position
685
+
686
+
687
+ def update_button_styles():
688
+ return {
689
+ btn: gr.update(elem_classes=["position-btn", "selected"] if pos == current_position else ["position-btn"])
690
+ for btn, pos in [
691
+ (btn_top_left, "top-left"),
692
+ (btn_top_center, "top-center"),
693
+ (btn_top_right, "top-right"),
694
+ (btn_middle_left, "middle-left"),
695
+ (btn_middle_center, "middle-center"),
696
+ (btn_middle_right, "middle-right"),
697
+ (btn_bottom_left, "bottom-left"),
698
+ (btn_bottom_center, "bottom-center"),
699
+ (btn_bottom_right, "bottom-right")
700
+ ]
701
+ }
702
+
703
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
704
  gr.HTML("""
705
  <div class="main-title">
 
866
  </style>
867
  """)
868
 
 
 
 
 
869
 
870
+ # ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
871
+ btn_top_left.click(fn=lambda: update_position("top-left"), outputs=position)
872
+ btn_top_center.click(fn=lambda: update_position("top-center"), outputs=position)
873
+ btn_top_right.click(fn=lambda: update_position("top-right"), outputs=position)
874
+ btn_middle_left.click(fn=lambda: update_position("middle-left"), outputs=position)
875
+ btn_middle_center.click(fn=lambda: update_position("middle-center"), outputs=position)
876
+ btn_middle_right.click(fn=lambda: update_position("middle-right"), outputs=position)
877
+ btn_bottom_left.click(fn=lambda: update_position("bottom-left"), outputs=position)
878
+ btn_bottom_center.click(fn=lambda: update_position("bottom-center"), outputs=position)
879
+ btn_bottom_right.click(fn=lambda: update_position("bottom-right"), outputs=position)
880
 
881
+ # ๊ธฐํƒ€ ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882
  input_image.change(
883
  fn=update_process_button,
884
  inputs=[input_image, text_prompt],
 
900
  queue=False
901
  )
902
 
 
903
  process_btn.click(
904
  fn=process_prompt,
905
  inputs=[
 
907
  text_prompt,
908
  bg_prompt,
909
  aspect_ratio,
910
+ position,
911
  scale_slider
912
  ],
913
  outputs=[combined_image, extracted_image],
914
  queue=True
915
  )
916
 
 
 
 
 
 
 
 
 
 
 
 
917
  add_text_btn.click(
918
  fn=add_text_to_image,
919
  inputs=[
 
926
  y_position,
927
  thickness,
928
  text_position_type,
929
+ font_choice
930
  ],
931
  outputs=combined_image
932
  )
933
 
934
+ demo.queue(max_size=5)
 
935
  demo.launch(
936
  server_name="0.0.0.0",
937
  server_port=7860,
938
  share=False,
939
+ max_threads=2
940
  )