Update app.py
Browse files
app.py
CHANGED
|
@@ -45,6 +45,80 @@ def load_backgrounds_from_env():
|
|
| 45 |
backgrounds_code = os.environ.get("BACKGROUNDS_DATA", "")
|
| 46 |
if not backgrounds_code:
|
| 47 |
logger.warning("BACKGROUNDS_DATA environment variable is empty")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
|
| 50 |
temp_filename = temp_file.name
|
|
@@ -135,7 +209,7 @@ def api_check_password(password, image_file, bg_type, simple, studio, nature, in
|
|
| 135 |
return result
|
| 136 |
except Exception as e:
|
| 137 |
logger.error(f"Error calling check_password API: {e}")
|
| 138 |
-
return
|
| 139 |
|
| 140 |
# Gradio 인터페이스 구성 (완전히 동일한 UI)
|
| 141 |
def create_gradio_interface():
|
|
@@ -223,8 +297,17 @@ def create_gradio_interface():
|
|
| 223 |
interactive=True
|
| 224 |
)
|
| 225 |
|
| 226 |
-
# 드롭다운 변경 함수
|
| 227 |
def update_dropdowns(bg_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
return {
|
| 229 |
simple_dropdown: gr.update(visible=(bg_type == "심플 배경")),
|
| 230 |
studio_dropdown: gr.update(visible=(bg_type == "스튜디오 배경")),
|
|
@@ -235,10 +318,12 @@ def create_gradio_interface():
|
|
| 235 |
special_effects_dropdown: gr.update(visible=(bg_type == "특수효과"))
|
| 236 |
}
|
| 237 |
|
|
|
|
| 238 |
background_type.change(
|
| 239 |
fn=update_dropdowns,
|
| 240 |
inputs=[background_type],
|
| 241 |
-
outputs=[simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, special_dropdown, jewelry_dropdown, special_effects_dropdown]
|
|
|
|
| 242 |
)
|
| 243 |
|
| 244 |
# 요청사항 입력
|
|
@@ -383,77 +468,4 @@ if __name__ == "__main__":
|
|
| 383 |
app.launch(share=True)
|
| 384 |
except Exception as e:
|
| 385 |
logger.error(f"Error running app: {e}")
|
| 386 |
-
logger.error(traceback.format_exc())
|
| 387 |
-
|
| 388 |
-
try:
|
| 389 |
-
# 환경변수에서 가져온 코드 실행하여 딕셔너리들 추출
|
| 390 |
-
local_vars = {}
|
| 391 |
-
exec(backgrounds_code, {}, local_vars)
|
| 392 |
-
|
| 393 |
-
return (
|
| 394 |
-
local_vars.get("SIMPLE_BACKGROUNDS", {}),
|
| 395 |
-
local_vars.get("STUDIO_BACKGROUNDS", {}),
|
| 396 |
-
local_vars.get("NATURE_BACKGROUNDS", {}),
|
| 397 |
-
local_vars.get("INDOOR_BACKGROUNDS", {}),
|
| 398 |
-
local_vars.get("SPECIAL_BACKGROUNDS", {}),
|
| 399 |
-
local_vars.get("JEWELRY_BACKGROUNDS", {}),
|
| 400 |
-
local_vars.get("SPECIAL_EFFECTS_BACKGROUNDS", {})
|
| 401 |
-
)
|
| 402 |
-
except Exception as e:
|
| 403 |
-
logger.error(f"Failed to parse BACKGROUNDS_DATA: {e}")
|
| 404 |
-
return {}, {}, {}, {}, {}, {}, {}
|
| 405 |
-
|
| 406 |
-
# 환경변수에서 배경 딕셔너리들 로드
|
| 407 |
-
(SIMPLE_BACKGROUNDS, STUDIO_BACKGROUNDS, NATURE_BACKGROUNDS,
|
| 408 |
-
INDOOR_BACKGROUNDS, SPECIAL_BACKGROUNDS, JEWELRY_BACKGROUNDS,
|
| 409 |
-
SPECIAL_EFFECTS_BACKGROUNDS) = load_backgrounds_from_env()
|
| 410 |
-
|
| 411 |
-
# 만약 환경변수가 비어있다면 기본값 사용
|
| 412 |
-
if not SIMPLE_BACKGROUNDS:
|
| 413 |
-
SIMPLE_BACKGROUNDS = {
|
| 414 |
-
"화이트 기본": "clean white background with soft lighting",
|
| 415 |
-
"회색 투톤": "light gray background with minimal shadows",
|
| 416 |
-
"라이트 그레이": "soft light gray backdrop with even illumination"
|
| 417 |
-
}
|
| 418 |
-
|
| 419 |
-
if not STUDIO_BACKGROUNDS:
|
| 420 |
-
STUDIO_BACKGROUNDS = {
|
| 421 |
-
"연녹색 장미 정원": "soft green background with rose garden elements",
|
| 422 |
-
"연분홍 장미 대리석": "pink rose with marble surface backdrop"
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
if not NATURE_BACKGROUNDS:
|
| 426 |
-
NATURE_BACKGROUNDS = {
|
| 427 |
-
"작은 파도가 있는 해변": "serene beach with gentle waves",
|
| 428 |
-
"열대해변": "tropical beach setting with palm trees"
|
| 429 |
-
}
|
| 430 |
-
|
| 431 |
-
if not INDOOR_BACKGROUNDS:
|
| 432 |
-
INDOOR_BACKGROUNDS = {
|
| 433 |
-
"기본 책상": "clean modern desk setup",
|
| 434 |
-
"빛이 비치는 거실": "bright living room with natural light"
|
| 435 |
-
}
|
| 436 |
-
|
| 437 |
-
if not SPECIAL_BACKGROUNDS:
|
| 438 |
-
SPECIAL_BACKGROUNDS = {
|
| 439 |
-
"네이비 빈티지 플로럴 벽지": "navy vintage floral wallpaper background"
|
| 440 |
-
}
|
| 441 |
-
|
| 442 |
-
if not JEWELRY_BACKGROUNDS:
|
| 443 |
-
JEWELRY_BACKGROUNDS = {
|
| 444 |
-
"화이트 미러 스팟 라이트": "white mirror surface with spotlight"
|
| 445 |
-
}
|
| 446 |
-
|
| 447 |
-
if not SPECIAL_EFFECTS_BACKGROUNDS:
|
| 448 |
-
SPECIAL_EFFECTS_BACKGROUNDS = {
|
| 449 |
-
"블루블랙 큰 물방울 효과": "blue-black background with water droplet effects"
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
# 임시 파일 저장 함수
|
| 453 |
-
def save_uploaded_file(uploaded_file, suffix='.png'):
|
| 454 |
-
try:
|
| 455 |
-
logger.info(f"Processing uploaded file: {type(uploaded_file)}")
|
| 456 |
-
|
| 457 |
-
if uploaded_file is None:
|
| 458 |
-
logger.warning("Uploaded file is None")
|
| 459 |
-
return
|
|
|
|
| 45 |
backgrounds_code = os.environ.get("BACKGROUNDS_DATA", "")
|
| 46 |
if not backgrounds_code:
|
| 47 |
logger.warning("BACKGROUNDS_DATA environment variable is empty")
|
| 48 |
+
return {}, {}, {}, {}, {}, {}, {}
|
| 49 |
+
|
| 50 |
+
try:
|
| 51 |
+
# 환경변수에서 가져온 코드 실행하여 딕셔너리들 추출
|
| 52 |
+
local_vars = {}
|
| 53 |
+
exec(backgrounds_code, {}, local_vars)
|
| 54 |
+
|
| 55 |
+
return (
|
| 56 |
+
local_vars.get("SIMPLE_BACKGROUNDS", {}),
|
| 57 |
+
local_vars.get("STUDIO_BACKGROUNDS", {}),
|
| 58 |
+
local_vars.get("NATURE_BACKGROUNDS", {}),
|
| 59 |
+
local_vars.get("INDOOR_BACKGROUNDS", {}),
|
| 60 |
+
local_vars.get("SPECIAL_BACKGROUNDS", {}),
|
| 61 |
+
local_vars.get("JEWELRY_BACKGROUNDS", {}),
|
| 62 |
+
local_vars.get("SPECIAL_EFFECTS_BACKGROUNDS", {})
|
| 63 |
+
)
|
| 64 |
+
except Exception as e:
|
| 65 |
+
logger.error(f"Failed to parse BACKGROUNDS_DATA: {e}")
|
| 66 |
+
return {}, {}, {}, {}, {}, {}, {}
|
| 67 |
+
|
| 68 |
+
# 환경변수에서 배경 딕셔너리들 로드
|
| 69 |
+
(SIMPLE_BACKGROUNDS, STUDIO_BACKGROUNDS, NATURE_BACKGROUNDS,
|
| 70 |
+
INDOOR_BACKGROUNDS, SPECIAL_BACKGROUNDS, JEWELRY_BACKGROUNDS,
|
| 71 |
+
SPECIAL_EFFECTS_BACKGROUNDS) = load_backgrounds_from_env()
|
| 72 |
+
|
| 73 |
+
# 만약 환경변수가 비어있다면 기본값 사용
|
| 74 |
+
if not SIMPLE_BACKGROUNDS:
|
| 75 |
+
SIMPLE_BACKGROUNDS = {
|
| 76 |
+
"화이트 기본": "clean white background with soft lighting",
|
| 77 |
+
"회색 투톤": "light gray background with minimal shadows",
|
| 78 |
+
"라이트 그레이": "soft light gray backdrop with even illumination"
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if not STUDIO_BACKGROUNDS:
|
| 82 |
+
STUDIO_BACKGROUNDS = {
|
| 83 |
+
"연녹색 장미 정원": "soft green background with rose garden elements",
|
| 84 |
+
"연분홍 장미 대리석": "pink rose with marble surface backdrop"
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if not NATURE_BACKGROUNDS:
|
| 88 |
+
NATURE_BACKGROUNDS = {
|
| 89 |
+
"작은 파도가 있는 해변": "serene beach with gentle waves",
|
| 90 |
+
"열대해변": "tropical beach setting with palm trees"
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if not INDOOR_BACKGROUNDS:
|
| 94 |
+
INDOOR_BACKGROUNDS = {
|
| 95 |
+
"기본 책상": "clean modern desk setup",
|
| 96 |
+
"빛이 비치는 거실": "bright living room with natural light"
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if not SPECIAL_BACKGROUNDS:
|
| 100 |
+
SPECIAL_BACKGROUNDS = {
|
| 101 |
+
"네이비 빈티지 플로럴 벽지": "navy vintage floral wallpaper background"
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
if not JEWELRY_BACKGROUNDS:
|
| 105 |
+
JEWELRY_BACKGROUNDS = {
|
| 106 |
+
"화이트 미러 스팟 라이트": "white mirror surface with spotlight"
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
if not SPECIAL_EFFECTS_BACKGROUNDS:
|
| 110 |
+
SPECIAL_EFFECTS_BACKGROUNDS = {
|
| 111 |
+
"블루블랙 큰 물방울 효과": "blue-black background with water droplet effects"
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
# 임시 파일 저장 함수
|
| 115 |
+
def save_uploaded_file(uploaded_file, suffix='.png'):
|
| 116 |
+
try:
|
| 117 |
+
logger.info(f"Processing uploaded file: {type(uploaded_file)}")
|
| 118 |
+
|
| 119 |
+
if uploaded_file is None:
|
| 120 |
+
logger.warning("Uploaded file is None")
|
| 121 |
+
return None
|
| 122 |
|
| 123 |
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
|
| 124 |
temp_filename = temp_file.name
|
|
|
|
| 209 |
return result
|
| 210 |
except Exception as e:
|
| 211 |
logger.error(f"Error calling check_password API: {e}")
|
| 212 |
+
return [], None, [], None, "", "", f"API 호출 오류: {str(e)}"
|
| 213 |
|
| 214 |
# Gradio 인터페이스 구성 (완전히 동일한 UI)
|
| 215 |
def create_gradio_interface():
|
|
|
|
| 297 |
interactive=True
|
| 298 |
)
|
| 299 |
|
| 300 |
+
# 드롭다운 변경 함수 (원본과 동일한 엔드포인트)
|
| 301 |
def update_dropdowns(bg_type):
|
| 302 |
+
# API 호출하여 원본 동작 유지
|
| 303 |
+
try:
|
| 304 |
+
result = api_update_dropdowns(bg_type)
|
| 305 |
+
if result:
|
| 306 |
+
return result
|
| 307 |
+
except:
|
| 308 |
+
pass
|
| 309 |
+
|
| 310 |
+
# 백업용 로컬 로직
|
| 311 |
return {
|
| 312 |
simple_dropdown: gr.update(visible=(bg_type == "심플 배경")),
|
| 313 |
studio_dropdown: gr.update(visible=(bg_type == "스튜디오 배경")),
|
|
|
|
| 318 |
special_effects_dropdown: gr.update(visible=(bg_type == "특수효과"))
|
| 319 |
}
|
| 320 |
|
| 321 |
+
# 원본과 동일한 엔드포인트 생성
|
| 322 |
background_type.change(
|
| 323 |
fn=update_dropdowns,
|
| 324 |
inputs=[background_type],
|
| 325 |
+
outputs=[simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, special_dropdown, jewelry_dropdown, special_effects_dropdown],
|
| 326 |
+
api_name="update_dropdowns" # 원본과 동일한 API 이름
|
| 327 |
)
|
| 328 |
|
| 329 |
# 요청사항 입력
|
|
|
|
| 468 |
app.launch(share=True)
|
| 469 |
except Exception as e:
|
| 470 |
logger.error(f"Error running app: {e}")
|
| 471 |
+
logger.error(traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|