zenityx commited on
Commit
da69ff5
·
verified ·
1 Parent(s): ef03112

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -70
app.py CHANGED
@@ -1,101 +1,116 @@
1
  import gradio as gr
2
- import random
3
 
4
- # ----- 1) กำหนดหมวดต่าง ๆ -----
5
- characters = [
6
- "shy kitten", "brave puppy", "tiny fairy", "silly robot", "kind princess",
7
- "friendly dragon", "playful elf", "curious mermaid", "gentle unicorn", "happy ninja"
8
  ]
9
- places = [
10
- "in a fluffy cloud kingdom", "on a giant rainbow slide", "inside a magical treehouse",
11
- "near a crystal waterfall", "in a cotton-candy land", "on a floating island",
12
- "beside a sparkling river", "at a mushroom village", "inside a glowing cave", "on a giant lily pad"
13
  ]
14
- activities = [
15
- "singing a funny song", "dancing with butterflies", "riding a magical bike",
16
- "painting colorful stars", "telling hilarious jokes", "juggling shining orbs",
17
- "building candy houses", "playing hide-and-seek", "collecting glowing gems", "spinning in circles"
18
  ]
19
- styles = [
20
- "cartoon style", "pastel style", "watercolor style", "3D clay style", "pixel art style",
21
- "comic style", "chibi style", "neon style", "storybook style", "fantasy style"
22
  ]
23
- weirds = [
24
- "with giant lollipops", "surrounded by friendly ghosts", "while time is frozen",
25
- "under a raining confetti sky", "next to floating musical notes",
26
- "with oversized flowers", "where everything is upside down",
27
- "in a world without gravity", "amidst talking clouds", "inside a giant soap bubble"
 
28
  ]
29
 
30
- # ----- 2) ฟังก์ชันสร้าง Prompt -----
31
- def spin_the_wheel():
32
- c = random.choice(characters)
33
- p = random.choice(places)
34
- a = random.choice(activities)
35
- s = random.choice(styles)
36
- w = random.choice(weirds)
37
-
38
- # โครงสร้างประโยค
39
- # "Behold a [character], [activity] [place] in [style] [weird]!"
40
- prompt = f"Behold a {c}, {a} {p} in {s} {w}!"
41
  return prompt
42
 
43
- # ----- 3) สร้าง UI Gradio -----
44
- custom_css = """
45
  body {
46
- background-color: #FFFEE0;
47
- font-family: "Comic Sans MS", "Comic Sans", cursive;
48
  }
49
 
50
  #title {
 
51
  text-align: center;
52
- color: #FF6F91;
53
  margin-top: 20px;
54
- font-size: 2.2rem;
55
  font-weight: bold;
56
  }
57
-
58
- #subtitle {
59
- text-align: center;
 
 
 
 
60
  color: #333;
61
- margin-bottom: 20px;
62
  }
63
-
 
 
 
 
 
 
 
 
 
 
64
  #prompt-box {
65
- font-size: 20px;
66
- min-height: 60px;
 
 
67
  padding: 10px;
68
- text-align: center;
69
- border: 2px solid #FFB74D;
70
- border-radius: 12px;
71
- background-color: #FFF3E0;
72
  }
73
  """
74
 
75
- with gr.Blocks(css=custom_css) as demo:
76
- gr.Markdown("<h1 id='title'>ZenityX Dream Explorers</h1>")
77
- gr.Markdown("""
78
- <p id='subtitle'>
79
- สวัสดีจ้า หนูน้อย! พร้อมหรือยังที่จะหมุนวงล้อ<br>
80
- เพื่อสร้าง Prompt สุดแฟนตาซีสำหรับ AI เจนภาพ?
81
- </p>
82
- """)
 
 
 
 
83
 
84
- # ปุ่ม Spin
85
- spin_btn = gr.Button("Spin the Wheel!")
 
 
 
 
 
86
 
87
- # กล่องแสดง Prompt
88
- prompt_output = gr.Textbox(
89
- label="Dream Prompt",
90
- interactive=False,
91
- elem_id="prompt-box"
92
- )
93
 
94
- # Event: เมื่อกดปุ่ม -> สร้าง Prompt
95
- spin_btn.click(
96
- fn=spin_the_wheel,
97
- inputs=[],
98
- outputs=prompt_output
 
 
 
99
  )
100
 
101
  demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ # หมวดหมู่ต่าง พร้อมตัวเลือก (ตัวอย่าง)
4
+ body_shapes = [
5
+ "slimy blob body", "furry ball body", "spiky ogre body",
6
+ "tiny insect body", "floating jelly body"
7
  ]
8
+ heads = [
9
+ "one-eyed head", "two-headed dragon skull", "giant horned head",
10
+ "smiling ghost face", "cute bunny ears head"
 
11
  ]
