ssboost commited on
Commit
5344ed9
ยท
verified ยท
1 Parent(s): f34d9b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -236
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import sys
2
  import base64
3
  import io
@@ -5,7 +6,6 @@ import logging
5
  import tempfile
6
  import traceback
7
  import requests
8
- import json
9
  from PIL import Image
10
  import gradio as gr
11
  from openai import OpenAI
@@ -40,147 +40,26 @@ else:
40
  logger.warning("GEMINI_API_KEY not found or empty, Gemini client not initialized")
41
  gemini_client = None
42
 
43
- # ์„ค์ •๊ฐ’๋“ค์„ ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋กœ๋“œํ•˜๋Š” ํ•จ์ˆ˜๋“ค
44
- def get_app_password():
45
- """ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค."""
46
- password = os.environ.get("APP_PASSWORD")
47
- if password:
48
- logger.info("App password loaded from environment variable")
49
- return password
50
- else:
51
- logger.warning("APP_PASSWORD environment variable not found, using default password")
52
- return "1089" # ๊ธฐ๋ณธ ๋น„๋ฐ€๋ฒˆํ˜ธ
53
-
54
- # ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ๋ฅผ ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋กœ๋“œํ•˜๋Š” ํ•จ์ˆ˜
55
- def load_backgrounds_from_env():
56
- """ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค."""
57
- try:
58
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ JSON ๋ฌธ์ž์—ด๋กœ ์ €์žฅ๋œ ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ๋กœ๋“œ
59
- backgrounds_data = os.environ.get("BACKGROUNDS_DATA")
60
- if backgrounds_data:
61
- logger.info("Loading backgrounds data from environment variable")
62
- return json.loads(backgrounds_data)
63
- else:
64
- logger.warning("BACKGROUNDS_DATA environment variable not found, using default backgrounds")
65
- return get_default_backgrounds()
66
- except Exception as e:
67
- logger.error(f"Error loading backgrounds from environment: {e}")
68
- logger.info("Falling back to default backgrounds")
69
- return get_default_backgrounds()
70
-
71
- def get_default_backgrounds():
72
- """๊ธฐ๋ณธ ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค."""
73
- return {
74
- "SIMPLE_BACKGROUNDS": {
75
- "ํ™”์ดํŠธ ๊ธฐ๋ณธ": "A clean, minimalistic digital background scene featuring a seamless pure white backdrop and a smooth white surface. The lighting is bright and evenly diffused from above, eliminating harsh shadows and creating a crisp, studio-lit environment. There are no products or objects present โ€” only the empty background remains. The composition is ultra-clean and modern, ideal for overlaying lifestyle or hydration-related products. The mood is fresh, light, and professional. Ultra-sharp, studio-quality, high resolution, photo-realistic",
76
- "ํšŒ์ƒ‰ ํˆฌํ†ค": "A clean and minimal product photography background featuring a seamless, near-white light gray tone across both the backdrop and surface. The entire scene is evenly lit with bright, diffused lighting from above, eliminating harsh shadows and producing a calm, sophisticated atmosphere. The composition remains empty โ€” with no products or objects present โ€” offering a soft and airy visual ideal for modern lifestyle, wellness, or eco-friendly branding. The lighting gently enhances spatial depth without creating reflections. Ultra-clear, studio-quality, photo-realistic"
77
- },
78
- "STUDIO_BACKGROUNDS": {
79
- "์—ฐ๋…น์ƒ‰ ์žฅ๋ฏธ ์ •์›": "A high-resolution, commercial-style digital photograph of a sophisticated background setup designed for a luxury product shoot. The scene features soft green tones with lush fern leaves and creamy pastel roses (white, peach, blush pink) artfully arranged. The flowers are placed on a white polished marble platform with soft veining, surrounded by elegant foliage. The lighting is natural and diffused from the top left, producing soft shadows and a serene mood. There is no product in the scene โ€” only the floral arrangement and surface remain, creating a refined, editorial-quality backdrop suitable for overlaying product photography. No object should be centered; the composition should remain balanced and inviting. ultra-detailed, 8K quality, photo-realistic studio setting."
80
- },
81
- "NATURE_BACKGROUNDS": {
82
- "์ž‘์€ ํŒŒ๋„๊ฐ€ ์žˆ๋Š” ํ•ด๋ณ€": "A serene and natural beach-themed product photography scene. The background features warm golden sand and gentle turquoise waves softly rolling onto the shore, with white foam catching the golden light of a late afternoon sun. Around the edges of the frame โ€” but not overlapping the center foreground โ€” small natural elements like seashells, conch shells, and bits of coral are randomly scattered with varied sizes, positions, and quantities to evoke a natural, organic arrangement. The product area remains clean and visually unobstructed to maintain focus. Lighting is soft and ambient with subtle natural shadows to highlight the uploaded product. The overall atmosphere is peaceful, sunlit, and summer-inspired. Ultra photo-realistic, studio-quality"
83
- },
84
- "INDOOR_BACKGROUNDS": {
85
- "๊ธฐ๋ณธ ์ฑ…์ƒ": "A bright, Scandinavian-inspired home office featuring a matte white desk with crisp edges placed against a soft sage green wall. Natural daylight gently enters from the side, casting diffused shadows across the surface and enhancing the calm, focused atmosphere. On the desk are neatly arranged everyday essentials like a few colorful pens, a potted plant, and an open notebook. A neutral-toned ergonomic chair is tucked under the desk, and the surrounding area is intentionally minimal to emphasize clarity and productivity. The entire setting evokes a modern, clutter-free work environment., photo-realistic, high-resolution."
86
- },
87
- "SPECIAL_BACKGROUNDS": {
88
- "๋„ค์ด๋น„ ๋นˆํ‹ฐ์ง€ ํ”Œ๋กœ๋Ÿด ๋ฒฝ์ง€": "A richly detailed studio photography background featuring an ornate, vintage-inspired floral wallpaper design. The backdrop showcases vibrant red, pink, yellow, and green botanical motifs intricately woven across a deep navy blue base. The floral pattern is symmetrical and bold, giving the composition an artistic, maximalist aesthetic. The floor is a clean, solid blue surface, providing visual contrast and modern balance. Lighting is bright and evenly diffused, emphasizing both the product and the intricate details of the wallpaper. Ideal for showcasing creative, lifestyle, or design-forward products. Ultra-detailed, high-resolution, ."
89
- },
90
- "JEWELRY_BACKGROUNDS": {
91
- "ํ™”์ดํŠธ ๋ฏธ๋Ÿฌ ์ŠคํŒŸ ๋ผ์ดํŠธ": "A luxury jewelry product photoshoot featuring a soft white backdrop and a polished white mirrored surface. A single focused overhead light beam softly illuminates the center of the scene, fading smoothly toward the edges with a clean gradient. The glossy white surface reflects the jewelry item with crystal clarity โ€” capturing the shape, facets, and symmetry of the design in perfect mirror-like detail. The reflection appears sharp, clean, and vertically aligned beneath the product, enhancing the sense of luxury and balance. The atmosphere is premium, minimal, and luminous โ€” ideal for high-end diamond earrings or bridal jewelry. Ultra-detailed, studio-quality, photo-realistic"
92
- },
93
- "SPECIAL_EFFECTS_BACKGROUNDS": {
94
- "๋ธ”๋ฃจ๋ธ”๋ž™ ํฐ ๋ฌผ๋ฐฉ์šธ ํšจ๊ณผ": "A deep black and vivid cobalt blue gradient backdrop with a reflective surface splashed by crystalline water droplets frozen mid-air. Backlighting enhances shimmer and motion, creating a sense of waterproof resilience. High-impact, ultra-detailed."
95
- }
96
- }
97
 
