Update app.py
Browse files
app.py
CHANGED
@@ -184,16 +184,16 @@ def process_images_with_prompt(image1, image2, image3, prompt):
|
|
184 |
|
185 |
# ํ๋กฌํํธ ์ฒ๋ฆฌ
|
186 |
if not prompt or not prompt.strip():
|
187 |
-
# ํ๋กฌํํธ๊ฐ ์์ผ๋ฉด ์
๋ก๋๋ ์ด๋ฏธ์ง ์์ ๋ฐ๋ผ ์๋ ํฉ์ฑ
|
188 |
if len(valid_images) == 1:
|
189 |
-
prompt = "
|
190 |
-
logger.info("
|
191 |
elif len(valid_images) == 2:
|
192 |
-
prompt = "
|
193 |
-
logger.info("
|
194 |
else:
|
195 |
-
prompt = "
|
196 |
-
logger.info("
|
197 |
else:
|
198 |
# ํ๋กฌํํธ ์ ์ฒ๋ฆฌ ๋ฐ ๊ธฐ๋ฅ ๋ช
๋ น ํด์
|
199 |
prompt = preprocess_prompt(prompt, image1, image2, image3)
|
@@ -205,27 +205,15 @@ def process_images_with_prompt(image1, image2, image3, prompt):
|
|
205 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
206 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
207 |
|
208 |
-
# ๊ธฐ๋ฅ ์ ํ
|
209 |
-
def update_prompt_from_function(function_choice, custom_text=""):
|
210 |
-
function_templates = {
|
211 |
-
"1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ": f'#1์ "{custom_text if custom_text else "์ํ๋ ์ค๋ช
"}"์ผ๋ก ๋ฐ๊ฟ๋ผ',
|
212 |
-
"2. ๊ธ์์ง์ฐ๊ธฐ": f'#1์์ "{custom_text if custom_text else "์ง์ธ ํ
์คํธ"}"๋ฅผ ์ง์๋ผ',
|
213 |
-
"3. ์ผ๊ตด๋ฐ๊พธ๊ธฐ": "#1์ ์ธ๋ฌผ์ #2์ ์ผ๊ตด๋ก ๋ฐ๊ฟ๋ผ",
|
214 |
-
"4. ์ท๋ฐ๊พธ๊ธฐ": "#1์ ์ธ๋ฌผ์ #2 ๋๋ #3์ ์ท์ผ๋ก ๋ณ๊ฒฝํ๋ผ",
|
215 |
-
"5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ": "#1์ ์ด๋ฏธ์ง์ #2์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ฐ๊ฟ๋ผ",
|
216 |
-
"6. ์ด๋ฏธ์ง ํฉ์ฑ(์ํํฌํจ)": "#1์ #2 ๋๋ #3์ ๋ฅผ ํฉ์ฑํ๋ผ",
|
217 |
-
"7. ์ด๋ฏธ์ง ํฉ์ฑ(์คํ์ผ์ ์ฉ)": "#1์ #2๋ฅผ ์คํ์ผ๋ก ๋ณํํ๋ผ"
|
218 |
-
}
|
219 |
-
|
220 |
-
return function_templates.get(function_choice, "")
|
221 |
|
222 |
-
# Gradio ์ธํฐํ์ด์ค
|
223 |
with gr.Blocks() as demo:
|
224 |
gr.HTML(
|
225 |
"""
|
226 |
<div style="text-align: center; margin-bottom: 1rem;">
|
227 |
<h1>๊ฐ๋จํ ์ด๋ฏธ์ง ์์ฑ๊ธฐ</h1>
|
228 |
-
<p>์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ๋ฐ๋ก ์คํํ๋ฉด ์๋์ผ๋ก
|
229 |
</div>
|
230 |
"""
|
231 |
)
|
@@ -238,28 +226,6 @@ with gr.Blocks() as demo:
|
|
238 |
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
|
239 |
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
|
240 |
|
241 |
-
# ๊ธฐ๋ฅ ์ ํ ๋๋กญ๋ค์ด๊ณผ ์ปค์คํ
ํ
์คํธ ์
๋ ฅ
|
242 |
-
with gr.Row():
|
243 |
-
function_dropdown = gr.Dropdown(
|
244 |
-
choices=[
|
245 |
-
"1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ",
|
246 |
-
"2. ๊ธ์์ง์ฐ๊ธฐ",
|
247 |
-
"3. ์ผ๊ตด๋ฐ๊พธ๊ธฐ",
|
248 |
-
"4. ์ท๋ฐ๊พธ๊ธฐ",
|
249 |
-
"5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ",
|
250 |
-
"6. ์ด๋ฏธ์ง ํฉ์ฑ(์ํํฌํจ)",
|
251 |
-
"7. ์ด๋ฏธ์ง ํฉ์ฑ(์คํ์ผ์ ์ฉ)"
|
252 |
-
],
|
253 |
-
label="๊ธฐ๋ฅ ์ ํ",
|
254 |
-
value=None
|
255 |
-
)
|
256 |
-
custom_text_input = gr.Textbox(
|
257 |
-
label="์ปค์คํ
ํ
์คํธ (1, 2๋ฒ ๊ธฐ๋ฅ์ฉ)",
|
258 |
-
placeholder="์: ๋ถ์์, ์์ฑํ ์คํ์ผ, ์ค๊ตญ์ด..."
|
259 |
-
)
|
260 |
-
|
261 |
-
apply_function_btn = gr.Button("๊ธฐ๋ฅ ์ ์ฉ")
|
262 |
-
|
263 |
# ํ๋กฌํํธ ์
๋ ฅ (์ ํ ์ฌํญ)
|
264 |
prompt_input = gr.Textbox(
|
265 |
lines=3,
|
@@ -278,13 +244,6 @@ with gr.Blocks() as demo:
|
|
278 |
# ์ฌ์ฉ๋ ํ๋กฌํํธ ํ์
|
279 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ", visible=True)
|
280 |
|
281 |
-
# ๊ธฐ๋ฅ ์ ์ฉ ๋ฒํผ ์ด๋ฒคํธ
|
282 |
-
apply_function_btn.click(
|
283 |
-
fn=update_prompt_from_function,
|
284 |
-
inputs=[function_dropdown, custom_text_input],
|
285 |
-
outputs=[prompt_input]
|
286 |
-
)
|
287 |
-
|
288 |
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
289 |
def process_and_show_prompt(image1, image2, image3, prompt):
|
290 |
# ์ด๋ฏธ์ง ๊ฐ์ ํ์ธ
|
@@ -296,11 +255,11 @@ with gr.Blocks() as demo:
|
|
296 |
auto_prompt = prompt
|
297 |
if not prompt or not prompt.strip():
|
298 |
if len(valid_images) == 1:
|
299 |
-
auto_prompt = "
|
300 |
elif len(valid_images) == 2:
|
301 |
-
auto_prompt = "
|
302 |
else:
|
303 |
-
auto_prompt = "
|
304 |
else:
|
305 |
auto_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
306 |
|
@@ -311,7 +270,7 @@ with gr.Blocks() as demo:
|
|
311 |
except Exception as e:
|
312 |
logger.exception("์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
313 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
314 |
-
|
315 |
submit_btn.click(
|
316 |
fn=process_and_show_prompt,
|
317 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
@@ -322,16 +281,14 @@ with gr.Blocks() as demo:
|
|
322 |
"""
|
323 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
324 |
|
325 |
-
1. **์๋ ํฉ์ฑ**: ์ด๋ฏธ์ง๋ง ์
๋ก๋ํ๊ณ ํ๋กฌํํธ๋ฅผ ๋น์๋๋ฉด ์๋์ผ๋ก
|
326 |
-
2.
|
327 |
-
3.
|
328 |
-
4. **์ด๋ฏธ์ง ์ฐธ์กฐ**: #1, #2, #3์ผ๋ก ๊ฐ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํ ์ ์์ต๋๋ค
|
329 |
-
5. **์ผ๋ถ ์ด๋ฏธ์ง๋ง**: ํ์ํ ์ด๋ฏธ์ง๋ง ์
๋ก๋ํด๋ ๊ธฐ๋ฅ ์คํ์ด ๊ฐ๋ฅํฉ๋๋ค
|
330 |
|
331 |
-
> **ํ**:
|
332 |
"""
|
333 |
)
|
334 |
|
335 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
336 |
if __name__ == "__main__":
|
337 |
-
demo.launch(share=True)
|
|
|
184 |
|
185 |
# ํ๋กฌํํธ ์ฒ๋ฆฌ
|
186 |
if not prompt or not prompt.strip():
|
187 |
+
# ํ๋กฌํํธ๊ฐ ์์ผ๋ฉด ์
๋ก๋๋ ์ด๋ฏธ์ง ์์ ๋ฐ๋ผ ์๋ ํฉ์ฑ ํ๋กฌํํธ๋ฅผ ์์ด๋ก ์์ฑ
|
188 |
if len(valid_images) == 1:
|
189 |
+
prompt = "Please creatively transform this image into a more vivid and artistic version."
|
190 |
+
logger.info("Default prompt generated for single image")
|
191 |
elif len(valid_images) == 2:
|
192 |
+
prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image."
|
193 |
+
logger.info("Default prompt generated for two images")
|
194 |
else:
|
195 |
+
prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene."
|
196 |
+
logger.info("Default prompt generated for three images")
|
197 |
else:
|
198 |
# ํ๋กฌํํธ ์ ์ฒ๋ฆฌ ๋ฐ ๊ธฐ๋ฅ ๋ช
๋ น ํด์
|
199 |
prompt = preprocess_prompt(prompt, image1, image2, image3)
|
|
|
205 |
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
206 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
207 |
|
208 |
+
# (๊ธฐ๋ฅ ์ ํ ๊ด๋ จ ์ฝ๋ ์ ์ฒด ์ญ์ ๋จ)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
+
# Gradio ์ธํฐํ์ด์ค
|
211 |
with gr.Blocks() as demo:
|
212 |
gr.HTML(
|
213 |
"""
|
214 |
<div style="text-align: center; margin-bottom: 1rem;">
|
215 |
<h1>๊ฐ๋จํ ์ด๋ฏธ์ง ์์ฑ๊ธฐ</h1>
|
216 |
+
<p>์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ๋ฐ๋ก ์คํํ๋ฉด ์๋์ผ๋ก ํฉ์ฑํฉ๋๋ค.</p>
|
217 |
</div>
|
218 |
"""
|
219 |
)
|
|
|
226 |
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
|
227 |
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
# ํ๋กฌํํธ ์
๋ ฅ (์ ํ ์ฌํญ)
|
230 |
prompt_input = gr.Textbox(
|
231 |
lines=3,
|
|
|
244 |
# ์ฌ์ฉ๋ ํ๋กฌํํธ ํ์
|
245 |
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ", visible=True)
|
246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
248 |
def process_and_show_prompt(image1, image2, image3, prompt):
|
249 |
# ์ด๋ฏธ์ง ๊ฐ์ ํ์ธ
|
|
|
255 |
auto_prompt = prompt
|
256 |
if not prompt or not prompt.strip():
|
257 |
if len(valid_images) == 1:
|
258 |
+
auto_prompt = "Please creatively transform this image into a more vivid and artistic version."
|
259 |
elif len(valid_images) == 2:
|
260 |
+
auto_prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image."
|
261 |
else:
|
262 |
+
auto_prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene."
|
263 |
else:
|
264 |
auto_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
265 |
|
|
|
270 |
except Exception as e:
|
271 |
logger.exception("์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:")
|
272 |
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt
|
273 |
+
|
274 |
submit_btn.click(
|
275 |
fn=process_and_show_prompt,
|
276 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
|
|
281 |
"""
|
282 |
### ์ฌ์ฉ ๋ฐฉ๋ฒ:
|
283 |
|
284 |
+
1. **์๋ ํฉ์ฑ**: ์ด๋ฏธ์ง๋ง ์
๋ก๋ํ๊ณ ํ๋กฌํํธ๋ฅผ ๋น์๋๋ฉด ์๋์ผ๋ก ํฉ์ฑ๋ฉ๋๋ค.
|
285 |
+
2. **์ด๋ฏธ์ง ์ฐธ์กฐ**: #1, #2, #3์ผ๋ก ๊ฐ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
|
286 |
+
3. **์ผ๋ถ ์ด๋ฏธ์ง๋ง**: ํ์ํ ์ด๋ฏธ์ง๋ง ์
๋ก๋ํด๋ ๊ธฐ๋ฅ ์คํ์ด ๊ฐ๋ฅํฉ๋๋ค.
|
|
|
|
|
287 |
|
288 |
+
> **ํ**: ํ๋กฌํํธ๋ฅผ ์ง์ ์์ ํ ์๋ ์์ต๋๋ค.
|
289 |
"""
|
290 |
)
|
291 |
|
292 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
293 |
if __name__ == "__main__":
|
294 |
+
demo.launch(share=True)
|