Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,101 +1,116 @@
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
"
|
7 |
-
"
|
8 |
]
|
9 |
-
|
10 |
-
"
|
11 |
-
"
|
12 |
-
"beside a sparkling river", "at a mushroom village", "inside a glowing cave", "on a giant lily pad"
|
13 |
]
|
14 |
-
|
15 |
-
"
|
16 |
-
"
|
17 |
-
"
|
18 |
]
|
19 |
-
|
20 |
-
"
|
21 |
-
"
|
22 |
]
|
23 |
-
|
24 |
-
"
|
25 |
-
"
|
26 |
-
|
27 |
-
|
|
|
28 |
]
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
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 |
-
|
44 |
-
custom_css = """
|
45 |
body {
|
46 |
-
background-color: #
|
47 |
-
font-family: "Comic Sans MS",
|
48 |
}
|
49 |
|
50 |
#title {
|
|
|
51 |
text-align: center;
|
52 |
-
|
53 |
margin-top: 20px;
|
54 |
-
|
55 |
font-weight: bold;
|
56 |
}
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
color: #333;
|
61 |
-
margin-bottom: 20px;
|
62 |
}
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
#prompt-box {
|
65 |
-
font-size:
|
66 |
-
|
|
|
|
|
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=
|
76 |
-
gr.Markdown("<h1 id='title'>ZenityX
|
77 |
-
gr.Markdown(
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
#
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
-
#
|
88 |
-
|
89 |
-
label="Dream Prompt",
|
90 |
-
interactive=False,
|
91 |
-
elem_id="prompt-box"
|
92 |
-
)
|
93 |
|
94 |
-
#
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
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()
|