Spaces:
Sleeping
Sleeping
import random | |
import time | |
import gradio as gr | |
def spin_game(names): | |
# Split the input string into a list of names | |
participants = [name.strip() for name in names.split(',') if name.strip()] | |
if len(participants) < 2: | |
return "Please enter at least two names." | |
result = "Welcome to the Spin Game!\n" | |
result += f"We have {len(participants)} participants.\n" | |
result += "Spinning the wheel...\n" | |
for i in range(3, 0, -1): | |
result += f"{i}...\n" | |
time.sleep(0.5) | |
winner = random.choice(participants) | |
result += "\nAnd the winner is...\n" | |
time.sleep(1) | |
result += f"π {winner.upper()}! π" | |
return result | |
def display_gif(names): | |
# Path to the GIF image | |
gif_url = "https://github.com/Decoding-Data-Science/airesidency/raw/main/spin-wheel.gif" | |
return gif_url, spin_game(names) | |
# Create the Gradio interface | |
def build_interface(): | |
with gr.Blocks() as iface: | |
with gr.Column(): | |
# Add the logo at the top | |
gr.Image("https://github.com/Decoding-Data-Science/airesidency/raw/main/dds_logo.jpg", type="filepath", height=100, width=100) | |
# Centered title | |
gr.Markdown("<h1 style='text-align: center;'>DDS Ondemand $500 Credit Winner!</h1>") | |
gr.Markdown("Enter a list of names separated by commas. The game will randomly select a winner!") | |
input_box = gr.Textbox(lines=5, placeholder="Enter names separated by commas...") | |
output_gif = gr.Image(type="filepath") | |
output_text = gr.Textbox() | |
# Add a button to trigger the spin_game function | |
submit_button = gr.Button("Spin the Wheel") | |
# Connect the button to the function | |
submit_button.click(display_gif, inputs=input_box, outputs=[output_gif, output_text]) | |
return iface | |
# Launch the app | |
iface = build_interface() | |
iface.launch() | |