Update app.py
Browse files
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 |
-
|
45 |
-
|
46 |
-
|
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 |
-
|
100 |
-
|
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
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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=
|
670 |
-
value=
|
671 |
label="์ฌํ ๋ฐฐ๊ฒฝ ์ ํ",
|
672 |
visible=True,
|
673 |
interactive=True
|
674 |
)
|
675 |
|
676 |
studio_dropdown = gr.Dropdown(
|
677 |
-
choices=
|
678 |
-
value=
|
679 |
label="์คํ๋์ค ๋ฐฐ๊ฒฝ ์ ํ",
|
680 |
visible=False,
|
681 |
interactive=True
|
682 |
)
|
683 |
|
684 |
nature_dropdown = gr.Dropdown(
|
685 |
-
choices=
|
686 |
-
value=
|
687 |
label="์์ฐ ํ๊ฒฝ ์ ํ",
|
688 |
visible=False,
|
689 |
interactive=True
|
690 |
)
|
691 |
|
692 |
indoor_dropdown = gr.Dropdown(
|
693 |
-
choices=
|
694 |
-
value=
|
695 |
label="์ค๋ด ํ๊ฒฝ ์ ํ",
|
696 |
visible=False,
|
697 |
interactive=True
|
698 |
)
|
699 |
|
700 |
special_dropdown = gr.Dropdown(
|
701 |
-
choices=
|
702 |
-
value=
|
703 |
label="ํน์๋ฐฐ๊ฒฝ ์ ํ",
|
704 |
visible=False,
|
705 |
interactive=True
|
706 |
)
|
707 |
|
708 |
jewelry_dropdown = gr.Dropdown(
|
709 |
-
choices=
|
710 |
-
value=
|
711 |
label="์ฃผ์ผ๋ฆฌ ๋ฐฐ๊ฒฝ ์ ํ",
|
712 |
visible=False,
|
713 |
interactive=True
|
714 |
)
|
715 |
|
716 |
special_effects_dropdown = gr.Dropdown(
|
717 |
-
choices=
|
718 |
-
value=
|
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 |
-
|
745 |
-
|
746 |
-
|
747 |
-
),
|
748 |
-
|
749 |
-
|
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("
|
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"
|
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())
|