98
- # ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ๋กœ๋“œ
99
- backgrounds_data = load_backgrounds_from_env()
100
- SIMPLE_BACKGROUNDS = backgrounds_data.get("SIMPLE_BACKGROUNDS", {})
101
- STUDIO_BACKGROUNDS = backgrounds_data.get("STUDIO_BACKGROUNDS", {})
102
- NATURE_BACKGROUNDS = backgrounds_data.get("NATURE_BACKGROUNDS", {})
103
- INDOOR_BACKGROUNDS = backgrounds_data.get("INDOOR_BACKGROUNDS", {})
104
- SPECIAL_BACKGROUNDS = backgrounds_data.get("SPECIAL_BACKGROUNDS", {})
105
- JEWELRY_BACKGROUNDS = backgrounds_data.get("JEWELRY_BACKGROUNDS", {})
106
- SPECIAL_EFFECTS_BACKGROUNDS = backgrounds_data.get("SPECIAL_EFFECTS_BACKGROUNDS", {})
107
 
108
- # ์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋กœ๋“œ
109
- APP_PASSWORD = get_app_password()
110
-
111
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ฒ€์ฆ ํ•จ์ˆ˜
112
- def validate_environment_variables():
113
- """ํ•„์ˆ˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค."""
114
- logger.info("=== ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ฒ€์ฆ ์‹œ์ž‘ ===")
115
-
116
- # ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ฒ€์ฆ
117
- logger.info(f"APP_PASSWORD: {'์„ค์ •๋จ' if os.environ.get('APP_PASSWORD') else '๊ธฐ๋ณธ๊ฐ’ ์‚ฌ์šฉ (1089)'}")
118
-
119
- # API ํ‚ค ๊ฒ€์ฆ
120
- openai_key = os.environ.get("OPENAI_API_KEY")
121
- replicate_token = os.environ.get("REPLICATE_API_TOKEN")
122
- gemini_key = os.environ.get("GEMINI_API_KEY")
123
-
124
- logger.info(f"OPENAI_API_KEY: {'์„ค์ •๋จ' if openai_key else '์„ค์ •๋˜์ง€ ์•Š์Œ'}")
125
- logger.info(f"REPLICATE_API_TOKEN: {'์„ค์ •๋จ' if replicate_token else '์„ค์ •๋˜์ง€ ์•Š์Œ'}")
126
- logger.info(f"GEMINI_API_KEY: {'์„ค์ •๋จ' if gemini_key else '์„ค์ •๋˜์ง€ ์•Š์Œ'}")
127
-
128
- # ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ๊ฒ€์ฆ
129
- backgrounds_data_env = os.environ.get("BACKGROUNDS_DATA")
130
- if backgrounds_data_env:
131
- logger.info("BACKGROUNDS_DATA: ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ์„ค์ •๋จ")
132
- try:
133
- parsed_data = json.loads(backgrounds_data_env)
134
- bg_counts = {
135
- category: len(backgrounds)
136
- for category, backgrounds in parsed_data.items()
137
- }
138
- logger.info(f"๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์„ฑ๊ณต: {bg_counts}")
139
-
140
- # ๊ฐ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์ƒ์„ธ ์ •๋ณด
141
- for category, backgrounds in parsed_data.items():
142
- if backgrounds:
143
- sample_keys = list(backgrounds.keys())[:3] # ์ฒ˜์Œ 3๊ฐœ๋งŒ ํ‘œ์‹œ
144
- logger.info(f" {category}: {len(backgrounds)}๊ฐœ - ์˜ˆ์‹œ: {sample_keys}")
145
- else:
146
- logger.warning(f" {category}: ๋น„์–ด์žˆ์Œ")
147
-
148
- except Exception as e:
149
- logger.error(f"BACKGROUNDS_DATA JSON ํŒŒ์‹ฑ ์˜ค๋ฅ˜: {e}")
150
- logger.error("๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅธ์ง€ ํ™•์ธํ•ด์ฃผ์„ธ์š”.")
151
- else:
152
- logger.info("BACKGROUNDS_DATA: ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์—†์Œ (๊ธฐ๋ณธ๊ฐ’ ์‚ฌ์šฉ)")
153
-
154
- # ์‹ค์ œ ๋กœ๋“œ๋œ ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ํ™•์ธ
155
- actual_bg_counts = {
156
- "SIMPLE_BACKGROUNDS": len(SIMPLE_BACKGROUNDS),
157
- "STUDIO_BACKGROUNDS": len(STUDIO_BACKGROUNDS),
158
- "NATURE_BACKGROUNDS": len(NATURE_BACKGROUNDS),
159
- "INDOOR_BACKGROUNDS": len(INDOOR_BACKGROUNDS),
160
- "SPECIAL_BACKGROUNDS": len(SPECIAL_BACKGROUNDS),
161
- "JEWELRY_BACKGROUNDS": len(JEWELRY_BACKGROUNDS),
162
- "SPECIAL_EFFECTS_BACKGROUNDS": len(SPECIAL_EFFECTS_BACKGROUNDS)
163
- }
164
- logger.info(f"์‹ค์ œ ๋กœ๋“œ๋œ ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ: {actual_bg_counts}")
165
-
166
- # ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€
167
- missing_apis = []
168
- if not openai_key:
169
- missing_apis.append("OpenAI (GPT ๋ชจ๋ธ ์‚ฌ์šฉ ๋ถˆ๊ฐ€)")
170
- if not replicate_token:
171
- missing_apis.append("Replicate (Flux ๋ชจ๋ธ ๋ฐ ํ™”์งˆ๊ฐœ์„  ์‚ฌ์šฉ ๋ถˆ๊ฐ€)")
172
- if not gemini_key:
173
- missing_apis.append("Gemini (๋ฒˆ์—ญ ๊ธฐ๋Šฅ ์‚ฌ์šฉ ๋ถˆ๊ฐ€)")
174
-
175
- if missing_apis:
176
- logger.warning(f"๋ˆ„๋ฝ๋œ API ํ‚ค๋กœ ์ธํ•ด ๋‹ค์Œ ๊ธฐ๋Šฅ์ด ์ œํ•œ๋ฉ๋‹ˆ๋‹ค: {', '.join(missing_apis)}")
177
- else:
178
- logger.info("๋ชจ๋“  API ํ‚ค๊ฐ€ ์„ค์ •๋˜์–ด ์ „์ฒด ๊ธฐ๋Šฅ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.")
179
-
180
- logger.info("=== ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ฒ€์ฆ ์™„๋ฃŒ ===")
181
 
