Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import time
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def spin_game(names):
|
| 6 |
+
# Split the input string into a list of names
|
| 7 |
+
participants = [name.strip() for name in names.split(',') if name.strip()]
|
| 8 |
+
|
| 9 |
+
if len(participants) < 2:
|
| 10 |
+
return "Please enter at least two names."
|
| 11 |
+
|
| 12 |
+
result = "Welcome to the Spin Game!\n"
|
| 13 |
+
result += f"We have {len(participants)} participants.\n"
|
| 14 |
+
result += "Spinning the wheel...\n"
|
| 15 |
+
|
| 16 |
+
for i in range(3, 0, -1):
|
| 17 |
+
result += f"{i}...\n"
|
| 18 |
+
time.sleep(0.5)
|
| 19 |
+
|
| 20 |
+
winner = random.choice(participants)
|
| 21 |
+
result += "\nAnd the winner is...\n"
|
| 22 |
+
time.sleep(1)
|
| 23 |
+
result += f"π {winner.upper()}! π"
|
| 24 |
+
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
+
def display_gif(names):
|
| 28 |
+
# Path to the GIF image
|
| 29 |
+
gif_url = "https://github.com/Decoding-Data-Science/airesidency/raw/main/spin-wheel.gif"
|
| 30 |
+
return gif_url, spin_game(names)
|
| 31 |
+
|
| 32 |
+
# Create the Gradio interface
|
| 33 |
+
def build_interface():
|
| 34 |
+
with gr.Blocks() as iface:
|
| 35 |
+
with gr.Column():
|
| 36 |
+
# Add the logo at the top
|
| 37 |
+
gr.Image("https://github.com/Decoding-Data-Science/airesidency/raw/main/dds_logo.jpg", type="filepath", height=100, width=100)
|
| 38 |
+
# Centered title
|
| 39 |
+
gr.Markdown("<h1 style='text-align: center;'>DDS Ondemand $500 Credit Winner!</h1>")
|
| 40 |
+
|
| 41 |
+
gr.Markdown("Enter a list of names separated by commas. The game will randomly select a winner!")
|
| 42 |
+
|
| 43 |
+
input_box = gr.Textbox(lines=5, placeholder="Enter names separated by commas...")
|
| 44 |
+
output_gif = gr.Image(type="filepath")
|
| 45 |
+
output_text = gr.Textbox()
|
| 46 |
+
|
| 47 |
+
# Add a button to trigger the spin_game function
|
| 48 |
+
submit_button = gr.Button("Spin the Wheel")
|
| 49 |
+
|
| 50 |
+
# Connect the button to the function
|
| 51 |
+
submit_button.click(display_gif, inputs=input_box, outputs=[output_gif, output_text])
|
| 52 |
+
|
| 53 |
+
return iface
|
| 54 |
+
|
| 55 |
+
# Launch the app
|
| 56 |
+
iface = build_interface()
|
| 57 |
+
iface.launch()
|