Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
def generate_pet_name(animal_type, personality):
|
| 5 |
+
cute_prefixes = ["Fluffy", "Ziggy", "Bubbles", "Pickle", "Waffle", "Mochi", "Cookie", "Pepper"]
|
| 6 |
+
animal_suffixes = {
|
| 7 |
+
"Cat": ["Whiskers", "Paws", "Mittens", "Purrington"],
|
| 8 |
+
"Dog": ["Woofles", "Barkington", "Waggins", "Pawsome"],
|
| 9 |
+
"Bird": ["Feathers", "Wings", "Chirpy", "Tweets"],
|
| 10 |
+
"Rabbit": ["Hops", "Cottontail", "Bouncy", "Fluff"]
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
prefix = random.choice(cute_prefixes)
|
| 14 |
+
suffix = random.choice(animal_suffixes[animal_type])
|
| 15 |
+
|
| 16 |
+
if personality == "Silly":
|
| 17 |
+
prefix = random.choice(["Sir", "Lady", "Captain", "Professor"]) + " " + prefix
|
| 18 |
+
elif personality == "Royal":
|
| 19 |
+
suffix += " the " + random.choice(["Great", "Magnificent", "Wise", "Brave"])
|
| 20 |
+
|
| 21 |
+
return f"{prefix} {suffix}"
|
| 22 |
+
|
| 23 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 24 |
+
with gr.Sidebar(position="left"):
|
| 25 |
+
gr.Markdown("# 🐾 Pet Name Generator")
|
| 26 |
+
gr.Markdown("Use the options below to generate a unique pet name!")
|
| 27 |
+
|
| 28 |
+
animal_type = gr.Dropdown(
|
| 29 |
+
choices=["Cat", "Dog", "Bird", "Rabbit"],
|
| 30 |
+
label="Choose your pet type",
|
| 31 |
+
value="Cat"
|
| 32 |
+
)
|
| 33 |
+
personality = gr.Radio(
|
| 34 |
+
choices=["Normal", "Silly", "Royal"],
|
| 35 |
+
label="Personality type",
|
| 36 |
+
value="Normal"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
name_output = gr.Textbox(label="Your pet's fancy name:", lines=2)
|
| 40 |
+
generate_btn = gr.Button("Generate Name! 🎲", variant="primary")
|
| 41 |
+
generate_btn.click(
|
| 42 |
+
fn=generate_pet_name,
|
| 43 |
+
inputs=[animal_type, personality],
|
| 44 |
+
outputs=name_output
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|