Files changed (1) hide show
  1. app.py +31 -44
app.py CHANGED
@@ -37,51 +37,53 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
37
  )
38
  return response.choices[0].message['content'].strip()
39
 
40
- # 1์ฐจ/2์ฐจ ์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒ ๊ธฐ๋Šฅ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
41
- def generate_category_prompt(object_input, category, background):
42
- # ์‚ฌ๋ฌผ์„ ์˜์–ด๋กœ ๋ฒˆ์—ญ
43
- system_message_object = "Translate the following object description from Korean to English. Keep it simple and concise."
44
- translated_object = call_api(object_input, system_message_object, max_tokens=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- # ์„ ํƒ๋œ ๋ฐฐ๊ฒฝ์„ ์˜์–ด๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
 
 
 
 
 
 
 
 
47
  background_english = next(
48
  (item["english"] for item in categories.get(category, []) if item["korean"] == background),
49
  ""
50
  )
51
-
52
- # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
53
  if translated_object and background_english:
54
  return f"advertisement photography, {translated_object} {background_english}."
55
  else:
56
  return "Error: Please ensure both object and background are provided correctly."
57
 
58
- # ๊ธฐ์กด ๊ธฐ๋Šฅ: ๋žœ๋ค ๋ฐฐ๊ฒฝ ์ƒ์„ฑ
59
- def generate_random_background(object_input):
60
- # ์‚ฌ๋ฌผ์„ ์˜์–ด๋กœ ๋ฒˆ์—ญ
61
- system_message_object = "Translate the following object description from Korean to English. Keep it simple and concise."
62
- translated_object = call_api(object_input, system_message_object, max_tokens=10)
63
-
64
- # ๋žœ๋ค ๋ฐฐ๊ฒฝ ์ƒ์„ฑ
65
- system_message_background = (
66
- "You are an AI that generates concise and natural background descriptions for objects in advertisement photography. "
67
- "Generate only the background description and do not include 'advertisement photography' in your output. "
68
- "Example 1: 'on a sunny summer beach.' "
69
- "Example 2: 'on a clean wooden table near a garden.' "
70
- f"Now generate a short background description for: '{translated_object}'."
71
- )
72
- background_prompt = call_api(translated_object, system_message_background, max_tokens=20)
73
-
74
- # ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ
75
- return f"advertisement photography, {translated_object} {background_prompt}"
76
-
77
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
78
  with gr.Blocks() as demo:
79
  with gr.Tab("์ง์ ‘ ๋ฐฐ๊ฒฝ ์ž…๋ ฅ"):
80
- gr.Markdown("### ํ•œ๊ตญ์–ด ์ด๋ฏธ์ง€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์˜์–ด๋กœ ๋ณ€ํ™˜ (์ง์ ‘ ๋ฐฐ๊ฒฝ ์ž…๋ ฅ)")
81
 
82
  with gr.Row():
83
  object_input = gr.Textbox(label="์‚ฌ๋ฌผ ์ž…๋ ฅ", placeholder="์˜ˆ: ์˜ค๋ Œ์ง€ ์ฃผ์Šค")
84
- background_input = gr.Textbox(label="๋ฐฐ๊ฒฝ ์ž…๋ ฅ", placeholder="์˜ˆ: ๊นจ๋—ํ•œ ์ฃผ๋ฐฉ (์ง์ ‘ ์ž…๋ ฅ)")
85
  output = gr.Textbox(label="์ƒ์„ฑ๋œ ์˜์–ด ํ”„๋กฌํ”„ํŠธ")
86
 
87
  generate_button = gr.Button("ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ")
@@ -107,7 +109,6 @@ with gr.Blocks() as demo:
107
  interactive=True
108
  )
109
 
110
- # 1์ฐจ ์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒ ์‹œ 2์ฐจ ๋ฐฐ๊ฒฝ ๋ชฉ๋ก ์—…๋ฐ์ดํŠธ
111
  def update_background_options(category):
112
  if category in categories:
113
  return gr.update(choices=[item["korean"] for item in categories[category]], value=None)
@@ -129,18 +130,4 @@ with gr.Blocks() as demo:
129
  outputs=category_prompt_output
130
  )
131
 
