Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,9 @@ from PIL import Image
|
|
4 |
import os
|
5 |
import json
|
6 |
import tempfile
|
|
|
7 |
import re
|
8 |
import time
|
9 |
-
import logging
|
10 |
|
11 |
# ๋ก๊น
์ค์
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
@@ -157,7 +157,7 @@ def generate_prompt_with_gemini(product_name, background_info, additional_info="
|
|
157 |
)
|
158 |
response = model.generate_content(
|
159 |
prompt_request,
|
160 |
-
generation_config=genai.GenerationConfig(
|
161 |
temperature=0.7,
|
162 |
top_p=0.95,
|
163 |
top_k=64,
|
@@ -171,7 +171,8 @@ def generate_prompt_with_gemini(product_name, background_info, additional_info="
|
|
171 |
except Exception as e:
|
172 |
return f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
173 |
|
174 |
-
# ์ด๋ฏธ์ง
|
|
|
175 |
def save_binary_file(file_name, data):
|
176 |
with open(file_name, "wb") as f:
|
177 |
f.write(data)
|
@@ -185,14 +186,15 @@ def translate_prompt_to_english(prompt):
|
|
185 |
prompt = prompt.replace("#3", "IMAGE_TAG_THREE")
|
186 |
|
187 |
try:
|
188 |
-
|
|
|
189 |
logger.error("Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
190 |
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
191 |
prompt = prompt.replace("IMAGE_TAG_TWO", "#2")
|
192 |
prompt = prompt.replace("IMAGE_TAG_THREE", "#3")
|
193 |
return prompt
|
194 |
|
195 |
-
|
196 |
translation_prompt = f"""
|
197 |
Translate the following Korean text to English:
|
198 |
|
@@ -203,9 +205,10 @@ def translate_prompt_to_english(prompt):
|
|
203 |
"""
|
204 |
|
205 |
logger.info(f"Translation prompt: {translation_prompt}")
|
206 |
-
response =
|
207 |
-
|
208 |
-
|
|
|
209 |
temperature=0.2,
|
210 |
top_p=0.95,
|
211 |
top_k=40,
|
@@ -213,7 +216,10 @@ def translate_prompt_to_english(prompt):
|
|
213 |
)
|
214 |
)
|
215 |
|
216 |
-
translated_text =
|
|
|
|
|
|
|
217 |
|
218 |
if translated_text.strip():
|
219 |
translated_text = translated_text.replace("IMAGE_TAG_ONE", "#1")
|
@@ -284,10 +290,11 @@ def preprocess_prompt(prompt, image1, image2, image3):
|
|
284 |
|
285 |
def generate_with_images(prompt, images, variation_index=0):
|
286 |
try:
|
287 |
-
|
|
|
288 |
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
289 |
|
290 |
-
|
291 |
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}, ๋ณํ ์ธ๋ฑ์ค: {variation_index}")
|
292 |
|
293 |
variation_suffixes = [
|
@@ -308,9 +315,11 @@ def generate_with_images(prompt, images, variation_index=0):
|
|
308 |
contents.append(img)
|
309 |
logger.info(f"์ด๋ฏธ์ง #{idx} ์ถ๊ฐ๋จ")
|
310 |
|
311 |
-
response =
|
|
|
312 |
contents=contents,
|
313 |
-
generation_config=genai.GenerationConfig(
|
|
|
314 |
temperature=1,
|
315 |
top_p=0.95,
|
316 |
top_k=40,
|
@@ -322,26 +331,19 @@ def generate_with_images(prompt, images, variation_index=0):
|
|
322 |
temp_path = tmp.name
|
323 |
result_text = ""
|
324 |
image_found = False
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
elif hasattr(part, 'inline_data') and part.inline_data:
|
334 |
-
save_binary_file(temp_path, part.inline_data.data)
|
335 |
-
image_found = True
|
336 |
-
logger.info("์๋ต์์ ์ด๋ฏธ์ง ์ถ์ถ ์ฑ๊ณต")
|
337 |
-
|
338 |
if not image_found:
|
339 |
return None, f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์๋ต ํ
์คํธ: {result_text}"
|
340 |
-
|
341 |
result_img = Image.open(temp_path)
|
342 |
if result_img.mode == "RGBA":
|
343 |
result_img = result_img.convert("RGB")
|
344 |
-
|
345 |
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}"
|
346 |
except Exception as e:
|
347 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
@@ -427,20 +429,26 @@ def generate_multiple_images(image1, image2, image3, prompt, progress=gr.Progres
|
|
427 |
return results[0], results[1], results[2], results[3], combined_status, combined_prompts
|
428 |
|
429 |
def create_app():
|
430 |
-
with gr.Blocks() as demo:
|
431 |
-
gr.Markdown("#
|
432 |
-
gr.Markdown("์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ์ต์
์ ์ ํํ๋ฉด ๊ณ ํ์ง ์์
์ฉ ํ๋กฌํํธ๊ฐ ์์ฑ๋ฉ๋๋ค.")
|
433 |
|
|
|
434 |
with gr.Row():
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
444 |
|
445 |
# ์ฌํ ๋ฐฐ๊ฒฝ ์ ํ ๋๋กญ๋ค์ด
|
446 |
simple_dropdown = gr.Dropdown(
|
@@ -469,7 +477,7 @@ def create_app():
|
|
469 |
interactive=True
|
470 |
)
|
471 |
|
472 |
-
|
473 |
indoor_dropdown = gr.Dropdown(
|
474 |
choices=list(INDOOR_BACKGROUNDS.keys()),
|
475 |
value=list(INDOOR_BACKGROUNDS.keys())[0] if INDOOR_BACKGROUNDS else None,
|
@@ -487,39 +495,40 @@ def create_app():
|
|
487 |
interactive=True
|
488 |
)
|
489 |
|
490 |
-
#
|
491 |
-
|
|
|
|
|
492 |
|
493 |
# ์ถ๊ฐ ์์ฒญ์ฌํญ
|
494 |
additional_info = gr.Textbox(
|
495 |
label="์ถ๊ฐ ์์ฒญ์ฌํญ (์ ํ์ฌํญ)",
|
496 |
placeholder="์: ๊ณ ๊ธ์ค๋ฌ์ด ๋๋, ๋ฐ์ ์กฐ๋ช
, ์์ฐ์ค๋ฌ์ด ๋ณด์กฐ์ ์ธ ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์ ๋ฑ",
|
497 |
-
lines=3
|
|
|
498 |
)
|
499 |
|
500 |
-
|
|
|
|
|
|
|
|
|
501 |
|
502 |
-
|
503 |
-
|
|
|
504 |
|
505 |
-
|
|
|
506 |
with gr.Row():
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
output_image2 = gr.Image(label="์ด๋ฏธ์ง #2")
|
516 |
-
with gr.Row():
|
517 |
-
with gr.Column():
|
518 |
-
output_image3 = gr.Image(label="์ด๋ฏธ์ง #3")
|
519 |
-
with gr.Column():
|
520 |
-
output_image4 = gr.Image(label="์ด๋ฏธ์ง #4")
|
521 |
-
|
522 |
-
status_output = gr.Textbox(label="์ํ ๋ฉ์์ง", lines=2)
|
523 |
|
524 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ๋๋กญ๋ค์ด ํ์ ์
๋ฐ์ดํธ
|
525 |
def update_dropdowns(bg_type):
|
@@ -558,7 +567,7 @@ def create_app():
|
|
558 |
"name": nature,
|
559 |
"english": NATURE_BACKGROUNDS.get(nature, "natural environment")
|
560 |
}
|
561 |
-
elif bg_type == "์ค๋ด ํ๊ฒฝ":
|
562 |
return {
|
563 |
"category": "์ค๋ด ํ๊ฒฝ",
|
564 |
"name": indoor,
|
@@ -578,12 +587,9 @@ elif bg_type == "์ค๋ด ํ๊ฒฝ":
|
|
578 |
}
|
579 |
|
580 |
# ํ๋กฌํํธ ์์ฑ ํจ์
|
581 |
-
def generate_prompt(
|
582 |
-
if
|
583 |
-
|
584 |
-
return "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์."
|
585 |
-
|
586 |
-
product_text = product_text.strip() or "์ ํ"
|
587 |
|
588 |
# ๋ฐฐ๊ฒฝ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
589 |
background_info = get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract)
|
@@ -600,7 +606,6 @@ API ํค ์ค์ ๋ฐฉ๋ฒ:
|
|
600 |
2. ์ฝ๋ ๋ด ์ง์ ์
๋ ฅ: GEMINI_API_KEY = "your-api-key"
|
601 |
ํค ๋ฐ๊ธ: https://makersuite.google.com/
|
602 |
"""
|
603 |
-
return prompt
|
604 |
|
605 |
return prompt
|
606 |
except Exception as e:
|
@@ -608,38 +613,10 @@ API ํค ์ค์ ๋ฐฉ๋ฒ:
|
|
608 |
gr.Error(error_msg)
|
609 |
return error_msg
|
610 |
|
611 |
-
#
|
612 |
-
def generate_single_image(image, prompt):
|
613 |
-
if image is None:
|
614 |
-
return None, None, None, None, "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์."
|
615 |
-
|
616 |
-
if not prompt or prompt.strip() == "":
|
617 |
-
return None, None, None, None, "ํ๋กฌํํธ๋ฅผ ์์ฑํด์ฃผ์ธ์."
|
618 |
-
|
619 |
-
if not GEMINI_API_KEY:
|
620 |
-
return None, None, None, None, "Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
621 |
-
|
622 |
-
try:
|
623 |
-
# ์์ด ํ๋กฌํํธ๋ก ๋ณํ
|
624 |
-
if re.search("[๊ฐ-ํฃ]", prompt):
|
625 |
-
prompt = translate_prompt_to_english(prompt)
|
626 |
-
|
627 |
-
# ์ด๋ฏธ์ง 1๊ฐ ์์ฑ (variation_index=0)
|
628 |
-
result_img, status, _ = process_images_with_prompt(image, None, None, prompt, 0, 3)
|
629 |
-
|
630 |
-
if result_img is None:
|
631 |
-
return None, None, None, None, status
|
632 |
-
|
633 |
-
return result_img, None, None, None, status
|
634 |
-
except Exception as e:
|
635 |
-
error_msg = f"์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
636 |
-
return None, None, None, None, error_msg
|
637 |
-
|
638 |
-
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
639 |
generate_prompt_btn.click(
|
640 |
fn=generate_prompt,
|
641 |
inputs=[
|
642 |
-
image_input,
|
643 |
background_type,
|
644 |
simple_dropdown,
|
645 |
studio_dropdown,
|
@@ -652,18 +629,18 @@ API ํค ์ค์ ๋ฐฉ๋ฒ:
|
|
652 |
outputs=prompt_output
|
653 |
)
|
654 |
|
655 |
-
# ๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ
|
656 |
-
|
657 |
-
fn=
|
658 |
-
inputs=[image_input, prompt_output],
|
659 |
-
outputs=[output_image1,
|
660 |
)
|
661 |
|
662 |
-
#
|
663 |
-
|
664 |
-
fn=
|
665 |
-
inputs=[image_input, prompt_output],
|
666 |
-
outputs=[output_image1, output_image2, output_image3, output_image4,
|
667 |
)
|
668 |
|
669 |
return demo
|
|
|
4 |
import os
|
5 |
import json
|
6 |
import tempfile
|
7 |
+
import logging
|
8 |
import re
|
9 |
import time
|
|
|
10 |
|
11 |
# ๋ก๊น
์ค์
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
157 |
)
|
158 |
response = model.generate_content(
|
159 |
prompt_request,
|
160 |
+
generation_config=genai.types.GenerationConfig(
|
161 |
temperature=0.7,
|
162 |
top_p=0.95,
|
163 |
top_k=64,
|
|
|
171 |
except Exception as e:
|
172 |
return f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
173 |
|
174 |
+
# ์ด๋ฏธ์ง ์์ฑ ๊ด๋ จ ์๋ก์ด ํจ์๋ค
|
175 |
+
|
176 |
def save_binary_file(file_name, data):
|
177 |
with open(file_name, "wb") as f:
|
178 |
f.write(data)
|
|
|
186 |
prompt = prompt.replace("#3", "IMAGE_TAG_THREE")
|
187 |
|
188 |
try:
|
189 |
+
api_key = GEMINI_API_KEY
|
190 |
+
if not api_key:
|
191 |
logger.error("Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
192 |
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
193 |
prompt = prompt.replace("IMAGE_TAG_TWO", "#2")
|
194 |
prompt = prompt.replace("IMAGE_TAG_THREE", "#3")
|
195 |
return prompt
|
196 |
|
197 |
+
client = genai.Client(api_key=api_key)
|
198 |
translation_prompt = f"""
|
199 |
Translate the following Korean text to English:
|
200 |
|
|
|
205 |
"""
|
206 |
|
207 |
logger.info(f"Translation prompt: {translation_prompt}")
|
208 |
+
response = client.generate_content(
|
209 |
+
model="gemini-2.0-flash",
|
210 |
+
contents=[translation_prompt],
|
211 |
+
generation_config=genai.types.GenerationConfig(
|
212 |
temperature=0.2,
|
213 |
top_p=0.95,
|
214 |
top_k=40,
|
|
|
216 |
)
|
217 |
)
|
218 |
|
219 |
+
translated_text = ""
|
220 |
+
for part in response.text:
|
221 |
+
if hasattr(part, 'text') and part.text:
|
222 |
+
translated_text += part.text
|
223 |
|
224 |
if translated_text.strip():
|
225 |
translated_text = translated_text.replace("IMAGE_TAG_ONE", "#1")
|
|
|
290 |
|
291 |
def generate_with_images(prompt, images, variation_index=0):
|
292 |
try:
|
293 |
+
api_key = GEMINI_API_KEY
|
294 |
+
if not api_key:
|
295 |
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
296 |
|
297 |
+
client = genai.Client(api_key=api_key)
|
298 |
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}, ๋ณํ ์ธ๋ฑ์ค: {variation_index}")
|
299 |
|
300 |
variation_suffixes = [
|
|
|
315 |
contents.append(img)
|
316 |
logger.info(f"์ด๋ฏธ์ง #{idx} ์ถ๊ฐ๋จ")
|
317 |
|
318 |
+
response = client.generate_content(
|
319 |
+
model="gemini-2.0-flash-exp-image-generation",
|
320 |
contents=contents,
|
321 |
+
generation_config=genai.types.GenerationConfig(
|
322 |
+
response_modalities=['Text', 'Image'],
|
323 |
temperature=1,
|
324 |
top_p=0.95,
|
325 |
top_k=40,
|
|
|
331 |
temp_path = tmp.name
|
332 |
result_text = ""
|
333 |
image_found = False
|
334 |
+
for part in response.candidates[0].content.parts:
|
335 |
+
if hasattr(part, 'text') and part.text:
|
336 |
+
result_text += part.text
|
337 |
+
logger.info(f"์๋ต ํ
์คํธ: {part.text}")
|
338 |
+
elif hasattr(part, 'inline_data') and part.inline_data:
|
339 |
+
save_binary_file(temp_path, part.inline_data.data)
|
340 |
+
image_found = True
|
341 |
+
logger.info("์๋ต์์ ์ด๋ฏธ์ง ์ถ์ถ ์ฑ๊ณต")
|
|
|
|
|
|
|
|
|
|
|
342 |
if not image_found:
|
343 |
return None, f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์๋ต ํ
์คํธ: {result_text}"
|
|
|
344 |
result_img = Image.open(temp_path)
|
345 |
if result_img.mode == "RGBA":
|
346 |
result_img = result_img.convert("RGB")
|
|
|
347 |
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}"
|
348 |
except Exception as e:
|
349 |
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
|
|
429 |
return results[0], results[1], results[2], results[3], combined_status, combined_prompts
|
430 |
|
431 |
def create_app():
|
432 |
+
with gr.Blocks(title="์ด๋ฏธ์ง ์์ฑ ์ ํ๋ฆฌ์ผ์ด์
") as demo:
|
433 |
+
gr.Markdown("# ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ํ๋กฌํํธ ์์ฑ๊ธฐ & ์ด๋ฏธ์ง ์์ฑ๊ธฐ")
|
434 |
+
gr.Markdown("์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ์ต์
์ ์ ํํ๋ฉด ๊ณ ํ์ง ์์
์ฉ ํ๋กฌํํธ๊ฐ ์์ฑ๋๊ณ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ฉ๋๋ค.")
|
435 |
|
436 |
+
# ์ํ๋ช
์น์
|
437 |
with gr.Row():
|
438 |
+
product_name = gr.Textbox(label="์ํ๋ช
(ํ๊ตญ์ด ์
๋ ฅ)", placeholder="์: ์คํจ์ผ์ด ํ๋ธ, ํ
๋ธ๋ฌ ๋ฑ", interactive=True)
|
439 |
+
|
440 |
+
# ๋ฐฐ๊ฒฝ ์ ํ์ ์ ํํ๊ธฐ ์ํ ๋ผ๋์ค ๋ฒํผ
|
441 |
+
background_type = gr.Radio(
|
442 |
+
choices=["์ฌํ ๋ฐฐ๊ฒฝ", "์คํ๋์ค ๋ฐฐ๊ฒฝ", "์์ฐ ํ๊ฒฝ", "์ค๋ด ํ๊ฒฝ", "์ถ์/ํน์ ๋ฐฐ๊ฒฝ"],
|
443 |
+
label="๋ฐฐ๊ฒฝ ์ ํ",
|
444 |
+
value="์ฌํ ๋ฐฐ๊ฒฝ"
|
445 |
+
)
|
446 |
+
|
447 |
+
# ๊ฐ ๋ฐฐ๊ฒฝ ์ ํ์ ๋ง๋ ๋๋กญ๋ค์ด ์ปดํฌ๋ํธ๋ค (์ฒ์์๋ ์ฌํ ๋ฐฐ๊ฒฝ๋ง ํ์)
|
448 |
+
with gr.Row():
|
449 |
+
# ์ข์ธก ์ปฌ๋ผ - ์
๋ ฅ ์ปจํธ๋กค
|
450 |
+
with gr.Column(scale=1):
|
451 |
+
image_input = gr.Image(label="์ํ ์ด๋ฏธ์ง ์
๋ก๋", type="pil")
|
452 |
|
453 |
# ์ฌํ ๋ฐฐ๊ฒฝ ์ ํ ๋๋กญ๋ค์ด
|
454 |
simple_dropdown = gr.Dropdown(
|
|
|
477 |
interactive=True
|
478 |
)
|
479 |
|
480 |
+
# ์ค๋ด ํ๊ฒฝ ์ ํ ๋๋กญ๋ค์ด
|
481 |
indoor_dropdown = gr.Dropdown(
|
482 |
choices=list(INDOOR_BACKGROUNDS.keys()),
|
483 |
value=list(INDOOR_BACKGROUNDS.keys())[0] if INDOOR_BACKGROUNDS else None,
|
|
|
495 |
interactive=True
|
496 |
)
|
497 |
|
498 |
+
# ์ด๋ฏธ์ง ์
๋ ฅ ์ปดํฌ๋ํธ (์ฐธ์กฐ ์ด๋ฏธ์ง์ฉ)
|
499 |
+
gr.Markdown("## ์ถ๊ฐ ์ฐธ์กฐ ์ด๋ฏธ์ง (์ต์
)")
|
500 |
+
image2_input = gr.Image(label="์ฐธ์กฐ ์ด๋ฏธ์ง #2 (์ ํ์ฌํญ)", type="pil", image_mode="RGB")
|
501 |
+
image3_input = gr.Image(label="์ฐธ์กฐ ์ด๋ฏธ์ง #3 (์ ํ์ฌํญ)", type="pil", image_mode="RGB")
|
502 |
|
503 |
# ์ถ๊ฐ ์์ฒญ์ฌํญ
|
504 |
additional_info = gr.Textbox(
|
505 |
label="์ถ๊ฐ ์์ฒญ์ฌํญ (์ ํ์ฌํญ)",
|
506 |
placeholder="์: ๊ณ ๊ธ์ค๋ฌ์ด ๋๋, ๋ฐ์ ์กฐ๋ช
, ์์ฐ์ค๋ฌ์ด ๋ณด์กฐ์ ์ธ ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์ ๋ฑ",
|
507 |
+
lines=3,
|
508 |
+
interactive=True
|
509 |
)
|
510 |
|
511 |
+
# ๋ฒํผ ์์ญ
|
512 |
+
with gr.Row():
|
513 |
+
generate_prompt_btn = gr.Button("ํ๋กฌํํธ ์์ฑ")
|
514 |
+
submit_single_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ (1์ฅ)")
|
515 |
+
submit_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ (4์ฅ)")
|
516 |
|
517 |
+
# ์ฐ์ธก ์ปฌ๋ผ - ์ถ๏ฟฝ๏ฟฝ ๊ฒฐ๊ณผ
|
518 |
+
with gr.Column(scale=1):
|
519 |
+
prompt_output = gr.Textbox(label="์์ฑ๋ ํ๋กฌํํธ", lines=10)
|
520 |
|
521 |
+
# ์ด๋ฏธ์ง ์ถ๋ ฅ ์์ญ
|
522 |
+
gr.Markdown("## ์์ฑ๋ ์ด๋ฏธ์ง")
|
523 |
with gr.Row():
|
524 |
+
output_image1 = gr.Image(label="์ด๋ฏธ์ง #1", type="pil")
|
525 |
+
output_image2 = gr.Image(label="์ด๋ฏธ์ง #2", type="pil")
|
526 |
+
with gr.Row():
|
527 |
+
output_image3 = gr.Image(label="์ด๋ฏธ์ง #3", type="pil")
|
528 |
+
output_image4 = gr.Image(label="์ด๋ฏธ์ง #4", type="pil")
|
529 |
+
|
530 |
+
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง", lines=2)
|
531 |
+
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True, lines=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
|
533 |
# ๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ผ ๋๋กญ๋ค์ด ํ์ ์
๋ฐ์ดํธ
|
534 |
def update_dropdowns(bg_type):
|
|
|
567 |
"name": nature,
|
568 |
"english": NATURE_BACKGROUNDS.get(nature, "natural environment")
|
569 |
}
|
570 |
+
elif bg_type == "์ค๋ด ํ๊ฒฝ":
|
571 |
return {
|
572 |
"category": "์ค๋ด ํ๊ฒฝ",
|
573 |
"name": indoor,
|
|
|
587 |
}
|
588 |
|
589 |
# ํ๋กฌํํธ ์์ฑ ํจ์
|
590 |
+
def generate_prompt(bg_type, simple, studio, nature, indoor, abstract, product_text, additional_text):
|
591 |
+
if not product_text.strip():
|
592 |
+
product_text = "์ ํ"
|
|
|
|
|
|
|
593 |
|
594 |
# ๋ฐฐ๊ฒฝ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
595 |
background_info = get_selected_background_info(bg_type, simple, studio, nature, indoor, abstract)
|
|
|
606 |
2. ์ฝ๋ ๋ด ์ง์ ์
๋ ฅ: GEMINI_API_KEY = "your-api-key"
|
607 |
ํค ๋ฐ๊ธ: https://makersuite.google.com/
|
608 |
"""
|
|
|
609 |
|
610 |
return prompt
|
611 |
except Exception as e:
|
|
|
613 |
gr.Error(error_msg)
|
614 |
return error_msg
|
615 |
|
616 |
+
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
generate_prompt_btn.click(
|
618 |
fn=generate_prompt,
|
619 |
inputs=[
|
|
|
620 |
background_type,
|
621 |
simple_dropdown,
|
622 |
studio_dropdown,
|
|
|
629 |
outputs=prompt_output
|
630 |
)
|
631 |
|
632 |
+
# ๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
633 |
+
submit_single_btn.click(
|
634 |
+
fn=lambda image1, image2, image3, prompt: process_images_with_prompt(image1, image2, image3, prompt, 0),
|
635 |
+
inputs=[image_input, image2_input, image3_input, prompt_output],
|
636 |
+
outputs=[output_image1, output_text, prompt_display],
|
637 |
)
|
638 |
|
639 |
+
# 4์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
640 |
+
submit_btn.click(
|
641 |
+
fn=generate_multiple_images,
|
642 |
+
inputs=[image_input, image2_input, image3_input, prompt_output],
|
643 |
+
outputs=[output_image1, output_image2, output_image3, output_image4, output_text, prompt_display],
|
644 |
)
|
645 |
|
646 |
return demo
|