Spaces:
Running
Running
Update app.py
#1
by
ssboost
- opened
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 |
-
#
|
41 |
-
def
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|