import gradio as gr import random # Card values and images cards = { 'Ace': 1, '2': 2, '3': 3, '4': 4 } card_images = { 'Ace': "https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/poker-playing-card-ace-diamond-miroslav-nemecek.jpg", '2': "https://cdn.vectorstock.com/i/1000v/58/67/poker-playing-card-2-club-vector-8695867.jpg", '3': "https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/poker-playing-card-3-diamond-miroslav-nemecek.jpg", '4': "https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/poker-playing-card-4-spade-miroslav-nemecek.jpg" } def get_random_card(): return random.choice(list(cards.keys())) def check_guess(current_card, next_card, guess): current_value = cards[current_card] next_value = cards[next_card] if guess == "higher": return next_value > current_value elif guess == "lower": return next_value < current_value else: # same return next_value == current_value def play_game(choice): current_card = get_random_card() next_card = get_random_card() result = check_guess(current_card, next_card, choice) return ( card_images[current_card], card_images[next_card], "Correct!" if result else "Wrong!" ) # Create Gradio interface with gr.Blocks() as demo: gr.Markdown("# Higher Lower Card Game") with gr.Row(): current_card_image = gr.Image(label="Current Card") next_card_image = gr.Image(label="Next Card") with gr.Row(): higher_btn = gr.Button("Higher") lower_btn = gr.Button("Lower") same_btn = gr.Button("Same") result_text = gr.Textbox(label="Result") higher_btn.click( fn=play_game, inputs=[gr.Textbox(value="higher", visible=False)], outputs=[current_card_image, next_card_image, result_text] ) lower_btn.click( fn=play_game, inputs=[gr.Textbox(value="lower", visible=False)], outputs=[current_card_image, next_card_image, result_text] ) same_btn.click( fn=play_game, inputs=[gr.Textbox(value="same", visible=False)], outputs=[current_card_image, next_card_image, result_text] ) demo.launch()