Update app.py
Browse files
app.py
CHANGED
@@ -26,41 +26,40 @@ def preprocess_prompt(prompt, image1, image2, image3):
|
|
26 |
"""
|
27 |
ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๊ณ ๊ธฐ๋ฅ ๋ช
๋ น์ ํด์
|
28 |
"""
|
29 |
-
# ์ด๋ฏธ์ง
|
30 |
has_img1 = image1 is not None
|
31 |
has_img2 = image2 is not None
|
32 |
has_img3 = image3 is not None
|
33 |
|
34 |
# #1, #2, #3 ์ฐธ์กฐ๋ฅผ ์ค๋ช
์ผ๋ก ๋ณํ (์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฌด์)
|
35 |
-
if "#1" in prompt
|
36 |
-
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
37 |
-
|
38 |
-
prompt = prompt.replace("#
|
39 |
-
|
40 |
-
|
41 |
-
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
42 |
-
else:
|
43 |
-
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
44 |
-
|
45 |
-
if "#3" in prompt and not has_img3:
|
46 |
-
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
47 |
-
else:
|
48 |
-
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
49 |
|
50 |
# ๊ธฐ๋ฅ ๋ช
๋ น ํด์
|
51 |
if "1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ" in prompt:
|
52 |
-
#
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
|
55 |
elif "2. ๊ธ์์ง์ฐ๊ธฐ" in prompt:
|
56 |
-
#
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
|
59 |
elif "3. ์ผ๊ตด๋ฐ๊พธ๊ธฐ" in prompt:
|
60 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์ผ๊ตด์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ผ๊ตด๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํด์ฃผ์ธ์. ์ผ๊ตด์ ํ์ ๊ณผ ํน์ง์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ๋๋จธ์ง ๋ถ๋ถ์ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
61 |
|
62 |
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt:
|
63 |
-
# ์ฌ๋ฌ ์ด๋ฏธ์ง ์ฐธ์กฐ ์ฒ๋ฆฌ
|
64 |
if "#3" in prompt or "๋๋ #3" in prompt:
|
65 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ๋๋ ์ธ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ์ฐธ์กฐ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
66 |
else:
|
@@ -70,7 +69,6 @@ def preprocess_prompt(prompt, image1, image2, image3):
|
|
70 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
71 |
|
72 |
elif "6. ์ด๋ฏธ์ง ํฉ์ฑ(์ํํฌํจ)" in prompt:
|
73 |
-
# ์ฌ๋ฌ ์ด๋ฏธ์ง ์ฐธ์กฐ ์ฒ๋ฆฌ
|
74 |
if "#3" in prompt or "๋๋ #3" in prompt:
|
75 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ ๋ฒ์งธ, ์ธ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํด์ฃผ์ธ์. ๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ์ ๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํด์ฃผ์ธ์."
|
76 |
else:
|
@@ -79,151 +77,86 @@ def preprocess_prompt(prompt, image1, image2, image3):
|
|
79 |
elif "7. ์ด๋ฏธ์ง ํฉ์ฑ(์คํ์ผ์ ์ฉ)" in prompt:
|
80 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ด์ฉ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์คํ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด์ ๊ตฌ๋๋ ์ ์งํ๋, ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์ ์ ์คํ์ผ, ์์, ์ง๊ฐ์ ์ ์ฉํด์ฃผ์ธ์."
|
81 |
|
82 |
-
# ๊ฐ๋จํ ์์ ๋ณ๊ฒฝ ์์ฒญ ์ฒ๋ฆฌ
|
83 |
elif "์ ๋ถ์์์ผ๋ก ๋ฐ๊ฟ๋ผ" in prompt or "๋ฅผ ๋ถ์์์ผ๋ก ๋ฐ๊ฟ๋ผ" in prompt:
|
84 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ถ์์ ํค์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ ์ฒด์ ์ธ ์์์ ๋ถ์ ๊ณ์ด๋ก ์กฐ์ ํ๊ณ ์์ฐ์ค๋ฌ๏ฟฝ๏ฟฝ ๋๋์ ์ ์งํด์ฃผ์ธ์."
|
85 |
|
86 |
-
# ๋ช
ํํ ์ด๋ฏธ์ง ์์ฑ ์์ฒญ ์ถ๊ฐ
|
87 |
prompt += " ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์."
|
88 |
-
|
89 |
return prompt
|
90 |
|
91 |
-
def generate_with_images(prompt, images
|
92 |
"""
|
93 |
-
|
94 |
-
์คํจ ์ ์ฌ์๋ ๊ธฐ๋ฅ ์ถ๊ฐ
|
95 |
"""
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
try:
|
101 |
-
# API ํค ํ์ธ
|
102 |
-
api_key = os.environ.get("GEMINI_API_KEY")
|
103 |
-
if not api_key:
|
104 |
-
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
105 |
-
|
106 |
-
# Gemini ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
107 |
-
client = genai.Client(api_key=api_key)
|
108 |
-
|
109 |
-
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt} (์๋: {retries+1}/{max_retries+1})")
|
110 |
-
|
111 |
-
# ์ด๋ฏธ์ง ๋ฐ ํ
์คํธ ์ปจํ
์ธ ์ค๋น
|
112 |
-
parts = []
|
113 |
-
|
114 |
-
# ์ด๋ฏธ์ง ํํธ ์ถ๊ฐ
|
115 |
-
for idx, img in enumerate(images, 1):
|
116 |
-
if img is not None:
|
117 |
-
# ์ด๋ฏธ์ง๋ฅผ ๋ฐ์ดํธ๋ก ๋ณํ
|
118 |
-
buffered = BytesIO()
|
119 |
-
img.save(buffered, format="PNG")
|
120 |
-
image_bytes = buffered.getvalue()
|
121 |
-
|
122 |
-
# ์ด๋ฏธ์ง ํํธ ์์ฑ
|
123 |
-
parts.append({
|
124 |
-
'inlineData': {
|
125 |
-
'mimeType': 'image/png',
|
126 |
-
'data': base64.b64encode(image_bytes).decode('utf-8')
|
127 |
-
}
|
128 |
-
})
|
129 |
-
logger.info(f"์ด๋ฏธ์ง #{idx} ์ถ๊ฐ๋จ")
|
130 |
-
|
131 |
-
# ํ
์คํธ ํ๋กฌํํธ ์ถ๊ฐ
|
132 |
-
parts.append({
|
133 |
-
'text': prompt
|
134 |
-
})
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
response = model.generate_content(request)
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
temp_path = tmp.name
|
165 |
-
|
166 |
-
result_text = ""
|
167 |
-
image_found = False
|
168 |
-
|
169 |
-
# ์ด๋ฏธ์ง ๋ฐ์ดํฐ ํ์ธ ๋ฐ ์ ์ฅ
|
170 |
-
for part in response.parts:
|
171 |
-
if hasattr(part, 'mime_type') and part.mime_type.startswith('image/'):
|
172 |
-
# base64 ๋์ฝ๋ฉ ๋ฐ ์ ์ฅ
|
173 |
-
img_data = base64.b64decode(part.data)
|
174 |
-
with open(temp_path, 'wb') as f:
|
175 |
-
f.write(img_data)
|
176 |
-
image_found = True
|
177 |
-
logger.info("์๋ต์์ ์ด๋ฏธ์ง ์ถ์ถ ์ฑ๊ณต")
|
178 |
-
break
|
179 |
-
|
180 |
-
# ํ
์คํธ ์ถ์ถ (์ต์
)
|
181 |
-
if hasattr(response, 'text'):
|
182 |
-
result_text = response.text
|
183 |
-
|
184 |
-
if not image_found:
|
185 |
-
if retries < max_retries:
|
186 |
-
retries += 1
|
187 |
-
logger.warning(f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์ฌ์๋ ์ค... ({retries}/{max_retries})")
|
188 |
-
continue
|
189 |
-
return None, f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์๋ต ํ
์คํธ: {result_text}"
|
190 |
-
|
191 |
-
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ๋ฐํ
|
192 |
-
result_img = Image.open(temp_path)
|
193 |
-
if result_img.mode == "RGBA":
|
194 |
-
result_img = result_img.convert("RGB")
|
195 |
|
196 |
-
|
|
|
|
|
197 |
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
logger.info(f"์ฌ์๋ ์ค... ({retries}/{max_retries})")
|
204 |
-
continue
|
205 |
-
return None, f"์ค๋ฅ ๋ฐ์: {last_error}"
|
206 |
-
|
207 |
-
return None, f"์ต๋ ์ฌ์๋ ํ์ ์ด๊ณผ. ๋ง์ง๋ง ์ค๋ฅ: {last_error}"
|
208 |
-
|
209 |
|
210 |
def process_images_with_prompt(image1, image2, image3, prompt):
|
211 |
"""
|
212 |
-
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๋
|
213 |
-
|
|
|
214 |
"""
|
215 |
try:
|
216 |
-
# ์ด๋ฏธ์ง ๊ฐ์ ํ์ธ
|
217 |
images = [image1, image2, image3]
|
218 |
-
valid_images = [img for img in images if img is not None]
|
219 |
|
220 |
-
# ํ๋กฌํํธ
|
221 |
if not prompt or not prompt.strip():
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
prompt = "์๋ฆ๋ค์ด ํ๊ฒฝ ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์. ํธ๋ฅธ ํ๋, ์ด๋ก์ ์ธ๋, ๊ทธ๋ฆฌ๊ณ ๋ง์ ํธ์๊ฐ ์๋ ํํ๋ก์ด ์์ฐ ํ๊ฒฝ์ ๋ง๋ค์ด์ฃผ์ธ์."
|
226 |
-
logger.info("์ด๋ฏธ์ง์ ํ๋กฌํํธ ๋ชจ๋ ์์. ๊ธฐ๋ณธ ํ๋กฌํํธ ์์ฑ")
|
227 |
elif len(valid_images) == 1:
|
228 |
prompt = "์ด ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
229 |
logger.info("๋จ์ผ ์ด๋ฏธ์ง ํ๋กฌํํธ ์๋ ์์ฑ")
|
@@ -234,21 +167,30 @@ def process_images_with_prompt(image1, image2, image3, prompt):
|
|
234 |
prompt = "์ด ์ธ ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ํฉ์ฑํด์ฃผ์ธ์. ๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๋ ์์ฐ์ค๋ฝ๊ณ ์ผ๊ด๋ ํ๋์ ์ฅ๋ฉด์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
235 |
logger.info("์ธ ์ด๋ฏธ์ง ํฉ์ฑ ํ๋กฌํํธ ์๋ ์์ฑ")
|
236 |
else:
|
237 |
-
# ํ๋กฌํํธ ์ ์ฒ๋ฆฌ ๋ฐ ๊ธฐ๋ฅ ๋ช
๋ น ํด์
|
238 |
prompt = preprocess_prompt(prompt, image1, image2, image3)
|
239 |
|
240 |
-
#
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
except Exception as e:
|
244 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
245 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
246 |
|
247 |
-
# ๊ธฐ๋ฅ ์ ํ ์ฝ๋ฐฑ
|
248 |
def update_prompt_from_function(function_choice):
|
|
|
|
|
|
|
|
|
249 |
function_templates = {
|
250 |
-
"1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ":
|
251 |
-
"2. ๊ธ์์ง์ฐ๊ธฐ":
|
252 |
"3. ์ผ๊ตด๋ฐ๊พธ๊ธฐ": "#1์ ์ธ๋ฌผ์ #2์ ์ผ๊ตด๋ก ๋ฐ๊ฟ๋ผ",
|
253 |
"4. ์ท๋ฐ๊พธ๊ธฐ": "#1์ ์ธ๋ฌผ์ #2 ๋๋ #3์ ์ท์ผ๋ก ๋ณ๊ฒฝํ๋ผ",
|
254 |
"5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ": "#1์ ์ด๋ฏธ์ง์ #2์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ฐ๊ฟ๋ผ",
|
@@ -258,26 +200,26 @@ def update_prompt_from_function(function_choice):
|
|
258 |
|
259 |
return function_templates.get(function_choice, "")
|
260 |
|
261 |
-
# Gradio ์ธํฐํ์ด์ค
|
262 |
with gr.Blocks() as demo:
|
263 |
gr.HTML(
|
264 |
"""
|
265 |
<div style="text-align: center; margin-bottom: 1rem;">
|
266 |
<h1>๊ฐ๋จํ ์ด๋ฏธ์ง ์์ฑ๊ธฐ</h1>
|
267 |
-
<p
|
268 |
</div>
|
269 |
"""
|
270 |
)
|
271 |
|
272 |
with gr.Row():
|
273 |
with gr.Column():
|
274 |
-
# 3๊ฐ์ ์ด๋ฏธ์ง ์
๋ ฅ
|
275 |
with gr.Row():
|
276 |
image1_input = gr.Image(type="pil", label="#1", image_mode="RGB")
|
277 |
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
|
278 |
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
|
279 |
|
280 |
-
# ๊ธฐ๋ฅ ์ ํ ๋๋กญ๋ค์ด
|
281 |
function_dropdown = gr.Dropdown(
|
282 |
choices=[
|
283 |
"1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ",
|
@@ -295,7 +237,7 @@ with gr.Blocks() as demo:
|
|
295 |
# ํ๋กฌํํธ ์
๋ ฅ (์ ํ ์ฌํญ)
|
296 |
prompt_input = gr.Textbox(
|
297 |
lines=3,
|
298 |
-
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋
|
299 |
label="ํ๋กฌํํธ (์ ํ ์ฌํญ)"
|
300 |
)
|
301 |
|
@@ -310,7 +252,7 @@ with gr.Blocks() as demo:
|
|
310 |
# ์ฌ์ฉ๋ ํ๋กฌํํธ ํ์
|
311 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ", visible=True)
|
312 |
|
313 |
-
# ๊ธฐ๋ฅ ์ ํ ๋๋กญ๋ค์ด
|
314 |
function_dropdown.change(
|
315 |
fn=update_prompt_from_function,
|
316 |
inputs=[function_dropdown],
|
@@ -324,12 +266,10 @@ with gr.Blocks() as demo:
|
|
324 |
valid_images = [img for img in images if img is not None]
|
325 |
|
326 |
try:
|
327 |
-
# ์๋ ํ๋กฌํํธ ์์ฑ ๋๋ ํ๋กฌํํธ ์ ์ฒ๋ฆฌ
|
328 |
auto_prompt = prompt
|
329 |
if not prompt or not prompt.strip():
|
330 |
-
if
|
331 |
-
|
332 |
-
auto_prompt = "์๋ฆ๋ค์ด ํ๊ฒฝ ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์. ํธ๋ฅธ ํ๋, ์ด๋ก์ ์ธ๋, ๊ทธ๋ฆฌ๊ณ ๋ง์ ํธ์๊ฐ ์๋ ํํ๋ก์ด ์์ฐ ํ๊ฒฝ์ ๋ง๋ค์ด์ฃผ์ธ์."
|
333 |
elif len(valid_images) == 1:
|
334 |
auto_prompt = "์ด ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
335 |
elif len(valid_images) == 2:
|
@@ -339,7 +279,6 @@ with gr.Blocks() as demo:
|
|
339 |
else:
|
340 |
auto_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
341 |
|
342 |
-
# ์ด๋ฏธ์ง ์์ฑ ํจ์ ํธ์ถ
|
343 |
result_img, status = process_images_with_prompt(image1, image2, image3, prompt)
|
344 |
|
345 |
return result_img, status, auto_prompt
|
@@ -357,17 +296,13 @@ with gr.Blocks() as demo:
|
|
357 |
"""
|
358 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
359 |
|
360 |
-
1.
|
361 |
-
2.
|
362 |
-
3.
|
363 |
-
4.
|
364 |
-
5. **์ผ๋ถ ์ด๋ฏธ์ง๋ง**: ํ์ํ ์ด๋ฏธ์ง๋ง ์
๋ก๋ํด๋ ๊ธฐ๋ฅ ์คํ์ด ๊ฐ๋ฅํฉ๋๋ค
|
365 |
-
6. **์ฌ์๋ ๊ธฐ๋ฅ**: ์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์ ์ ์๋์ผ๋ก ์ฌ์๋ํฉ๋๋ค
|
366 |
-
|
367 |
-
> **ํ**: ๊ธฐ๋ฅ์ ์ ํํ ํ์๋ ํ๋กฌํํธ๋ฅผ ์ง์ ์์ ํ ์ ์์ต๋๋ค
|
368 |
"""
|
369 |
)
|
370 |
|
371 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
372 |
if __name__ == "__main__":
|
373 |
-
demo.launch(share=True)
|
|
|
26 |
"""
|
27 |
ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๊ณ ๊ธฐ๋ฅ ๋ช
๋ น์ ํด์
|
28 |
"""
|
29 |
+
# ์ด๋ฏธ์ง ์กด์ฌ ์ฌ๋ถ ํ์ธ
|
30 |
has_img1 = image1 is not None
|
31 |
has_img2 = image2 is not None
|
32 |
has_img3 = image3 is not None
|
33 |
|
34 |
# #1, #2, #3 ์ฐธ์กฐ๋ฅผ ์ค๋ช
์ผ๋ก ๋ณํ (์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฌด์)
|
35 |
+
if "#1" in prompt:
|
36 |
+
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง" if has_img1 else "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
37 |
+
if "#2" in prompt:
|
38 |
+
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง" if has_img2 else "๋ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
39 |
+
if "#3" in prompt:
|
40 |
+
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง" if has_img3 else "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# ๊ธฐ๋ฅ ๋ช
๋ น ํด์
|
43 |
if "1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ" in prompt:
|
44 |
+
desc_match = re.search(r'#1์ "(.*?)"์ผ๋ก ๋ฐ๊ฟ๋ผ', prompt)
|
45 |
+
if desc_match:
|
46 |
+
description = desc_match.group(1)
|
47 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ {description}์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์๋ณธ ์ด๋ฏธ์ง์ ์ฃผ์ ๋ด์ฉ์ ์ ์งํ๋ ์๋ก์ด ์คํ์ผ๊ณผ ๋ถ์๊ธฐ๋ก ์ฌํด์ํด์ฃผ์ธ์."
|
48 |
+
else:
|
49 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
50 |
|
51 |
elif "2. ๊ธ์์ง์ฐ๊ธฐ" in prompt:
|
52 |
+
text_match = re.search(r'#1์์ "(.*?)"๋ฅผ ์ง์๋ผ', prompt)
|
53 |
+
if text_match:
|
54 |
+
text_to_remove = text_match.group(1)
|
55 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ '{text_to_remove}' ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ํ
์คํธ๊ฐ ์๋ ๋ถ๋ถ์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ์ฑ์์ฃผ์ธ์."
|
56 |
+
else:
|
57 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ ๋ชจ๋ ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ๊น๋ํ ์ด๋ฏธ์ง๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
58 |
|
59 |
elif "3. ์ผ๊ตด๋ฐ๊พธ๊ธฐ" in prompt:
|
60 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์ผ๊ตด์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ผ๊ตด๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํด์ฃผ์ธ์. ์ผ๊ตด์ ํ์ ๊ณผ ํน์ง์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ๋๋จธ์ง ๋ถ๋ถ์ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
61 |
|
62 |
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt:
|
|
|
63 |
if "#3" in prompt or "๋๋ #3" in prompt:
|
64 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ๋๋ ์ธ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ์ฐธ์กฐ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
65 |
else:
|
|
|
69 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
70 |
|
71 |
elif "6. ์ด๋ฏธ์ง ํฉ์ฑ(์ํํฌํจ)" in prompt:
|
|
|
72 |
if "#3" in prompt or "๋๋ #3" in prompt:
|
73 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ ๋ฒ์งธ, ์ธ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํด์ฃผ์ธ์. ๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ์ ๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํด์ฃผ์ธ์."
|
74 |
else:
|
|
|
77 |
elif "7. ์ด๋ฏธ์ง ํฉ์ฑ(์คํ์ผ์ ์ฉ)" in prompt:
|
78 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ด์ฉ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์คํ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด์ ๊ตฌ๋๋ ์ ์งํ๋, ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์ ์ ์คํ์ผ, ์์, ์ง๊ฐ์ ์ ์ฉํด์ฃผ์ธ์."
|
79 |
|
|
|
80 |
elif "์ ๋ถ์์์ผ๋ก ๋ฐ๊ฟ๋ผ" in prompt or "๋ฅผ ๋ถ์์์ผ๋ก ๋ฐ๊ฟ๋ผ" in prompt:
|
81 |
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ถ์์ ํค์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ ์ฒด์ ์ธ ์์์ ๋ถ์ ๊ณ์ด๋ก ์กฐ์ ํ๊ณ ์์ฐ์ค๋ฌ๏ฟฝ๏ฟฝ ๋๋์ ์ ์งํด์ฃผ์ธ์."
|
82 |
|
|
|
83 |
prompt += " ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์."
|
|
|
84 |
return prompt
|
85 |
|
86 |
+
def generate_with_images(prompt, images):
|
87 |
"""
|
88 |
+
API ํธ์ถ์ ํตํด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ํจ์
|
|
|
89 |
"""
|
90 |
+
try:
|
91 |
+
api_key = os.environ.get("GEMINI_API_KEY")
|
92 |
+
if not api_key:
|
93 |
+
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
client = genai.Client(api_key=api_key)
|
96 |
+
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}")
|
97 |
+
|
98 |
+
contents = []
|
99 |
+
contents.append(prompt)
|
100 |
+
for idx, img in enumerate(images, 1):
|
101 |
+
if img is not None:
|
102 |
+
contents.append(img)
|
103 |
+
logger.info(f"์ด๋ฏธ์ง #{idx} ์ถ๊ฐ๋จ")
|
104 |
+
|
105 |
+
response = client.models.generate_content(
|
106 |
+
model="gemini-2.0-flash-exp-image-generation",
|
107 |
+
contents=contents,
|
108 |
+
config=types.GenerateContentConfig(
|
109 |
+
response_modalities=['Text', 'Image'],
|
110 |
+
temperature=1,
|
111 |
+
top_p=0.95,
|
112 |
+
top_k=40,
|
113 |
+
max_output_tokens=8192
|
114 |
+
)
|
115 |
+
)
|
116 |
+
|
117 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
118 |
+
temp_path = tmp.name
|
119 |
|
120 |
+
result_text = ""
|
121 |
+
image_found = False
|
|
|
122 |
|
123 |
+
for part in response.candidates[0].content.parts:
|
124 |
+
if hasattr(part, 'text') and part.text:
|
125 |
+
result_text += part.text
|
126 |
+
logger.info(f"์๋ต ํ
์คํธ: {part.text}")
|
127 |
+
elif hasattr(part, 'inline_data') and part.inline_data:
|
128 |
+
save_binary_file(temp_path, part.inline_data.data)
|
129 |
+
image_found = True
|
130 |
+
logger.info("์๋ต์์ ์ด๋ฏธ์ง ์ถ์ถ ์ฑ๊ณต")
|
131 |
|
132 |
+
if not image_found:
|
133 |
+
return None, f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์๋ต ํ
์คํธ: {result_text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
result_img = Image.open(temp_path)
|
136 |
+
if result_img.mode == "RGBA":
|
137 |
+
result_img = result_img.convert("RGB")
|
138 |
|
139 |
+
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}"
|
140 |
+
|
141 |
+
except Exception as e:
|
142 |
+
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
143 |
+
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
def process_images_with_prompt(image1, image2, image3, prompt):
|
146 |
"""
|
147 |
+
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๋ ํจ์.
|
148 |
+
์ด๋ฏธ์ง๊ฐ ์
๋ก๋๋์ง ์์ ๊ฒฝ์ฐ์๋ ํ๋กฌํํธ์ ๋ฐ๋ผ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ฉฐ,
|
149 |
+
์ด๋ฏธ์ง ์์ฑ์ ์คํจํ๋ฉด ์ต๋ 3ํ๊น์ง ์ฌ์๋ํฉ๋๋ค.
|
150 |
"""
|
151 |
try:
|
|
|
152 |
images = [image1, image2, image3]
|
153 |
+
valid_images = [img for img in images if img is not None] # ์ด๋ฏธ์ง๊ฐ ์์ ์๋ ์์
|
154 |
|
155 |
+
# ํ๋กฌํํธ ์๋ ์์ฑ (์
๋ก๋๋ ์ด๋ฏธ์ง ์์ ๋ฐ๋ผ)
|
156 |
if not prompt or not prompt.strip():
|
157 |
+
if len(valid_images) == 0:
|
158 |
+
prompt = "์ด ํ๋กฌํํธ์ ๋ง์ถฐ ์ฐฝ์์ ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์."
|
159 |
+
logger.info("ํ
์คํธ ์ ์ฉ ํ๋กฌํํธ ์๋ ์์ฑ")
|
|
|
|
|
160 |
elif len(valid_images) == 1:
|
161 |
prompt = "์ด ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
162 |
logger.info("๋จ์ผ ์ด๋ฏธ์ง ํ๋กฌํํธ ์๋ ์์ฑ")
|
|
|
167 |
prompt = "์ด ์ธ ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ํฉ์ฑํด์ฃผ์ธ์. ๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๋ ์์ฐ์ค๋ฝ๊ณ ์ผ๊ด๋ ํ๋์ ์ฅ๋ฉด์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
168 |
logger.info("์ธ ์ด๋ฏธ์ง ํฉ์ฑ ํ๋กฌํํธ ์๋ ์์ฑ")
|
169 |
else:
|
|
|
170 |
prompt = preprocess_prompt(prompt, image1, image2, image3)
|
171 |
|
172 |
+
# ์ต๋ 3ํ๊น์ง ์ฌ์๋
|
173 |
+
max_retries = 3
|
174 |
+
for attempt in range(max_retries):
|
175 |
+
result_img, status = generate_with_images(prompt, valid_images)
|
176 |
+
if result_img is not None:
|
177 |
+
return result_img, status
|
178 |
+
else:
|
179 |
+
logger.info(f"์ด๋ฏธ์ง ์์ฑ ์คํจ, ์ฌ์๋ ์ค ({attempt+1}/{max_retries})")
|
180 |
+
return None, f"์ด๋ฏธ์ง ์์ฑ์ ์คํจํ์์ต๋๋ค. ๋ง์ง๋ง ์ํ: {status}"
|
181 |
|
182 |
except Exception as e:
|
183 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
184 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
185 |
|
|
|
186 |
def update_prompt_from_function(function_choice):
|
187 |
+
"""
|
188 |
+
๊ธฐ๋ฅ ์ ํ์ ๋ฐ๋ผ ํ๋กฌํํธ ํ
ํ๋ฆฟ์ ๋ฐํํฉ๋๋ค.
|
189 |
+
(์ปค์คํ
ํ
์คํธ ์
๋ ฅ์ ์ ๊ฑฐ๋์์ต๋๋ค.)
|
190 |
+
"""
|
191 |
function_templates = {
|
192 |
+
"1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ": '#1์ "์ํ๋ ์ค๋ช
"์ผ๋ก ๋ฐ๊ฟ๋ผ',
|
193 |
+
"2. ๊ธ์์ง์ฐ๊ธฐ": '#1์์ "์ง์ธ ํ
์คํธ"๋ฅผ ์ง์๋ผ',
|
194 |
"3. ์ผ๊ตด๋ฐ๊พธ๊ธฐ": "#1์ ์ธ๋ฌผ์ #2์ ์ผ๊ตด๋ก ๋ฐ๊ฟ๋ผ",
|
195 |
"4. ์ท๋ฐ๊พธ๊ธฐ": "#1์ ์ธ๋ฌผ์ #2 ๋๋ #3์ ์ท์ผ๋ก ๋ณ๊ฒฝํ๋ผ",
|
196 |
"5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ": "#1์ ์ด๋ฏธ์ง์ #2์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ฐ๊ฟ๋ผ",
|
|
|
200 |
|
201 |
return function_templates.get(function_choice, "")
|
202 |
|
203 |
+
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
204 |
with gr.Blocks() as demo:
|
205 |
gr.HTML(
|
206 |
"""
|
207 |
<div style="text-align: center; margin-bottom: 1rem;">
|
208 |
<h1>๊ฐ๋จํ ์ด๋ฏธ์ง ์์ฑ๊ธฐ</h1>
|
209 |
+
<p>ํ๋กฌํํธ๋ง ์
๋ ฅํด๋ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ฉ๋๋ค. ๋ํ, ๊ธฐ๋ฅ ์ ํ๋ง์ผ๋ก ํ๋กฌํํธ์ ์ ์ฉํ ์ ์์ต๋๋ค.</p>
|
210 |
</div>
|
211 |
"""
|
212 |
)
|
213 |
|
214 |
with gr.Row():
|
215 |
with gr.Column():
|
216 |
+
# 3๊ฐ์ ์ด๋ฏธ์ง ์
๋ ฅ (์
๋ก๋ํ์ง ์์๋ ๋จ)
|
217 |
with gr.Row():
|
218 |
image1_input = gr.Image(type="pil", label="#1", image_mode="RGB")
|
219 |
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
|
220 |
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
|
221 |
|
222 |
+
# ๊ธฐ๋ฅ ์ ํ ๋๋กญ๋ค์ด (์ปค์คํ
ํ
์คํธ ์
๋ ฅ ์ ๊ฑฐ)
|
223 |
function_dropdown = gr.Dropdown(
|
224 |
choices=[
|
225 |
"1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ",
|
|
|
237 |
# ํ๋กฌํํธ ์
๋ ฅ (์ ํ ์ฌํญ)
|
238 |
prompt_input = gr.Textbox(
|
239 |
lines=3,
|
240 |
+
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ์์ฑ๋ฉ๋๋ค.",
|
241 |
label="ํ๋กฌํํธ (์ ํ ์ฌํญ)"
|
242 |
)
|
243 |
|
|
|
252 |
# ์ฌ์ฉ๋ ํ๋กฌํํธ ํ์
|
253 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ", visible=True)
|
254 |
|
255 |
+
# ๊ธฐ๋ฅ ์ ํ ๋๋กญ๋ค์ด ๋ณ๊ฒฝ ์ ํ๋กฌํํธ ์
๋ฐ์ดํธ (apply ๋ฒํผ ์์ด ๋ฐ๋ก ์ ์ฉ)
|
256 |
function_dropdown.change(
|
257 |
fn=update_prompt_from_function,
|
258 |
inputs=[function_dropdown],
|
|
|
266 |
valid_images = [img for img in images if img is not None]
|
267 |
|
268 |
try:
|
|
|
269 |
auto_prompt = prompt
|
270 |
if not prompt or not prompt.strip():
|
271 |
+
if len(valid_images) == 0:
|
272 |
+
auto_prompt = "์ด ํ๋กฌํํธ์ ๋ง์ถฐ ์ฐฝ์์ ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์."
|
|
|
273 |
elif len(valid_images) == 1:
|
274 |
auto_prompt = "์ด ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
275 |
elif len(valid_images) == 2:
|
|
|
279 |
else:
|
280 |
auto_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
281 |
|
|
|
282 |
result_img, status = process_images_with_prompt(image1, image2, image3, prompt)
|
283 |
|
284 |
return result_img, status, auto_prompt
|
|
|
296 |
"""
|
297 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
298 |
|
299 |
+
1. **ํ
์คํธ ์ ์ฉ ์์ฑ**: ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ง ์๊ณ ํ๋กฌํํธ๋ง ์
๋ ฅํด๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
|
300 |
+
2. **๊ธฐ๋ฅ ์ ํ**: ๋๋กญ๋ค์ด์์ ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ๋ฉด ํด๋น ๊ธฐ๋ฅ์ ํ
ํ๋ฆฟ์ด ํ๋กฌํํธ์ ์๋ ๋ฐ์๋ฉ๋๋ค.
|
301 |
+
3. **์ด๋ฏธ์ง ์
๋ก๋**: ์ผ๋ถ ๋๋ ์ ์ฒด ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด๋ ๊ธฐ๋ฅ์ด ์ ์์ ์ผ๋ก ๋์ํฉ๋๋ค.
|
302 |
+
4. **์๋ ์ฌ์๋**: ์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด ์ต๋ 2ํ ์ถ๊ฐ ์ฌ์๋ํฉ๋๋ค.
|
|
|
|
|
|
|
|
|
303 |
"""
|
304 |
)
|
305 |
|
306 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
307 |
if __name__ == "__main__":
|
308 |
+
demo.launch(share=True)
|