182
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ฒ€์ฆ ์‹คํ–‰
183
- validate_environment_variables()
 
 
 
 
 
184
 
185
  # ์ž„์‹œ ํŒŒ์ผ ์ €์žฅ ํ•จ์ˆ˜
186
  def save_uploaded_file(uploaded_file, suffix='.png'):
@@ -652,70 +531,58 @@ def create_gradio_interface():
652
  value="์‹ฌํ”Œ ๋ฐฐ๊ฒฝ"
653
  )
654
 
655
- # ๋“œ๋กญ๋‹ค์šด ์ปดํฌ๋„ŒํŠธ๋“ค - ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋กœ๋“œ๋œ ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ
656
- simple_choices = list(SIMPLE_BACKGROUNDS.keys()) if SIMPLE_BACKGROUNDS else []
657
- studio_choices = list(STUDIO_BACKGROUNDS.keys()) if STUDIO_BACKGROUNDS else []
658
- nature_choices = list(NATURE_BACKGROUNDS.keys()) if NATURE_BACKGROUNDS else []
659
- indoor_choices = list(INDOOR_BACKGROUNDS.keys()) if INDOOR_BACKGROUNDS else []
660
- special_choices = list(SPECIAL_BACKGROUNDS.keys()) if SPECIAL_BACKGROUNDS else []
661
- jewelry_choices = list(JEWELRY_BACKGROUNDS.keys()) if JEWELRY_BACKGROUNDS else []
662
- special_effects_choices = list(SPECIAL_EFFECTS_BACKGROUNDS.keys()) if SPECIAL_EFFECTS_BACKGROUNDS else []
663
-
664
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์—†์–ด์„œ ๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ๊ฐ€ ๋น„์–ด์žˆ๋Š” ๊ฒฝ์šฐ ๊ฒฝ๊ณ 
665
- if not any([simple_choices, studio_choices, nature_choices, indoor_choices, special_choices, jewelry_choices, special_effects_choices]):
666
- logger.error("๋ชจ๋“  ๋ฐฐ๊ฒฝ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค. BACKGROUNDS_DATA ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.")
667
-
668
  simple_dropdown = gr.Dropdown(
669
- choices=simple_choices,
670
- value=simple_choices[0] if simple_choices else None,
671
  label="์‹ฌํ”Œ ๋ฐฐ๊ฒฝ ์„ ํƒ",
672
  visible=True,
673
  interactive=True
674
  )