132
- with gr.Tab("๋žœ๋ค ๋ฐฐ๊ฒฝ ์ƒ์„ฑ"):
133
- gr.Markdown("### ํ•œ๊ตญ์–ด ์ด๋ฏธ์ง€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์˜์–ด๋กœ ๋ณ€ํ™˜ (๋žœ๋ค ๋ฐฐ๊ฒฝ ์ƒ์„ฑ)")
134
-
135
- with gr.Row():
136
- object_input = gr.Textbox(label="์‚ฌ๋ฌผ ์ž…๋ ฅ", placeholder="์˜ˆ: ์˜ค๋ Œ์ง€ ์ฃผ์Šค")
137
- random_background_output = gr.Textbox(label="์ž๋™ ์ƒ์„ฑ๋œ ์˜์–ด ํ”„๋กฌํ”„ํŠธ")
138
-
139
- random_generate_button = gr.Button("๋žœ๋ค ๋ฐฐ๊ฒฝ ์ƒ์„ฑ")
140
- random_generate_button.click(
141
- fn=generate_random_background,
142
- inputs=object_input,
143
- outputs=random_background_output
144
- )
145
-
146
  demo.launch()
 
37
  )
38
  return response.choices[0].message['content'].strip()
39
 
40
+ # ์‚ฌ๋ฌผ ๋ฐ ๋ฐฐ๊ฒฝ ๋ฒˆ์—ญ ํ•จ์ˆ˜
41
+ def translate_object(object_input):
42
+ system_message = "Translate the following object description from Korean to English. Keep it simple and concise."
43
+ return call_api(
44
+ content=object_input,
45
+ system_message=system_message,
46
+ max_tokens=10,
47
+ temperature=0.7,
48
+ top_p=1.0
49
+ )
50
+
51
+ def translate_background(background_input):
52
+ system_message = "Translate the following background description from Korean to English. Keep it simple and concise."
53
+ return call_api(
54
+ content=background_input,
55
+ system_message=system_message,
56
+ max_tokens=20,
57
+ temperature=0.7,
58
+ top_p=1.0
59
+ )
60
 
61
+ # ์ง์ ‘ ๋ฐฐ๊ฒฝ ์ž…๋ ฅ ํƒญ์˜ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ•จ์ˆ˜
62
+ def generate_prompt(object_input, background_input):
63
+ translated_object = translate_object(object_input)
64
+ translated_background = translate_background(background_input)
65
+ return f"advertisement photography, {translated_object} {translated_background}"
66
+
67
+ # 1์ฐจ/2์ฐจ ์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒ ํƒญ์˜ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ํ•จ์ˆ˜
68
+ def generate_category_prompt(object_input, category, background):
69
+ translated_object = translate_object(object_input)
70
  background_english = next(
71
  (item["english"] for item in categories.get(category, []) if item["korean"] == background),
72
  ""
73
  )
 
 
74
  if translated_object and background_english:
75
  return f"advertisement photography, {translated_object} {background_english}."
76
  else:
77
  return "Error: Please ensure both object and background are provided correctly."
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
80
  with gr.Blocks() as demo:
81
  with gr.Tab("์ง์ ‘ ๋ฐฐ๊ฒฝ ์ž…๋ ฅ"):
82
+ gr.Markdown("### ์ง์ ‘ ๋ฐฐ๊ฒฝ ์ž…๋ ฅ์„ ํ†ตํ•œ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ")
83
 
84
  with gr.Row():
85
  object_input = gr.Textbox(label="์‚ฌ๋ฌผ ์ž…๋ ฅ", placeholder="์˜ˆ: ์˜ค๋ Œ์ง€ ์ฃผ์Šค")
86
+ background_input = gr.Textbox(label="๋ฐฐ๊ฒฝ ์ž…๋ ฅ", placeholder="์˜ˆ: ๊นจ๋—ํ•œ ์ฃผ๋ฐฉ")
87
  output = gr.Textbox(label="์ƒ์„ฑ๋œ ์˜์–ด ํ”„๋กฌํ”„ํŠธ")
88
 
89
  generate_button = gr.Button("ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ")
 
109
  interactive=True
110
  )
111
 
 
112
  def update_background_options(category):
113
  if category in categories:
114
  return gr.update(choices=[item["korean"] for item in categories[category]], value=None)
 
130
  outputs=category_prompt_output
131
  )
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  demo.launch()