freddyaboulton HF staff commited on
Commit
7aadc61
·
verified ·
1 Parent(s): 01f1169

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +7 -7
  2. requirements.txt +2 -0
  3. run.ipynb +1 -0
  4. run.py +48 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Blocks Sidebar Main
3
- emoji: 🐠
4
- colorFrom: yellow
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.13.2
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: blocks_sidebar_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 5.13.2
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@ef66fe52b22448a5125a314581f2ec6c73c24145#subdirectory=client/python
2
+ https://gradio-pypi-previews.s3.amazonaws.com/ef66fe52b22448a5125a314581f2ec6c73c24145/gradio-5.13.2-py3-none-any.whl
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_sidebar"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import random\n", "\n", "def generate_pet_name(animal_type, personality):\n", " cute_prefixes = [\"Fluffy\", \"Ziggy\", \"Bubbles\", \"Pickle\", \"Waffle\", \"Mochi\", \"Cookie\", \"Pepper\"]\n", " animal_suffixes = {\n", " \"Cat\": [\"Whiskers\", \"Paws\", \"Mittens\", \"Purrington\"],\n", " \"Dog\": [\"Woofles\", \"Barkington\", \"Waggins\", \"Pawsome\"],\n", " \"Bird\": [\"Feathers\", \"Wings\", \"Chirpy\", \"Tweets\"],\n", " \"Rabbit\": [\"Hops\", \"Cottontail\", \"Bouncy\", \"Fluff\"]\n", " }\n", "\n", " prefix = random.choice(cute_prefixes)\n", " suffix = random.choice(animal_suffixes[animal_type])\n", "\n", " if personality == \"Silly\":\n", " prefix = random.choice([\"Sir\", \"Lady\", \"Captain\", \"Professor\"]) + \" \" + prefix\n", " elif personality == \"Royal\":\n", " suffix += \" the \" + random.choice([\"Great\", \"Magnificent\", \"Wise\", \"Brave\"])\n", "\n", " return f\"{prefix} {suffix}\"\n", "\n", "with gr.Blocks(theme=gr.themes.Soft()) as demo:\n", " with gr.Sidebar():\n", " gr.Markdown(\"# \ud83d\udc3e Pet Name Generator\")\n", " gr.Markdown(\"Use the options below to generate a unique pet name!\")\n", "\n", " animal_type = gr.Dropdown(\n", " choices=[\"Cat\", \"Dog\", \"Bird\", \"Rabbit\"],\n", " label=\"Choose your pet type\",\n", " value=\"Cat\"\n", " )\n", " personality = gr.Radio(\n", " choices=[\"Normal\", \"Silly\", \"Royal\"],\n", " label=\"Personality type\",\n", " value=\"Normal\"\n", " )\n", "\n", " name_output = gr.Textbox(label=\"Your pet's fancy name:\", lines=2)\n", " generate_btn = gr.Button(\"Generate Name! \ud83c\udfb2\", variant=\"primary\")\n", " generate_btn.click(\n", " fn=generate_pet_name,\n", " inputs=[animal_type, personality],\n", " outputs=name_output\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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():
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
+ if __name__ == "__main__":
48
+ demo.launch()