File size: 1,922 Bytes
20ddeec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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()