Spaces:
Sleeping
Sleeping
import gradio as gr | |
import random | |
# ----- 1) กำหนดหมวดต่าง ๆ ----- | |
characters = [ | |
"shy kitten", "brave puppy", "tiny fairy", "silly robot", "kind princess", | |
"friendly dragon", "playful elf", "curious mermaid", "gentle unicorn", "happy ninja" | |
] | |
places = [ | |
"in a fluffy cloud kingdom", "on a giant rainbow slide", "inside a magical treehouse", | |
"near a crystal waterfall", "in a cotton-candy land", "on a floating island", | |
"beside a sparkling river", "at a mushroom village", "inside a glowing cave", "on a giant lily pad" | |
] | |
activities = [ | |
"singing a funny song", "dancing with butterflies", "riding a magical bike", | |
"painting colorful stars", "telling hilarious jokes", "juggling shining orbs", | |
"building candy houses", "playing hide-and-seek", "collecting glowing gems", "spinning in circles" | |
] | |
styles = [ | |
"cartoon style", "pastel style", "watercolor style", "3D clay style", "pixel art style", | |
"comic style", "chibi style", "neon style", "storybook style", "fantasy style" | |
] | |
weirds = [ | |
"with giant lollipops", "surrounded by friendly ghosts", "while time is frozen", | |
"under a raining confetti sky", "next to floating musical notes", | |
"with oversized flowers", "where everything is upside down", | |
"in a world without gravity", "amidst talking clouds", "inside a giant soap bubble" | |
] | |
# ----- 2) ฟังก์ชันสร้าง Prompt ----- | |
def spin_the_wheel(): | |
c = random.choice(characters) | |
p = random.choice(places) | |
a = random.choice(activities) | |
s = random.choice(styles) | |
w = random.choice(weirds) | |
# โครงสร้างประโยค | |
# "Behold a [character], [activity] [place] in [style] [weird]!" | |
prompt = f"Behold a {c}, {a} {p} in {s} {w}!" | |
return prompt | |
# ----- 3) สร้าง UI Gradio ----- | |
custom_css = """ | |
body { | |
background-color: #FFFEE0; | |
font-family: "Comic Sans MS", "Comic Sans", cursive; | |
} | |
#title { | |
text-align: center; | |
color: #FF6F91; | |
margin-top: 20px; | |
font-size: 2.2rem; | |
font-weight: bold; | |
} | |
#subtitle { | |
text-align: center; | |
color: #333; | |
margin-bottom: 20px; | |
} | |
#prompt-box { | |
font-size: 20px; | |
min-height: 60px; | |
padding: 10px; | |
text-align: center; | |
border: 2px solid #FFB74D; | |
border-radius: 12px; | |
background-color: #FFF3E0; | |
} | |
""" | |
with gr.Blocks(css=custom_css) as demo: | |
gr.Markdown("<h1 id='title'>ZenityX Dream Explorers</h1>") | |
gr.Markdown(""" | |
<p id='subtitle'> | |
สวัสดีจ้า หนูน้อย! พร้อมหรือยังที่จะหมุนวงล้อ<br> | |
เพื่อสร้าง Prompt สุดแฟนตาซีสำหรับ AI เจนภาพ? | |
</p> | |
""") | |
# ปุ่ม Spin | |
spin_btn = gr.Button("Spin the Wheel!") | |
# กล่องแสดง Prompt | |
prompt_output = gr.Textbox( | |
label="Dream Prompt", | |
interactive=False, | |
elem_id="prompt-box" | |
) | |
# Event: เมื่อกดปุ่ม -> สร้าง Prompt | |
spin_btn.click( | |
fn=spin_the_wheel, | |
inputs=[], | |
outputs=prompt_output | |
) | |
demo.launch() | |