Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|