675
 
676
  studio_dropdown = gr.Dropdown(
677
- choices=studio_choices,
678
- value=studio_choices[0] if studio_choices else None,
679
  label="์ŠคํŠœ๋””์˜ค ๋ฐฐ๊ฒฝ ์„ ํƒ",
680
  visible=False,
681
  interactive=True
682
  )
683
 
684
  nature_dropdown = gr.Dropdown(
685
- choices=nature_choices,
686
- value=nature_choices[0] if nature_choices else None,
687
  label="์ž์—ฐ ํ™˜๊ฒฝ ์„ ํƒ",
688
  visible=False,
689
  interactive=True
690
  )
691
 
692
  indoor_dropdown = gr.Dropdown(
693
- choices=indoor_choices,
694
- value=indoor_choices[0] if indoor_choices else None,
695
  label="์‹ค๋‚ด ํ™˜๊ฒฝ ์„ ํƒ",
696
  visible=False,
697
  interactive=True
698
  )
699
 
700
  special_dropdown = gr.Dropdown(
701
- choices=special_choices,
702
- value=special_choices[0] if special_choices else None,
703
  label="ํŠน์ˆ˜๋ฐฐ๊ฒฝ ์„ ํƒ",
704
  visible=False,
705
  interactive=True
706
  )
707
 