12
+ arms_legs = [
13
+ "tentacle arms and octopus legs", "mechanical arms and roller-skate feet",
14
+ "feathered wings and lion paws", "glowing hands and hoverboard legs",
15
+ "wooden puppet arms and spider legs"
16
  ]
17
+ skin_patterns = [
18
+ "rainbow stripes", "glowing purple spots", "metallic scales",
19
+ "sparkling feathers", "glittery polka dots"
20
  ]
21
+ abilities = [
22
+ "breathing fire", "shooting bubbles", "controlling lightning",
23
+ "singing lullabies", "teleporting short distances"
24
+ ]
25
+ moods = [
26
+ "friendly", "grumpy", "silly", "mischievous", "shy"
27
  ]
28
 
29
+ def generate_monster_prompt(body, head, arms, skin, ability, mood):
30
+ """
31
+ สร้างประโยค (Prompt) บรรยายมอนสเตอร์ตามตัวเลือกที่เด็กเลือก
32
+ """
33
+ prompt = (
34
+ f"This is a {mood} monster with a {body}, a {head}, "
35
+ f"{arms}, covered in {skin} skin, and it can {ability}!"
36
+ )
 
 
 
37
  return prompt
38
 
39
+ css_code = """
 
40
  body {
41
+ background-color: #FFFCF2;
42
+ font-family: "Comic Sans MS", cursive;
43
  }
44
 
45
  #title {
46
+ color: #F96C85;
47
  text-align: center;
48
+ font-size: 2.1rem;
49
  margin-top: 20px;
50
+ margin-bottom: 10px;
51
  font-weight: bold;
52
  }
53
+ .game-desc {
54
+ margin: 0 auto;
55
+ width: 80%;
56
+ background-color: #FFF2F0;
57
+ border: 2px dashed #FAB1A0;
58
+ border-radius: 10px;
59
+ padding: 15px;
60
  color: #333;
 
61
  }
62
+ .monster-btn {
63
+ background-color: #FFB74D;
64
+ border: 2px solid #FFA726;
65
+ font-weight: bold;
66
+ font-size: 1.1rem;
67
+ padding: 10px 20px;
68
+ border-radius: 10px;
69
+ }
70
+ .monster-btn:hover {
71
+ background-color: #FFD180;
72
+ }
73
  #prompt-box {
74
+ font-size: 18px;
75
+ background-color: #FFF8E1;
76
+ border: 2px solid #FFE0B2;
77
+ border-radius: 10px;
78
  padding: 10px;
 
 
 
 
79
  }
80
  """
81
 
82
+ with gr.Blocks(css=css_code) as demo:
83
+ gr.Markdown("<h1 id='title'>ZenityX Monster Lab</h1>")
84
+ gr.Markdown(
85
+ """
86
+ <div class="game-desc">
87
+ <p>ยินดีต้อนรับจ้า หนูน้อยนักทดลอง! ที่นี่คือห้องทดลองลับของ ZenityX!</p>
88
+ <p>มาออกแบบมอนสเตอร์กันเถอะ: เลือกรูปร่าง, หัว, แขนขา, สีผิว, พลังพิเศษ,
89
+ และอารมณ์สุดเพี้ยน. จากนั้นกดปุ่ม <strong>"Activate Lab!"</strong></p>
90
+ <p>ลองดูสิ ว่ามอนสเตอร์ของหนูน้อยจะออกมาเป็นแบบไหน?</p>
91
+ </div>
92
+ """
93
+ )
94
 
95
+ # ส่วนเลือกค่าแต่ละหมวด
96
+ body_dropdown = gr.Dropdown(label="Body Shape", choices=body_shapes, value=body_shapes[0])
97
+ head_dropdown = gr.Dropdown(label="Head & Face", choices=heads, value=heads[0])
98
+ arms_dropdown = gr.Dropdown(label="Arms & Legs", choices=arms_legs, value=arms_legs[0])
99
+ skin_dropdown = gr.Dropdown(label="Skin Color / Pattern", choices=skin_patterns, value=skin_patterns[0])
100
+ ability_dropdown = gr.Dropdown(label="Special Ability", choices=abilities, value=abilities[0])
101
+ mood_dropdown = gr.Dropdown(label="Mood / Personality", choices=moods, value=moods[0])
102
 
103
+ # ปุ่มกด
104
+ create_button = gr.Button("Activate Lab!", elem_classes="monster-btn")
 
 
 
 
105
 
106
+ # ช่องแสดงผล Prompt
107
+ monster_prompt_out = gr.Textbox(label="Your Monster Prompt", interactive=False, elem_id="prompt-box")
108
+
109
+ # เมื่อกดปุ่ม -> สร้าง Prompt
110
+ create_button.click(
111
+ fn=generate_monster_prompt,
112
+ inputs=[body_dropdown, head_dropdown, arms_dropdown, skin_dropdown, ability_dropdown, mood_dropdown],
113
+ outputs=monster_prompt_out
114
  )
115
 
116
  demo.launch()