Update app.py
Browse files
app.py
CHANGED
@@ -30,27 +30,27 @@ def check_text(prompt, negative=""):
|
|
30 |
# Kid-friendly styles
|
31 |
style_list = [
|
32 |
{
|
33 |
-
"name": "
|
34 |
"prompt": "colorful cartoon {prompt}. vibrant, playful, friendly, suitable for children, highly detailed, bright colors",
|
35 |
"negative_prompt": "scary, dark, violent, ugly, realistic",
|
36 |
},
|
37 |
{
|
38 |
-
"name": "
|
39 |
"prompt": "children's illustration {prompt}. cute, colorful, fun, simple shapes, smooth lines, highly detailed, joyful",
|
40 |
"negative_prompt": "scary, dark, violent, deformed, ugly",
|
41 |
},
|
42 |
{
|
43 |
-
"name": "
|
44 |
"prompt": "children's sticker of {prompt}. bright colors, playful, high resolution, cartoonish",
|
45 |
"negative_prompt": "scary, dark, violent, ugly, low resolution",
|
46 |
},
|
47 |
{
|
48 |
-
"name": "
|
49 |
"prompt": "fantasy world for children with {prompt}. magical, vibrant, friendly, beautiful, colorful",
|
50 |
"negative_prompt": "dark, scary, violent, ugly, realistic",
|
51 |
},
|
52 |
{
|
53 |
-
"name": "(
|
54 |
"prompt": "{prompt}",
|
55 |
"negative_prompt": "",
|
56 |
},
|
@@ -58,22 +58,21 @@ style_list = [
|
|
58 |
|
59 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
60 |
STYLE_NAMES = list(styles.keys())
|
61 |
-
DEFAULT_STYLE_NAME = "
|
62 |
|
63 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
64 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
65 |
return p.replace("{prompt}", positive), n + negative
|
66 |
|
67 |
-
DESCRIPTION = """##
|
68 |
-
|
69 |
-
Generate fun and playful stickers for children using AI.
|
70 |
"""
|
71 |
|
72 |
if not torch.cuda.is_available():
|
73 |
-
DESCRIPTION += "\n<p>โ ๏ธ
|
74 |
|
75 |
MAX_SEED = np.iinfo(np.int32).max
|
76 |
-
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "
|
77 |
|
78 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
79 |
|
@@ -149,7 +148,7 @@ def generate(
|
|
149 |
prompt = translate_if_korean(prompt)
|
150 |
|
151 |
if check_text(prompt, negative_prompt):
|
152 |
-
raise ValueError("
|
153 |
|
154 |
# Ensure prompt is 2-3 words long
|
155 |
prompt = " ".join(re.findall(r'\w+', prompt)[:3])
|
@@ -198,56 +197,55 @@ footer {
|
|
198 |
}
|
199 |
"""
|
200 |
|
201 |
-
|
202 |
# Define the Gradio UI for the sticker generator
|
203 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
204 |
|
205 |
with gr.Group():
|
206 |
with gr.Row():
|
207 |
prompt = gr.Text(
|
208 |
-
label="
|
209 |
show_label=False,
|
210 |
max_lines=1,
|
211 |
-
placeholder="
|
212 |
container=False,
|
213 |
)
|
214 |
-
run_button = gr.Button("
|
215 |
-
result = gr.Gallery(label="
|
216 |
-
with gr.Accordion("
|
217 |
-
use_negative_prompt = gr.Checkbox(label="
|
218 |
negative_prompt = gr.Text(
|
219 |
-
label="
|
220 |
max_lines=1,
|
221 |
-
placeholder="
|
222 |
-
value="(
|
223 |
visible=True,
|
224 |
)
|
225 |
seed = gr.Slider(
|
226 |
-
label="
|
227 |
minimum=0,
|
228 |
maximum=MAX_SEED,
|
229 |
step=1,
|
230 |
value=0,
|
231 |
visible=True
|
232 |
)
|
233 |
-
randomize_seed = gr.Checkbox(label="
|
234 |
size_selection = gr.Radio(
|
235 |
choices=["75mm", "35mm"],
|
236 |
value="75mm",
|
237 |
-
label="
|
238 |
)
|
239 |
style_selection = gr.Radio(
|
240 |
choices=STYLE_NAMES,
|
241 |
value=DEFAULT_STYLE_NAME,
|
242 |
-
label="
|
243 |
)
|
244 |
background_selection = gr.Radio(
|
245 |
-
choices=["
|
246 |
-
value="
|
247 |
-
label="
|
248 |
)
|
249 |
guidance_scale = gr.Slider(
|
250 |
-
label="
|
251 |
minimum=0.1,
|
252 |
maximum=20.0,
|
253 |
step=0.1,
|
|
|
30 |
# Kid-friendly styles
|
31 |
style_list = [
|
32 |
{
|
33 |
+
"name": "๋งํ",
|
34 |
"prompt": "colorful cartoon {prompt}. vibrant, playful, friendly, suitable for children, highly detailed, bright colors",
|
35 |
"negative_prompt": "scary, dark, violent, ugly, realistic",
|
36 |
},
|
37 |
{
|
38 |
+
"name": "์ด๋ฆฐ์ด ์ผ๋ฌ์คํธ",
|
39 |
"prompt": "children's illustration {prompt}. cute, colorful, fun, simple shapes, smooth lines, highly detailed, joyful",
|
40 |
"negative_prompt": "scary, dark, violent, deformed, ugly",
|
41 |
},
|
42 |
{
|
43 |
+
"name": "์คํฐ์ปค",
|
44 |
"prompt": "children's sticker of {prompt}. bright colors, playful, high resolution, cartoonish",
|
45 |
"negative_prompt": "scary, dark, violent, ugly, low resolution",
|
46 |
},
|
47 |
{
|
48 |
+
"name": "ํํ์ง",
|
49 |
"prompt": "fantasy world for children with {prompt}. magical, vibrant, friendly, beautiful, colorful",
|
50 |
"negative_prompt": "dark, scary, violent, ugly, realistic",
|
51 |
},
|
52 |
{
|
53 |
+
"name": "(์คํ์ผ ์์)",
|
54 |
"prompt": "{prompt}",
|
55 |
"negative_prompt": "",
|
56 |
},
|
|
|
58 |
|
59 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
60 |
STYLE_NAMES = list(styles.keys())
|
61 |
+
DEFAULT_STYLE_NAME = "์คํฐ์ปค"
|
62 |
|
63 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
64 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
65 |
return p.replace("{prompt}", positive), n + negative
|
66 |
|
67 |
+
DESCRIPTION = """## ์ด๋ฆฐ์ด ์คํฐ์ปค ์์ฑ๊ธฐ
|
68 |
+
AI๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ๋ฏธ์๊ณ ๊ท์ฌ์ด ์ด๋ฆฐ์ด ์คํฐ์ปค๋ฅผ ์์ฑํฉ๋๋ค.
|
|
|
69 |
"""
|
70 |
|
71 |
if not torch.cuda.is_available():
|
72 |
+
DESCRIPTION += "\n<p>โ ๏ธCPU์์ ์คํ ์ค์
๋๋ค. CPU์์๋ ์ ๋๋ก ์๋ํ์ง ์์ ์ ์์ต๋๋ค.</p>"
|
73 |
|
74 |
MAX_SEED = np.iinfo(np.int32).max
|
75 |
+
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "1") == "1"
|
76 |
|
77 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
78 |
|
|
|
148 |
prompt = translate_if_korean(prompt)
|
149 |
|
150 |
if check_text(prompt, negative_prompt):
|
151 |
+
raise ValueError("ํ๋กฌํํธ์ ์ ํ๋ ๋จ์ด๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.")
|
152 |
|
153 |
# Ensure prompt is 2-3 words long
|
154 |
prompt = " ".join(re.findall(r'\w+', prompt)[:3])
|
|
|
197 |
}
|
198 |
"""
|
199 |
|
|
|
200 |
# Define the Gradio UI for the sticker generator
|
201 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
202 |
|
203 |
with gr.Group():
|
204 |
with gr.Row():
|
205 |
prompt = gr.Text(
|
206 |
+
label="ํ๋กฌํํธ ์
๋ ฅ",
|
207 |
show_label=False,
|
208 |
max_lines=1,
|
209 |
+
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ์ธ์.",
|
210 |
container=False,
|
211 |
)
|
212 |
+
run_button = gr.Button("์คํ")
|
213 |
+
result = gr.Gallery(label="์์ฑ๋ ์คํฐ์ปค", columns=2, preview=True)
|
214 |
+
with gr.Accordion("๊ณ ๊ธ ์ต์
", open=False):
|
215 |
+
use_negative_prompt = gr.Checkbox(label="๋ค๊ฑฐํฐ๋ธ ํ๋กฌํํธ ์ฌ์ฉ", value=True, visible=True)
|
216 |
negative_prompt = gr.Text(
|
217 |
+
label="๋ค๊ฑฐํฐ๋ธ ํ๋กฌํํธ",
|
218 |
max_lines=1,
|
219 |
+
placeholder="๋ค๊ฑฐํฐ๋ธ ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ์ธ์",
|
220 |
+
value="(๋ฌด์์ด, ํญ๋ ฅ์ ์ธ, ์ด๋์ด, ์ถํ)",
|
221 |
visible=True,
|
222 |
)
|
223 |
seed = gr.Slider(
|
224 |
+
label="์๋",
|
225 |
minimum=0,
|
226 |
maximum=MAX_SEED,
|
227 |
step=1,
|
228 |
value=0,
|
229 |
visible=True
|
230 |
)
|
231 |
+
randomize_seed = gr.Checkbox(label="๋๋ค ์๋", value=True)
|
232 |
size_selection = gr.Radio(
|
233 |
choices=["75mm", "35mm"],
|
234 |
value="75mm",
|
235 |
+
label="์คํฐ์ปค ํฌ๊ธฐ",
|
236 |
)
|
237 |
style_selection = gr.Radio(
|
238 |
choices=STYLE_NAMES,
|
239 |
value=DEFAULT_STYLE_NAME,
|
240 |
+
label="์ด๋ฏธ์ง ์คํ์ผ",
|
241 |
)
|
242 |
background_selection = gr.Radio(
|
243 |
+
choices=["ํฌ๋ช
", "ํฐ์"],
|
244 |
+
value="ํฐ์",
|
245 |
+
label="๋ฐฐ๊ฒฝ์",
|
246 |
)
|
247 |
guidance_scale = gr.Slider(
|
248 |
+
label="๊ฐ์ด๋์ค ์ค์ผ์ผ",
|
249 |
minimum=0.1,
|
250 |
maximum=20.0,
|
251 |
step=0.1,
|