aiqtech commited on
Commit
bd40024
·
verified ·
1 Parent(s): 9eba18d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -30
app.py CHANGED
@@ -353,7 +353,7 @@ def process_prompt(img: Image.Image, prompt: str, bg_prompt: str | None = None,
353
  if img is None or prompt.strip() == "":
354
  raise gr.Error("Please provide both image and prompt")
355
 
356
- print(f"Processing with position: {position}, scale: {scale_percent}") # 디버깅용
357
 
358
  try:
359
  prompt = translate_to_english(prompt)
@@ -366,8 +366,7 @@ def process_prompt(img: Image.Image, prompt: str, bg_prompt: str | None = None,
366
 
367
  if bg_prompt:
368
  try:
369
- print(f"Using position: {position}") # 디버깅용
370
- # 위치 값 검증
371
  valid_positions = ["top-left", "top-center", "top-right",
372
  "middle-left", "middle-center", "middle-right",
373
  "bottom-left", "bottom-center", "bottom-right"]
@@ -381,12 +380,13 @@ def process_prompt(img: Image.Image, prompt: str, bg_prompt: str | None = None,
381
  position=position,
382
  scale_percent=scale_percent
383
  )
384
- return combined, results[2]
 
385
  except Exception as e:
386
  print(f"Combination error: {str(e)}")
387
- return results[1], results[2]
388
 
389
- return results[1], results[2] # 기본 반환 추가
390
  except Exception as e:
391
  print(f"Error in process_prompt: {str(e)}")
392
  raise gr.Error(str(e))
@@ -888,29 +888,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
888
  outputs=position
889
  )
890
 
891
-
892
- # 이벤트 바인딩
893
- bg_prompt.change(
894
- fn=update_controls,
895
- inputs=bg_prompt,
896
- outputs=[aspect_ratio, object_controls],
897
- queue=False
898
- )
899
-
900
- input_image.change(
901
- fn=update_process_button,
902
- inputs=[input_image, text_prompt],
903
- outputs=process_btn,
904
- queue=False
905
- )
906
-
907
- text_prompt.change(
908
- fn=update_process_button,
909
- inputs=[input_image, text_prompt],
910
- outputs=process_btn,
911
- queue=False
912
- )
913
-
914
  process_btn.click(
915
  fn=process_prompt,
916
  inputs=[
@@ -922,7 +899,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
922
  scale_slider
923
  ],
924
  outputs=[combined_image, extracted_image],
925
- queue=True
 
926
  )
927
 
928
  add_text_btn.click(
@@ -940,8 +918,46 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
940
  font_choice
941
  ],
942
  outputs=combined_image,
 
943
  show_progress=True
944
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
945
 
946
  demo.queue(max_size=5)
947
  demo.launch(
 
353
  if img is None or prompt.strip() == "":
354
  raise gr.Error("Please provide both image and prompt")
355
 
356
+ print(f"Processing with position: {position}, scale: {scale_percent}")
357
 
358
  try:
359
  prompt = translate_to_english(prompt)
 
366
 
367
  if bg_prompt:
368
  try:
369
+ print(f"Using position: {position}")
 
370
  valid_positions = ["top-left", "top-center", "top-right",
371
  "middle-left", "middle-center", "middle-right",
372
  "bottom-left", "bottom-center", "bottom-right"]
 
380
  position=position,
381
  scale_percent=scale_percent
382
  )
383
+ # 이미지를 RGB 모드로 변환하여 반환
384
+ return combined.convert('RGB'), results[2].convert('RGB')
385
  except Exception as e:
386
  print(f"Combination error: {str(e)}")
387
+ return results[1].convert('RGB'), results[2].convert('RGB')
388
 
389
+ return results[1].convert('RGB'), results[2].convert('RGB')
390
  except Exception as e:
391
  print(f"Error in process_prompt: {str(e)}")
392
  raise gr.Error(str(e))
 
888
  outputs=position
889
  )
890
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
891
  process_btn.click(
892
  fn=process_prompt,
893
  inputs=[
 
899
  scale_slider
900
  ],
901
  outputs=[combined_image, extracted_image],
902
+ queue=True,
903
+ show_progress=True
904
  )
905
 
906
  add_text_btn.click(
 
918
  font_choice
919
  ],
920
  outputs=combined_image,
921
+ queue=True,
922
  show_progress=True
923
  )
924
+
925
+ # 추가: 결과 이미지 업데이트를 위한 이벤트
926
+ combined_image.change(
927
+ fn=lambda x: x,
928
+ inputs=combined_image,
929
+ outputs=combined_image,
930
+ queue=False
931
+ )
932
+
933
+
934
+
935
+
936
+ # 이벤트 바인딩
937
+ bg_prompt.change(
938
+ fn=update_controls,
939
+ inputs=bg_prompt,
940
+ outputs=[aspect_ratio, object_controls],
941
+ queue=False
942
+ )
943
+
944
+ input_image.change(
945
+ fn=update_process_button,
946
+ inputs=[input_image, text_prompt],
947
+ outputs=process_btn,
948
+ queue=False
949
+ )
950
+
951
+ text_prompt.change(
952
+ fn=update_process_button,
953
+ inputs=[input_image, text_prompt],
954
+ outputs=process_btn,
955
+ queue=False
956
+ )
957
+
958
+
959
+
960
+
961
 
962
  demo.queue(max_size=5)
963
  demo.launch(