| import random | |
| import gradio as gr | |
| def roll_dice(): | |
| p1_roll = random.randint(1, 6) | |
| p2_roll = random.randint(1, 6) | |
| if p1_roll > p2_roll: | |
| winner = "Player 1 wins!" | |
| elif p2_roll > p1_roll: | |
| winner = "Player 2 wins!" | |
| else: | |
| winner = "It's a draw!" | |
| result = f"Player 1 rolled: {p1_roll}\nPlayer 2 rolled: {p2_roll}\n\n{winner}" | |
| return result | |
| iface = gr.Interface( | |
| fn=roll_dice, | |
| inputs=[], | |
| outputs="text", | |
| title="Mini Dice Game", | |
| description="Click the button to roll dice for Player 1 and Player 2" | |
| ) | |
| iface.launch() |