openfree commited on
Commit
db55d24
โ€ข
1 Parent(s): 81a39a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -30
app.py CHANGED
@@ -30,27 +30,27 @@ def check_text(prompt, negative=""):
30
  # Kid-friendly styles
31
  style_list = [
32
  {
33
- "name": "Cartoon",
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": "Children's Illustration",
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": "Sticker",
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": "Fantasy",
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": "(No style)",
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 = "Sticker"
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 = """## Children's Sticker Generator
68
-
69
- Generate fun and playful stickers for children using AI.
70
  """
71
 
72
  if not torch.cuda.is_available():
73
- DESCRIPTION += "\n<p>โš ๏ธRunning on CPU, This may not work on CPU.</p>"
74
 
75
  MAX_SEED = np.iinfo(np.int32).max
76
- CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
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("Prompt contains restricted words.")
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="Enter your prompt",
209
  show_label=False,
210
  max_lines=1,
211
- placeholder="ํ”„๋กฌํ”„ํŠธ์— ์ž…๋ ฅ์„ ํ•˜์„ธ์š”.",
212
  container=False,
213
  )
214
- run_button = gr.Button("Run")
215
- result = gr.Gallery(label="Generated Stickers", columns=2, preview=True)
216
- with gr.Accordion("Advanced options", open=False):
217
- use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True, visible=True)
218
  negative_prompt = gr.Text(
219
- label="Negative prompt",
220
  max_lines=1,
221
- placeholder="Enter a negative prompt",
222
- value="(scary, violent, dark, ugly)",
223
  visible=True,
224
  )
225
  seed = gr.Slider(
226
- label="Seed",
227
  minimum=0,
228
  maximum=MAX_SEED,
229
  step=1,
230
  value=0,
231
  visible=True
232
  )
233
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
234
  size_selection = gr.Radio(
235
  choices=["75mm", "35mm"],
236
  value="75mm",
237
- label="Sticker Size",
238
  )
239
  style_selection = gr.Radio(
240
  choices=STYLE_NAMES,
241
  value=DEFAULT_STYLE_NAME,
242
- label="Image Style",
243
  )
244
  background_selection = gr.Radio(
245
- choices=["transparent", "white"],
246
- value="white",
247
- label="transparent",
248
  )
249
  guidance_scale = gr.Slider(
250
- label="Guidance Scale",
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,