708
  jewelry_dropdown = gr.Dropdown(
709
- choices=jewelry_choices,
710
- value=jewelry_choices[0] if jewelry_choices else None,
711
  label="์ฃผ์–ผ๋ฆฌ ๋ฐฐ๊ฒฝ ์„ ํƒ",
712
  visible=False,
713
  interactive=True
714
  )
715
 
716
  special_effects_dropdown = gr.Dropdown(
717
- choices=special_effects_choices,
718
- value=special_effects_choices[0] if special_effects_choices else None,
719
  label="ํŠน์ˆ˜ํšจ๊ณผ ๋ฐฐ๊ฒฝ ์„ ํƒ",
720
  visible=False,
721
  interactive=True
@@ -723,58 +590,14 @@ def create_gradio_interface():
723
 
724
  # ๋“œ๋กญ๋‹ค์šด ๋ณ€๊ฒฝ ํ•จ์ˆ˜
725
  def update_dropdowns(bg_type):
726
- """๋ฐฐ๊ฒฝ ์œ ํ˜•์— ๋”ฐ๋ผ ๋“œ๋กญ๋‹ค์šด์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค."""
727
- logger.info(f"Updating dropdowns for background type: {bg_type}")
728
-
729
- # ๊ฐ ๋ฐฐ๊ฒฝ ์นดํ…Œ๊ณ ๋ฆฌ์˜ ํ‚ค ๋ชฉ๋ก ๊ฐ€์ ธ์˜ค๊ธฐ
730
- simple_choices = list(SIMPLE_BACKGROUNDS.keys()) if SIMPLE_BACKGROUNDS else []
731
- studio_choices = list(STUDIO_BACKGROUNDS.keys()) if STUDIO_BACKGROUNDS else []
732
- nature_choices = list(NATURE_BACKGROUNDS.keys()) if NATURE_BACKGROUNDS else []
733
- indoor_choices = list(INDOOR_BACKGROUNDS.keys()) if INDOOR_BACKGROUNDS else []
734
- special_choices = list(SPECIAL_BACKGROUNDS.keys()) if SPECIAL_BACKGROUNDS else []
735
- jewelry_choices = list(JEWELRY_BACKGROUNDS.keys()) if JEWELRY_BACKGROUNDS else []
736
- special_effects_choices = list(SPECIAL_EFFECTS_BACKGROUNDS.keys()) if SPECIAL_EFFECTS_BACKGROUNDS else []
737
-
738
- # ๋””๋ฒ„๊น… ์ •๋ณด ๋กœ๊น…
739
- logger.info(f"Available choices - Simple: {len(simple_choices)}, Studio: {len(studio_choices)}, Nature: {len(nature_choices)}")
740
- logger.info(f"Indoor: {len(indoor_choices)}, Special: {len(special_choices)}, Jewelry: {len(jewelry_choices)}, Effects: {len(special_effects_choices)}")
741
-
742
  return {
743
- simple_dropdown: gr.update(
744
- visible=(bg_type == "์‹ฌํ”Œ ๋ฐฐ๊ฒฝ"),
745
- choices=simple_choices,
746
- value=simple_choices[0] if simple_choices else None
747
- ),
748
- studio_dropdown: gr.update(
749
- visible=(bg_type == "์ŠคํŠœ๋””์˜ค ๋ฐฐ๊ฒฝ"),
750
- choices=studio_choices,
751
- value=studio_choices[0] if studio_choices else None
752
- ),
753
- nature_dropdown: gr.update(
754
- visible=(bg_type == "์ž์—ฐ ํ™˜๊ฒฝ"),
755
- choices=nature_choices,
756
- value=nature_choices[0] if nature_choices else None
757
- ),
758
- indoor_dropdown: gr.update(
759
- visible=(bg_type == "์‹ค๋‚ด ํ™˜๊ฒฝ"),
760
- choices=indoor_choices,
761
- value=indoor_choices[0] if indoor_choices else None
762
- ),
763
- special_dropdown: gr.update(
764
- visible=(bg_type == "ํŠน์ˆ˜๋ฐฐ๊ฒฝ"),
765
- choices=special_choices,
766
- value=special_choices[0] if special_choices else None
767
- ),
768
- jewelry_dropdown: gr.update(
769
- visible=(bg_type == "์ฃผ์–ผ๋ฆฌ"),
770
- choices=jewelry_choices,
771
- value=jewelry_choices[0] if jewelry_choices else None
772
- ),
773
- special_effects_dropdown: gr.update(
774
- visible=(bg_type == "ํŠน์ˆ˜ํšจ๊ณผ"),
775
- choices=special_effects_choices,
776
- value=special_effects_choices[0] if special_effects_choices else None
777
- )
778
  }
779
 
780
  background_type.change(
@@ -843,7 +666,7 @@ def create_gradio_interface():
843
 
844
  # ํ”„๋กฌํ”„ํŠธ๋งŒ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜ (๋น„๋ฐ€๋ฒˆํ˜ธ ์ฒดํฌ ํฌํ•จ)
845
  def generate_prompt_with_password_check(password, bg_type, simple, studio, nature, indoor, special, jewelry, special_effects, request_text, aspect_ratio):
846
- # ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ - ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๊ฐ€์ ธ์˜จ ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ๋น„๊ต
847
  if password != APP_PASSWORD:
848
  return "๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
849
 
@@ -994,30 +817,15 @@ def create_gradio_interface():
994
  # ์•ฑ ์‹คํ–‰
995
  if __name__ == "__main__":
996
  try:
997
- logger.info("=== AI ์ด๋ฏธ์ง€ ํŽธ์ง‘ ๋ฐ ํ™”์งˆ ๊ฐœ์„  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹œ์ž‘ ===")
998
 
999
  # imgs ๋””๋ ‰ํ† ๋ฆฌ ํ™•์ธ/์ƒ์„ฑ
1000
  os.makedirs("imgs", exist_ok=True)
1001
  logger.info("์ด๋ฏธ์ง€ ๋””๋ ‰ํ† ๋ฆฌ ์ค€๋น„ ์™„๋ฃŒ")
1002
 
1003
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์žฌ๊ฒ€์ฆ (์•ฑ ์‹œ์ž‘ ์‹œ)
1004
- logger.info("์•ฑ ์‹œ์ž‘ ์ „ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ตœ์ข… ํ™•์ธ")
1005
- if not APP_PASSWORD:
1006
- logger.warning("๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ๋น„๋ฐ€๋ฒˆํ˜ธ(1089)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.")
1007
-
1008
- if not any([
1009
- os.environ.get("OPENAI_API_KEY"),
1010
- os.environ.get("REPLICATE_API_TOKEN"),
1011
- os.environ.get("GEMINI_API_KEY")
1012
- ]):
1013
- logger.warning("API ํ‚ค๊ฐ€ ํ•˜๋‚˜๋„ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๊ธฐ๋Šฅ์ด ์ œํ•œ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
1014
-
1015
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ ๋ฐ ์‹คํ–‰
1016
  app = create_gradio_interface()
1017
- logger.info("Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ ์™„๋ฃŒ")
1018
- logger.info("์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค...")
1019
  app.launch(share=True)
1020
-
1021
  except Exception as e:
1022
- logger.error(f"์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
1023
  logger.error(traceback.format_exc())
 
1
+ import os
2
  import sys
3
  import base64
4
  import io
 
6
  import tempfile
7
  import traceback
8
  import requests
 
9
  from PIL import Image
10
  import gradio as gr
11
  from openai import OpenAI
 
40
  logger.warning("GEMINI_API_KEY not found or empty, Gemini client not initialized")
41
  gemini_client = None
42
 
43
+ # ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋ฐฐ๊ฒฝ ํ”„๋กฌํ”„ํŠธ ๋กœ๋“œ
44
+ BACKGROUNDS_DATA = os.environ.get("BACKGROUNDS_DATA", "")
45
+ # ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋กœ๋“œ
46
+ APP_PASSWORD = os.environ.get("APP_PASSWORD", "")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ if not BACKGROUNDS_DATA:
49
+ logger.error("BACKGROUNDS_DATA environment variable not found")
50
+ raise ValueError("BACKGROUNDS_DATA ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.")
 
 
 
 
 
 
51
 
52
+ if not APP_PASSWORD:
53
+ logger.error("APP_PASSWORD environment variable not found")
54
+ raise ValueError("APP_PASSWORD ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์ด์ฌ ์ฝ”๋“œ๋กœ ์‹คํ–‰ํ•˜์—ฌ ๋ฐฐ๊ฒฝ ๋”•์…”๋„ˆ๋ฆฌ๋“ค ์ƒ์„ฑ
57
+ try:
58
+ exec(BACKGROUNDS_DATA)
59
+ logger.info("Background data loaded from environment variable")
60
+ except Exception as e:
61
+ logger.error(f"Failed to load background data: {e}")
62
+ raise ValueError(f"๋ฐฐ๊ฒฝ ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ: {e}")
63
 
64
  # ์ž„์‹œ ํŒŒ์ผ ์ €์žฅ ํ•จ์ˆ˜
65
  def save_uploaded_file(uploaded_file, suffix='.png'):
 
531
  value="์‹ฌํ”Œ ๋ฐฐ๊ฒฝ"
532
  )
533
 
534
+ # ๋“œ๋กญ๋‹ค์šด ์ปดํฌ๋„ŒํŠธ๋“ค
 
 
 
 
 
 
 
 
 
 
 
 
535
  simple_dropdown = gr.Dropdown(
536
+ choices=list(SIMPLE_BACKGROUNDS.keys()),
537
+ value=list(SIMPLE_BACKGROUNDS.keys())[0] if SIMPLE_BACKGROUNDS else None,
538
  label="์‹ฌํ”Œ ๋ฐฐ๊ฒฝ ์„ ํƒ",
539
  visible=True,
540
  interactive=True
541
  )
542
 
543
  studio_dropdown = gr.Dropdown(
544
+ choices=list(STUDIO_BACKGROUNDS.keys()),
545
+ value=list(STUDIO_BACKGROUNDS.keys())[0] if STUDIO_BACKGROUNDS else None,
546
  label="์ŠคํŠœ๋””์˜ค ๋ฐฐ๊ฒฝ ์„ ํƒ",
547
  visible=False,
548
  interactive=True
549
  )
550
 
551
  nature_dropdown = gr.Dropdown(
552
+ choices=list(NATURE_BACKGROUNDS.keys()),
553
+ value=list(NATURE_BACKGROUNDS.keys())[0] if NATURE_BACKGROUNDS else None,
554
  label="์ž์—ฐ ํ™˜๊ฒฝ ์„ ํƒ",
555
  visible=False,
556
  interactive=True
557
  )
558
 
559
  indoor_dropdown = gr.Dropdown(
560
+ choices=list(INDOOR_BACKGROUNDS.keys()),
561
+ value=list(INDOOR_BACKGROUNDS.keys())[0] if INDOOR_BACKGROUNDS else None,
562
  label="์‹ค๋‚ด ํ™˜๊ฒฝ ์„ ํƒ",
563
  visible=False,
564
  interactive=True
565
  )
566
 
567
  special_dropdown = gr.Dropdown(
568
+ choices=list(SPECIAL_BACKGROUNDS.keys()),
569
+ value=list(SPECIAL_BACKGROUNDS.keys())[0] if SPECIAL_BACKGROUNDS else None,
570
  label="ํŠน์ˆ˜๋ฐฐ๊ฒฝ ์„ ํƒ",
571
  visible=False,
572
  interactive=True
573
  )
574
 
575
  jewelry_dropdown = gr.Dropdown(
576
+ choices=list(JEWELRY_BACKGROUNDS.keys()),
577
+ value=list(JEWELRY_BACKGROUNDS.keys())[0] if JEWELRY_BACKGROUNDS else None,
578
  label="์ฃผ์–ผ๋ฆฌ ๋ฐฐ๊ฒฝ ์„ ํƒ",
579
  visible=False,
580
  interactive=True
581
  )
582
 
583
  special_effects_dropdown = gr.Dropdown(
584
+ choices=list(SPECIAL_EFFECTS_BACKGROUNDS.keys()),
585
+ value=list(SPECIAL_EFFECTS_BACKGROUNDS.keys())[0] if SPECIAL_EFFECTS_BACKGROUNDS else None,
586
  label="ํŠน์ˆ˜ํšจ๊ณผ ๋ฐฐ๊ฒฝ ์„ ํƒ",
587
  visible=False,
588
  interactive=True
 
590
 
591
  # ๋“œ๋กญ๋‹ค์šด ๋ณ€๊ฒฝ ํ•จ์ˆ˜
592
  def update_dropdowns(bg_type):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  return {
594
+ simple_dropdown: gr.update(visible=(bg_type == "์‹ฌํ”Œ ๋ฐฐ๊ฒฝ")),
595
+ studio_dropdown: gr.update(visible=(bg_type == "์ŠคํŠœ๋””์˜ค ๋ฐฐ๊ฒฝ")),
596
+ nature_dropdown: gr.update(visible=(bg_type == "์ž์—ฐ ํ™˜๊ฒฝ")),
597
+ indoor_dropdown: gr.update(visible=(bg_type == "์‹ค๋‚ด ํ™˜๊ฒฝ")),
598
+ special_dropdown: gr.update(visible=(bg_type == "ํŠน์ˆ˜๋ฐฐ๊ฒฝ")),
599
+ jewelry_dropdown: gr.update(visible=(bg_type == "์ฃผ์–ผ๋ฆฌ")),
600
+ special_effects_dropdown: gr.update(visible=(bg_type == "ํŠน์ˆ˜ํšจ๊ณผ"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  }
602
 
603
  background_type.change(
 
666
 
667
  # ํ”„๋กฌํ”„ํŠธ๋งŒ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜ (๋น„๋ฐ€๋ฒˆํ˜ธ ์ฒดํฌ ํฌํ•จ)
668
  def generate_prompt_with_password_check(password, bg_type, simple, studio, nature, indoor, special, jewelry, special_effects, request_text, aspect_ratio):
669
+ # ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ
670
  if password != APP_PASSWORD:
671
  return "๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
672
 
 
817
  # ์•ฑ ์‹คํ–‰
818
  if __name__ == "__main__":
819
  try:
820
+ logger.info("Starting application")
821
 
822
  # imgs ๋””๋ ‰ํ† ๋ฆฌ ํ™•์ธ/์ƒ์„ฑ
823
  os.makedirs("imgs", exist_ok=True)
824
  logger.info("์ด๋ฏธ์ง€ ๋””๋ ‰ํ† ๋ฆฌ ์ค€๋น„ ์™„๋ฃŒ")
825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826
  app = create_gradio_interface()
827
+ logger.info("Launching Gradio app")
 
828
  app.launch(share=True)
 
829
  except Exception as e:
830
+ logger.error(f"Error running app: {e}")
831
  logger.error(traceback.format_exc())