Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,23 +2,16 @@ import random
|
|
2 |
import gradio as gr
|
3 |
|
4 |
def roll_dice(sides):
|
5 |
-
# Convert input to an integer, default to 20 if input is blank or not valid
|
6 |
-
try:
|
7 |
-
sides = int(sides) if sides else 20
|
8 |
-
if sides < 2 or sides > 100: # Ensure sides are within the valid range
|
9 |
-
return "Please enter a number between 2 and 100."
|
10 |
-
except ValueError:
|
11 |
-
return "Please enter a valid number."
|
12 |
-
|
13 |
return random.randint(1, sides)
|
14 |
|
15 |
# Create the Gradio interface
|
16 |
iface = gr.Interface(
|
17 |
fn=roll_dice,
|
18 |
-
inputs=gr.
|
19 |
outputs="number",
|
20 |
title="Dice Roller",
|
21 |
-
description="Enter the number of sides on the dice and click 'Submit' to roll!
|
22 |
)
|
23 |
|
24 |
-
#
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
def roll_dice(sides):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
return random.randint(1, sides)
|
6 |
|
7 |
# Create the Gradio interface
|
8 |
iface = gr.Interface(
|
9 |
fn=roll_dice,
|
10 |
+
inputs=gr.Number(label="Number of Sides (2-100)", value=6, precision=0),
|
11 |
outputs="number",
|
12 |
title="Dice Roller",
|
13 |
+
description="Enter the number of sides on the dice and click 'Submit' to roll!"
|
14 |
)
|
15 |
|
16 |
+
# Launch the app
|
17 |
+
iface.launch()
|